Skip to content

Commit bbcc4c6

Browse files
committed
TMCL: Allow a TMCLReply creation also from 8 bytes of data
.. instead of only 9 bytes
1 parent bf4b477 commit bbcc4c6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pytrinamic/tmcl.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,21 @@ def __init__(self, reply_address, module_address, status, command, value, checks
229229

230230
@staticmethod
231231
def from_buffer(data):
232-
reply_struct = struct.unpack(_PACKAGE_STRUCTURE, data)
232+
if len(data) == 9:
233+
package_structure = _PACKAGE_STRUCTURE
234+
no_checksum = False
235+
elif len(data) == 8:
236+
package_structure = _PACKAGE_STRUCTURE[:-1] # Remove checksum from package structure
237+
no_checksum = True
238+
else:
239+
raise ValueError("Invalid data length!")
240+
reply_struct = struct.unpack(package_structure, data)
241+
if no_checksum:
242+
checksum = None
243+
else:
244+
checksum = reply_struct[5]
233245
return TMCLReply(reply_struct[0], reply_struct[1], reply_struct[2], reply_struct[3],
234-
reply_struct[4], reply_struct[5])
246+
reply_struct[4], checksum)
235247

236248
def calculate_checksum(self):
237249
self.checksum = TMCL.calculate_checksum(self.to_buffer()[:-1])

0 commit comments

Comments
 (0)