From 0de88ff0fb69b49d10624d94b0893a11ffad7e3f Mon Sep 17 00:00:00 2001 From: Philippe Gauthier Date: Thu, 29 Mar 2012 17:34:08 -0400 Subject: [PATCH] Fix binary framer and add start and end tokens Fixes a TypeError occuring while escaping token bytes in the message and adds the start and end tokens to the packet. --- pymodbus/transaction.py | 3 ++- test/test_transaction.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index 4118ba826..9bfc4d779 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -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): @@ -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)) #---------------------------------------------------------------------------# diff --git a/test/test_transaction.py b/test/test_transaction.py index a0ac8c7ad..2df2736f6 100644 --- a/test/test_transaction.py +++ b/test/test_transaction.py @@ -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