Skip to content

Commit

Permalink
python3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeSkywalker92 committed Oct 26, 2018
1 parent da8ab24 commit ed352c5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pyTMCL/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def send(self, address, command, type, motorbank, value):
else:
checksum = self._binaryadd(
address, command, type, motorbank, value)
msg = struct.pack(MSG_STRUCTURE, address, command,
type, motorbank, value, checksum)
msg = struct.pack(MSG_STRUCTURE, int(address), int(command),
int(type), int(motorbank), int(value), int(checksum))
self.serial.write(msg)
rep = self.serial.read(REPLY_LENGTH)
reply = Reply(struct.unpack(REPLY_STRUCTURE, rep))
Expand Down Expand Up @@ -99,9 +99,12 @@ def _handle_reply(self, reply):

def _binaryadd(self, address, command, type, motorbank, value):
checksum_struct = struct.pack(
MSG_STRUCTURE[:-1], address, command, type, motorbank, value)
MSG_STRUCTURE[:-1], int(address), int(command), int(type), int(motorbank), int(value))
checksum = 0
for s in checksum_struct:
checksum += int(s.encode('hex'), 16) % 256
try:
checksum += int(s.encode('hex'), 16) % 256
except:
checksum += s % 256
checksum = checksum % 256
return checksum
return int(checksum)

0 comments on commit ed352c5

Please # to comment.