Skip to content

Commit

Permalink
Rtu decode frames without byte count. (#2412)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Oct 24, 2024
1 parent 144e43b commit 9b97a18
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pymodbus/framer/rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ def decode(self, data: bytes) -> tuple[int, int, int, bytes]:
if data_len < used_len +size:
Log.debug("Frame - not ready")
return used_len, dev_id, 0, self.EMPTY
start_crc = used_len + size -2
crc = data[start_crc : start_crc + 2]
crc_val = (int(crc[0]) << 8) + int(crc[1])
if not FramerRTU.check_CRC(data[used_len : start_crc], crc_val):
Log.debug("Frame check failed, ignoring!!")
continue
return start_crc + 2, dev_id, 0, data[used_len + 1 : start_crc]
for test_len in range(data_len, used_len + size - 1, -1):
start_crc = test_len -2
crc = data[start_crc : start_crc + 2]
crc_val = (int(crc[0]) << 8) + int(crc[1])
if not FramerRTU.check_CRC(data[used_len : start_crc], crc_val):
Log.debug("Frame check failed, possible garbage after frame, testing..")
continue
return start_crc + 2, dev_id, 0, data[used_len + 1 : start_crc]
return 0, 0, 0, self.EMPTY


Expand Down

0 comments on commit 9b97a18

Please sign in to comment.