diff --git a/examples/client_async.py b/examples/client_async.py index d676194fe0..0f81651c28 100755 --- a/examples/client_async.py +++ b/examples/client_async.py @@ -39,8 +39,8 @@ AsyncModbusTcpClient, AsyncModbusTlsClient, AsyncModbusUdpClient, + ModbusException, ) -from pymodbus.exceptions import ModbusIOException logging.basicConfig() @@ -135,7 +135,7 @@ async def run_a_few_calls(client): rr = await client.read_holding_registers(4, 2, slave=1) assert rr.registers[0] == 17 assert rr.registers[1] == 17 - except ModbusIOException: + except ModbusException: pass diff --git a/examples/client_sync.py b/examples/client_sync.py index abce01bc66..da177db507 100755 --- a/examples/client_sync.py +++ b/examples/client_sync.py @@ -38,6 +38,7 @@ # import the various client implementations # --------------------------------------------------------------------------- # from pymodbus.client import ( + ModbusException, ModbusSerialClient, ModbusTcpClient, ModbusTlsClient, @@ -136,12 +137,14 @@ def run_sync_client(client, modbus_calls=None): def run_a_few_calls(client): """Test connection works.""" - rr = client.read_coils(32, 1, slave=1) - assert len(rr.bits) == 8 - rr = client.read_holding_registers(4, 2, slave=1) - assert rr.registers[0] == 17 - assert rr.registers[1] == 17 - + try: + rr = client.read_coils(32, 1, slave=1) + assert len(rr.bits) == 8 + rr = client.read_holding_registers(4, 2, slave=1) + assert rr.registers[0] == 17 + assert rr.registers[1] == 17 + except ModbusException as exc: + raise exc def main(cmdline=None): """Combine setup and run.""" diff --git a/pymodbus/client/__init__.py b/pymodbus/client/__init__.py index 472855dd31..71ccfdc903 100644 --- a/pymodbus/client/__init__.py +++ b/pymodbus/client/__init__.py @@ -5,15 +5,17 @@ "AsyncModbusTcpClient", "AsyncModbusTlsClient", "AsyncModbusUdpClient", + "Framer", + "ModbusException", "ModbusSerialClient", "ModbusTcpClient", "ModbusTlsClient", "ModbusUdpClient", - "Framer" ] from pymodbus.client.serial import AsyncModbusSerialClient, ModbusSerialClient from pymodbus.client.tcp import AsyncModbusTcpClient, ModbusTcpClient from pymodbus.client.tls import AsyncModbusTlsClient, ModbusTlsClient from pymodbus.client.udp import AsyncModbusUdpClient, ModbusUdpClient +from pymodbus.exceptions import ModbusException from pymodbus.framer import Framer