Handle CRC too short in readMemory
This commit is contained in:
parent
00fb5f1dee
commit
efddfd60cb
1 changed files with 5 additions and 1 deletions
|
@ -305,7 +305,11 @@ def readMemory(fh: RawIOBase, address: int, words: int = 1) -> Optional[bytes]:
|
|||
data = fh.read(size)
|
||||
_crc = fh.read(2)
|
||||
if data and _crc:
|
||||
try:
|
||||
crc = struct.unpack_from("<H", _crc)[0]
|
||||
except struct.error:
|
||||
log(f"readMemory: CRC error; read {len(_crc)} bytes (2 expected)")
|
||||
return None
|
||||
calculated_crc = modbus(bytes([tag, operation, size, *data]))
|
||||
if crc == calculated_crc:
|
||||
return data
|
||||
|
|
Loading…
Reference in a new issue