Skip to content

Commit

Permalink
Merge pull request #5 from deuxpi/binary-framer-fix
Browse files Browse the repository at this point in the history
Fix binary framer and add start and end tokens
  • Loading branch information
bashwork committed Mar 30, 2012
2 parents e343a98 + 0de88ff commit 29300e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ def buildPacket(self, message):
message.unit_id,
message.function_code) + data
packet += struct.pack(">H", computeCRC(packet))
packet = '%s%s%s' % (self.__start, packet, self.__end)
return packet

def _preflight(self, data):
Expand All @@ -755,7 +756,7 @@ def _preflight(self, data):
'''
def _filter(a):
if a in ['}', '{']: return a * 2
else: return a, data
else: return a
return ''.join(map(_filter, data))

#---------------------------------------------------------------------------#
Expand Down
2 changes: 1 addition & 1 deletion test/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def testBinaryFramerPacket(self):
message = ModbusRequest()
message.unit_id = 0xff
message.function_code = 0x01
expected = '\xff\x01\x81\x80'
expected = '\x7b\xff\x01\x81\x80\x7d'
actual = self._binary.buildPacket(message)
self.assertEqual(expected, actual)
ModbusRequest.encode = old_encode
Expand Down

0 comments on commit 29300e2

Please sign in to comment.