Skip to content

Commit

Permalink
Disable modbus length check due to Goodwe bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 20, 2024
1 parent 0b9da5a commit bbbbcbb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions goodwe/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ def validate_modbus_tcp_response(data: bytes, cmd: int, offset: int, value: int)
if len(data) <= 8:
logger.debug("Response is too short.")
return False
expected_length = int.from_bytes(data[4:6], byteorder='big', signed=False) + 6
# The weird expected_length != 12 is work around Goodwe bug answering wrong (hardcoded 6) length.
if len(data) < expected_length and expected_length != 12:
raise PartialResponseException(len(data), expected_length)

# The Modbus/TCP message length check is completely ignore due to Goodwe bugs
# expected_length = int.from_bytes(data[4:6], byteorder='big', signed=False) + 6
# if len(data) < expected_length:
# raise PartialResponseException(len(data), expected_length)

if data[7] == MODBUS_READ_CMD:
expected_length = data[8] + 9
Expand All @@ -235,8 +236,8 @@ def validate_modbus_tcp_response(data: bytes, cmd: int, offset: int, value: int)
return False
elif data[7] in (MODBUS_WRITE_CMD, MODBUS_WRITE_MULTI_CMD):
if len(data) < 12:
logger.debug("Response has unexpected length: %d, expected %d.", len(data), 14)
raise PartialResponseException(len(data), expected_length)
logger.debug("Response has unexpected length: %d, expected %d.", len(data), 12)
return False
response_offset = int.from_bytes(data[8:10], byteorder='big', signed=False)
if response_offset != offset:
logger.debug("Response has wrong offset: %X, expected %X.", response_offset, offset)
Expand Down

0 comments on commit bbbbcbb

Please sign in to comment.