Skip to content

Commit

Permalink
1. #277 MEI message reception issue with UDP client
Browse files Browse the repository at this point in the history
2. Fix unit tests
3. Update changelog
  • Loading branch information
dhoomakethu committed Apr 9, 2018
1 parent 900db55 commit c49038a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Version 1.5.0
* Move framers from transaction.py to respective modules
* Fix modbus payload builder and decoder
* Async servers can now have an option to defer `reactor.run()` when using `Start<Tcp/Serial/Udo>Server(...,defer_reactor_run=True)`
* Fix UDP client issue while handling MEI messages (ReadDeviceInformationRequest)
* Fix Misc examples

Version 1.4.0
Expand Down
8 changes: 6 additions & 2 deletions examples/common/synchronous_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ def run_server():
# ----------------------------------------------------------------------- #
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))


# TCP with different framer
# StartTcpServer(context, identity=identity,
# framer=ModbusRtuFramer, address=("0.0.0.0", 5020))

# Udp:
# StartUdpServer(context, identity=identity, address=("localhost", 5020))
# StartUdpServer(context, identity=identity, address=("0.0.0.0", 5020))

# Ascii:
# StartSerialServer(context, identity=identity,
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __str__(self):
:returns: The string representation
"""
return "%s:%s" % (self.host, self.port)
return "ModbusTcpClient(%s:%s)" % (self.host, self.port)


# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -330,7 +330,7 @@ def __str__(self):
:returns: The string representation
"""
return "%s:%s" % (self.host, self.port)
return "ModbusUdpClient(%s:%s)" % (self.host, self.port)


# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -478,7 +478,7 @@ def __str__(self):
:returns: The string representation
"""
return "%s baud[%s]" % (self.method, self.baudrate)
return "ModbusSerialClient(%s baud[%s])" % (self.method, self.baudrate)

# --------------------------------------------------------------------------- #
# Exported symbols
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/server/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def __init__(self, context, framer=None, identity=None, address=None,

socketserver.ThreadingUDPServer.__init__(self,
self.address, self.handler)
self._BaseServer__shutdown_request = True
# self._BaseServer__shutdown_request = True

def process_request(self, request, client):
""" Callback for connecting a new client thread
Expand Down
3 changes: 3 additions & 0 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def execute(self, request):
full = True
else:
full = False
c_str = str(self.client)
if "modbusudpclient" in c_str.lower().strip():
full = True
response, last_exception = self._transact(request,
expected_response_length,
full=full
Expand Down
6 changes: 3 additions & 3 deletions test/test_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def testBasicSyncUdpClient(self):
client.socket = False
client.close()

self.assertEqual("127.0.0.1:502", str(client))
self.assertEqual("ModbusUdpClient(127.0.0.1:502)", str(client))

def testUdpClientAddressFamily(self):
''' Test the Udp client get address family method'''
Expand Down Expand Up @@ -158,7 +158,7 @@ def testBasicSyncTcpClient(self):
client.socket = False
client.close()

self.assertEqual("127.0.0.1:502", str(client))
self.assertEqual("ModbusTcpClient(127.0.0.1:502)", str(client))

def testTcpClientConnect(self):
''' Test the tcp client connection method'''
Expand Down Expand Up @@ -234,7 +234,7 @@ def testBasicSyncSerialClient(self, mock_serial):
client.socket = False
client.close()

self.assertEqual('ascii baud[19200]', str(client))
self.assertEqual('ModbusSerialClient(ascii baud[19200])', str(client))

def testSerialClientConnect(self):
''' Test the serial client connection method'''
Expand Down
3 changes: 1 addition & 2 deletions test/test_server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#---------------------------------------------------------------------------#
class MockServer(object):
def __init__(self):
self.framer = lambda _: "framer"
self.framer = lambda _, client=None: "framer"
self.decoder = "decoder"
self.threads = []
self.context = {}
Expand Down Expand Up @@ -59,7 +59,6 @@ def testBaseHandlerMethods(self):
request = ReadCoilsRequest(1, 1)
address = ('server', 12345)
server = MockServer()

with patch.object(ModbusBaseRequestHandler, 'handle') as mock_handle:
with patch.object(ModbusBaseRequestHandler, 'send') as mock_send:
mock_handle.return_value = True
Expand Down

0 comments on commit c49038a

Please sign in to comment.