File tree Expand file tree Collapse file tree 4 files changed +13
-11
lines changed Expand file tree Collapse file tree 4 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 1
1
"""Modbus client async serial communication."""
2
2
import asyncio
3
3
import time
4
- from contextlib import suppress
5
4
from functools import partial
6
5
from typing import Any , Type
7
6
14
13
from pymodbus .utilities import ModbusTransactionState
15
14
16
15
17
- with suppress ( ImportError ) :
16
+ try :
18
17
import serial
18
+ except ImportError :
19
+ raise ImportError (
20
+ "Serial client requires pyserial"
21
+ 'Please install with "pip install pyserial" and try again.'
22
+ )
19
23
20
24
21
25
class AsyncModbusSerialClient (ModbusBaseClient , asyncio .Protocol ):
Original file line number Diff line number Diff line change 23
23
from pymodbus .transport import CommParams , CommType , ModbusProtocol
24
24
25
25
26
- with suppress (ImportError ):
27
- pass
28
-
29
-
30
26
# --------------------------------------------------------------------------- #
31
27
# Protocol Handlers
32
28
# --------------------------------------------------------------------------- #
Original file line number Diff line number Diff line change 15
15
try :
16
16
from aiohttp import web
17
17
except ImportError :
18
- print (
18
+ raise ImportError (
19
19
"Reactive server requires aiohttp. "
20
20
'Please install with "pip install aiohttp" and try again.'
21
21
)
22
- sys .exit (1 )
23
22
24
23
from pymodbus import __version__ as pymodbus_version
25
24
from pymodbus .datastore import ModbusServerContext , ModbusSlaveContext
Original file line number Diff line number Diff line change 9
9
from typing import List
10
10
11
11
12
- with contextlib . suppress ( ImportError ) :
12
+ try :
13
13
from aiohttp import web
14
+ except ImportError :
15
+ raise ImportError (
16
+ "Simulator server requires aiohttp. "
17
+ 'Please install with "pip install aiohttp" and try again.'
18
+ )
14
19
15
20
from pymodbus .datastore import ModbusServerContext , ModbusSimulatorContext
16
21
from pymodbus .datastore .simulator import Label
@@ -124,8 +129,6 @@ def __init__(
124
129
custom_actions_module : str = None ,
125
130
):
126
131
"""Initialize http interface."""
127
- if not web :
128
- raise RuntimeError ("aiohttp not installed!" )
129
132
with open (json_file , encoding = "utf-8" ) as file :
130
133
setup = json .load (file )
131
134
You can’t perform that action at this time.
0 commit comments