Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_device_information with sync client. #2441

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/client_async_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def async_handle_file_records(client):
async def async_execute_information_requests(client):
"""Execute extended information requests."""
_logger.info("### Running information requests.")
rr = await client.read_device_information(slave=SLAVE)
rr = await client.read_device_information(slave=SLAVE, read_code=1, object_id=0)
assert not rr.isError() # test that call was OK
assert rr.information[0] == b"Pymodbus"

Expand Down
8 changes: 3 additions & 5 deletions examples/client_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,9 @@ def handle_file_records(client):
def execute_information_requests(client):
"""Execute extended information requests."""
_logger.info("### Running information requests.")
# NOT WORKING: ONLY SYNC.
# FAILS WITH framer = RTU
# rr = client.read_device_information(slave=SLAVE)
# assert not rr.isError() # test that call was OK
# assert rr.information[0] == b"Pymodbus"
rr = client.read_device_information(slave=SLAVE, read_code=1, object_id=0)
assert not rr.isError() # test that call was OK
assert rr.information[0] == b"Pymodbus"

rr = client.report_slave_id(slave=SLAVE)
assert not rr.isError() # test that call was OK
Expand Down
4 changes: 4 additions & 0 deletions pymodbus/pdu/mei_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ class ReadDeviceInformationResponse(ModbusPDU):
def calculateRtuFrameSize(cls, buffer: bytes) -> int:
"""Calculate the size of the message."""
size = 8 # skip the header information
if (data_len := len(buffer)) < size:
return 999
count = int(buffer[7])

try:
while count > 0:
if data_len < size+2:
return 998
_, object_length = struct.unpack(">BB", buffer[size : size + 2])
size += object_length + 2
count -= 1
Expand Down