diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e13bfc559..e8c9bc6d4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 `StartServer(...,defer_reactor_run=True)` +* Fix UDP client issue while handling MEI messages (ReadDeviceInformationRequest) * Fix Misc examples Version 1.4.0 diff --git a/examples/common/synchronous_server.py b/examples/common/synchronous_server.py index 20fc13c4f..617b1acc9 100755 --- a/examples/common/synchronous_server.py +++ b/examples/common/synchronous_server.py @@ -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, diff --git a/pymodbus/client/sync.py b/pymodbus/client/sync.py index 213e6d22b..fb45ec6f7 100644 --- a/pymodbus/client/sync.py +++ b/pymodbus/client/sync.py @@ -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) # --------------------------------------------------------------------------- # @@ -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) # --------------------------------------------------------------------------- # @@ -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 diff --git a/pymodbus/server/sync.py b/pymodbus/server/sync.py index d22f76cdf..cb7c26e39 100644 --- a/pymodbus/server/sync.py +++ b/pymodbus/server/sync.py @@ -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 diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index 3cfb4b91a..44beb8a79 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -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 diff --git a/test/test_client_sync.py b/test/test_client_sync.py index 3c91ccd43..d503d0dda 100644 --- a/test/test_client_sync.py +++ b/test/test_client_sync.py @@ -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''' @@ -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''' @@ -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''' diff --git a/test/test_server_sync.py b/test/test_server_sync.py index 70a5a1dc8..38f1121aa 100644 --- a/test/test_server_sync.py +++ b/test/test_server_sync.py @@ -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 = {} @@ -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