Skip to content

Commit

Permalink
Merge pull request #88 from vrtsystems/fix-udp-sync-client
Browse files Browse the repository at this point in the history
Fix udp sync client
  • Loading branch information
bashwork committed Sep 26, 2015
2 parents 2afc1e7 + e27dbb4 commit 6c7edfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pymodbus/register_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def __init__(self, address=None, values=None, **kwargs):
'''
ModbusRequest.__init__(self, **kwargs)
self.address = address
self.values = values or []
if not hasattr(values, '__iter__'):
self.values = [values]
if values is None:
values = []
elif not hasattr(values, '__iter__'):
values = [values]
self.values = values
self.count = len(self.values)
self.byte_count = self.count * 2

Expand Down
5 changes: 4 additions & 1 deletion test/test_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def testUdpClientAddressFamily(self):
def testUdpClientConnect(self):
''' Test the Udp client connection method'''
with patch.object(socket, 'socket') as mock_method:
mock_method.return_value = object()
class DummySocket(object):
def settimeout(self, *a, **kwa):
pass
mock_method.return_value = DummySocket()
client = ModbusUdpClient()
self.assertTrue(client.connect())

Expand Down
2 changes: 1 addition & 1 deletion test/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def testPayloadDecoderRegisterFactory(self):
''' Test the payload decoder reset functionality '''
payload = [1,2,3,4]
decoder = BinaryPayloadDecoder.fromRegisters(payload, endian=Endian.Little)
encoded = '\x00\x01\x00\x02\x00\x03\x00\x04'
encoded = '\x01\x00\x02\x00\x03\x00\x04\x00'
self.assertEqual(encoded, decoder.decode_string(8))

decoder = BinaryPayloadDecoder.fromRegisters(payload, endian=Endian.Big)
Expand Down

0 comments on commit 6c7edfc

Please sign in to comment.