Skip to content

Commit cd9da27

Browse files
committed
Merge pull request #79 from BartDeWaal/master
Problems I encountered while making a modbus RTU server
2 parents 6c7edfc + 7a50def commit cd9da27

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

examples/common/synchronous-server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from pymodbus.datastore import ModbusSequentialDataBlock
2020
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
2121

22+
from pymodbus.transaction import ModbusRtuFramer
2223
#---------------------------------------------------------------------------#
2324
# configure the service logging
2425
#---------------------------------------------------------------------------#
@@ -103,6 +104,14 @@
103104
#---------------------------------------------------------------------------#
104105
# run the server you want
105106
#---------------------------------------------------------------------------#
107+
# Tcp:
106108
StartTcpServer(context, identity=identity, address=("localhost", 5020))
109+
110+
# Udp:
107111
#StartUdpServer(context, identity=identity, address=("localhost", 502))
112+
113+
# Ascii:
108114
#StartSerialServer(context, identity=identity, port='/dev/pts/3', timeout=1)
115+
116+
# RTU:
117+
#StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/pts/3', timeout=.005)

pymodbus/other_message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def decode(self, data):
4242
'''
4343
pass
4444

45-
def execute(self):
45+
def execute(self, context):
4646
''' Run a read exeception status request against the store
4747
4848
:returns: The populated response
@@ -143,7 +143,7 @@ def decode(self, data):
143143
'''
144144
pass
145145

146-
def execute(self):
146+
def execute(self, context):
147147
''' Run a read exeception status request against the store
148148
149149
:returns: The populated response
@@ -248,7 +248,7 @@ def decode(self, data):
248248
'''
249249
pass
250250

251-
def execute(self):
251+
def execute(self, context):
252252
''' Run a read exeception status request against the store
253253
254254
:returns: The populated response
@@ -358,7 +358,7 @@ def decode(self, data):
358358
'''
359359
pass
360360

361-
def execute(self):
361+
def execute(self, context):
362362
''' Run a read exeception status request against the store
363363
364364
:returns: The populated response

test/test_other_messages.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def testReadExceptionStatus(self):
3737
request = ReadExceptionStatusRequest()
3838
request.decode('\x12')
3939
self.assertEqual(request.encode(), '')
40-
self.assertEqual(request.execute().function_code, 0x07)
40+
self.assertEqual(request.execute(None).function_code, 0x07)
4141

4242
response = ReadExceptionStatusResponse(0x12)
4343
self.assertEqual(response.encode(), '\x12')
@@ -48,7 +48,7 @@ def testGetCommEventCounter(self):
4848
request = GetCommEventCounterRequest()
4949
request.decode('\x12')
5050
self.assertEqual(request.encode(), '')
51-
self.assertEqual(request.execute().function_code, 0x0b)
51+
self.assertEqual(request.execute(None).function_code, 0x0b)
5252

5353
response = GetCommEventCounterResponse(0x12)
5454
self.assertEqual(response.encode(), '\x00\x00\x00\x12')
@@ -63,7 +63,7 @@ def testGetCommEventLog(self):
6363
request = GetCommEventLogRequest()
6464
request.decode('\x12')
6565
self.assertEqual(request.encode(), '')
66-
self.assertEqual(request.execute().function_code, 0x0c)
66+
self.assertEqual(request.execute(None).function_code, 0x0c)
6767

6868
response = GetCommEventLogResponse()
6969
self.assertEqual(response.encode(), '\x06\x00\x00\x00\x00\x00\x00')
@@ -89,9 +89,9 @@ def testReportSlaveId(self):
8989
request = ReportSlaveIdRequest()
9090
request.decode('\x12')
9191
self.assertEqual(request.encode(), '')
92-
self.assertEqual(request.execute().function_code, 0x11)
92+
self.assertEqual(request.execute(None).function_code, 0x11)
9393

94-
response = ReportSlaveIdResponse(request.execute().identifier, True)
94+
response = ReportSlaveIdResponse(request.execute(None).identifier, True)
9595
self.assertEqual(response.encode(), '\x0apymodbus\xff')
9696
response.decode('\x03\x12\x00')
9797
self.assertEqual(response.status, False)

0 commit comments

Comments
 (0)