Skip to content

Commit 572ce90

Browse files
authored
Merge pull request #1 from corystegel/master
Fix type mismatch for struct.unpack
2 parents 1471029 + 142444a commit 572ce90

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

chamberconnectlibrary/modbus.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ def make_packet(self, function, register, args):
189189

190190
def decode_packet(self, packet, spacket):
191191
'''Decode the modbus request packet.'''
192-
fcode = struct.unpack(">B", packet[1])[0]
193-
addr = struct.unpack(">B", packet[0])[0]
192+
fcode = struct.unpack(">B", bytes([packet[1]]))[0]
193+
addr = struct.unpack(">B", bytes([packet[0]]))[0]
194194
if self.address != addr:
195195
shex = ":".join("{:02x}".format(ord(c) for c in spacket))
196196
rhex = ":".join("{:02x}".format(ord(c) for c in packet))
197197
raise ModbusError("Address error; Sent=%s, Recieved=%s" % (shex, rhex))
198198
if fcode > 127:
199-
ecode = struct.unpack(">B", packet[2])[0]
199+
ecode = struct.unpack(">B", bytes([packet[2]]))[0]
200200
ttp = (ecode, self.errorMessages.get(ecode, 'Unknown error code'))
201201
raise ModbusError('Modbus Error: Exception code = %d(%s)' % ttp)
202202

203203
if fcode == 3: #Read holding register(s)
204-
cnt = struct.unpack(">B", packet[2])[0]/2
205-
return struct.unpack(">%dH" % cnt, packet[3:])
204+
cnt = struct.unpack(">B", bytes([packet[2]]))[0] / 2
205+
return struct.unpack(">%dH" % cnt, bytes(packet[3:]))
206206
elif fcode == 6:
207207
pass #nothing is required
208208
elif fcode == 16:

0 commit comments

Comments
 (0)