Skip to content

Commit c49038a

Browse files
committed
1. #277 MEI message reception issue with UDP client
2. Fix unit tests 3. Update changelog
1 parent 900db55 commit c49038a

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Version 1.5.0
1010
* Move framers from transaction.py to respective modules
1111
* Fix modbus payload builder and decoder
1212
* Async servers can now have an option to defer `reactor.run()` when using `Start<Tcp/Serial/Udo>Server(...,defer_reactor_run=True)`
13+
* Fix UDP client issue while handling MEI messages (ReadDeviceInformationRequest)
1314
* Fix Misc examples
1415

1516
Version 1.4.0

examples/common/synchronous_server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ def run_server():
112112
# ----------------------------------------------------------------------- #
113113
# Tcp:
114114
StartTcpServer(context, identity=identity, address=("localhost", 5020))
115-
115+
116+
# TCP with different framer
117+
# StartTcpServer(context, identity=identity,
118+
# framer=ModbusRtuFramer, address=("0.0.0.0", 5020))
119+
116120
# Udp:
117-
# StartUdpServer(context, identity=identity, address=("localhost", 5020))
121+
# StartUdpServer(context, identity=identity, address=("0.0.0.0", 5020))
118122

119123
# Ascii:
120124
# StartSerialServer(context, identity=identity,

pymodbus/client/sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def __str__(self):
240240
241241
:returns: The string representation
242242
"""
243-
return "%s:%s" % (self.host, self.port)
243+
return "ModbusTcpClient(%s:%s)" % (self.host, self.port)
244244

245245

246246
# --------------------------------------------------------------------------- #
@@ -330,7 +330,7 @@ def __str__(self):
330330
331331
:returns: The string representation
332332
"""
333-
return "%s:%s" % (self.host, self.port)
333+
return "ModbusUdpClient(%s:%s)" % (self.host, self.port)
334334

335335

336336
# --------------------------------------------------------------------------- #
@@ -478,7 +478,7 @@ def __str__(self):
478478
479479
:returns: The string representation
480480
"""
481-
return "%s baud[%s]" % (self.method, self.baudrate)
481+
return "ModbusSerialClient(%s baud[%s])" % (self.method, self.baudrate)
482482

483483
# --------------------------------------------------------------------------- #
484484
# Exported symbols

pymodbus/server/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def __init__(self, context, framer=None, identity=None, address=None,
369369

370370
socketserver.ThreadingUDPServer.__init__(self,
371371
self.address, self.handler)
372-
self._BaseServer__shutdown_request = True
372+
# self._BaseServer__shutdown_request = True
373373

374374
def process_request(self, request, client):
375375
""" Callback for connecting a new client thread

pymodbus/transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def execute(self, request):
140140
full = True
141141
else:
142142
full = False
143+
c_str = str(self.client)
144+
if "modbusudpclient" in c_str.lower().strip():
145+
full = True
143146
response, last_exception = self._transact(request,
144147
expected_response_length,
145148
full=full

test/test_client_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def testBasicSyncUdpClient(self):
9191
client.socket = False
9292
client.close()
9393

94-
self.assertEqual("127.0.0.1:502", str(client))
94+
self.assertEqual("ModbusUdpClient(127.0.0.1:502)", str(client))
9595

9696
def testUdpClientAddressFamily(self):
9797
''' Test the Udp client get address family method'''
@@ -158,7 +158,7 @@ def testBasicSyncTcpClient(self):
158158
client.socket = False
159159
client.close()
160160

161-
self.assertEqual("127.0.0.1:502", str(client))
161+
self.assertEqual("ModbusTcpClient(127.0.0.1:502)", str(client))
162162

163163
def testTcpClientConnect(self):
164164
''' Test the tcp client connection method'''
@@ -234,7 +234,7 @@ def testBasicSyncSerialClient(self, mock_serial):
234234
client.socket = False
235235
client.close()
236236

237-
self.assertEqual('ascii baud[19200]', str(client))
237+
self.assertEqual('ModbusSerialClient(ascii baud[19200])', str(client))
238238

239239
def testSerialClientConnect(self):
240240
''' Test the serial client connection method'''

test/test_server_sync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#---------------------------------------------------------------------------#
3030
class MockServer(object):
3131
def __init__(self):
32-
self.framer = lambda _: "framer"
32+
self.framer = lambda _, client=None: "framer"
3333
self.decoder = "decoder"
3434
self.threads = []
3535
self.context = {}
@@ -59,7 +59,6 @@ def testBaseHandlerMethods(self):
5959
request = ReadCoilsRequest(1, 1)
6060
address = ('server', 12345)
6161
server = MockServer()
62-
6362
with patch.object(ModbusBaseRequestHandler, 'handle') as mock_handle:
6463
with patch.object(ModbusBaseRequestHandler, 'send') as mock_send:
6564
mock_handle.return_value = True

0 commit comments

Comments
 (0)