Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binary framer and add start and end tokens #5

Merged
merged 1 commit into from
Mar 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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