Skip to content

Commit

Permalink
ModbusException.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Oct 31, 2023
1 parent 2403abb commit 4381f0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
AsyncModbusTcpClient,
AsyncModbusTlsClient,
AsyncModbusUdpClient,
ModbusException,
)
from pymodbus.exceptions import ModbusIOException


logging.basicConfig()
Expand Down Expand Up @@ -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


Expand Down
15 changes: 9 additions & 6 deletions examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# import the various client implementations
# --------------------------------------------------------------------------- #
from pymodbus.client import (
ModbusException,
ModbusSerialClient,
ModbusTcpClient,
ModbusTlsClient,
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 3 additions & 1 deletion pymodbus/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4381f0e

Please sign in to comment.