Skip to content

Commit 5030514

Browse files
JStrbgdhoomakethu
authored andcommitted
Fixed erronous CRC handling
If the CRC recieved is not correct in my case my slave got caught in a deadlock, not taking any new requests. This addition fixed that.
1 parent 6960d9c commit 5030514

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pymodbus/framer/rtu_framer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ def checkFrame(self):
9191
data = self._buffer[:frame_size - 2]
9292
crc = self._buffer[frame_size - 2:frame_size]
9393
crc_val = (byte2int(crc[0]) << 8) + byte2int(crc[1])
94-
return checkCRC(data, crc_val)
94+
if checkCRC(data, crc_val):
95+
return True
96+
else:
97+
_logger.debug("CRC invalid, discarding header!!")
98+
self.resetFrame()
99+
return False
95100
except (IndexError, KeyError, struct.error):
96101
return False
97102

0 commit comments

Comments
 (0)