Skip to content

Commit 504af27

Browse files
committed
Add get_expected_response_length to transaction.
1 parent f63a4eb commit 504af27

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pymodbus/transaction.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def _recv(self, expected_response_length, full): # noqa: C901
386386
IndexError # response length indeterminate with available bytes
387387
):
388388
expected_response_length = (
389-
self.client.framer.get_expected_response_length(
389+
self._get_expected_response_length(
390390
read_min
391391
)
392392
)
@@ -424,6 +424,17 @@ def _recv(self, expected_response_length, full): # noqa: C901
424424
self.client.state = ModbusTransactionState.PROCESSING_REPLY
425425
return result
426426

427+
def _get_expected_response_length(self, data):
428+
"""Get the expected response length.
429+
430+
:param data: Message data read so far
431+
:raises IndexError: If not enough data to read byte count
432+
:return: Total frame size
433+
"""
434+
func_code = int(data[1])
435+
pdu_class = self.client.framer.decoder.lookupPduClass(func_code)
436+
return pdu_class.calculateRtuFrameSize(data)
437+
427438
def addTransaction(self, request, tid=None):
428439
"""Add a transaction to the handler.
429440

0 commit comments

Comments
 (0)