Skip to content

Commit

Permalink
Merge pull request pymodbus-dev#79 from BartDeWaal/master
Browse files Browse the repository at this point in the history
Problems I encountered while making a modbus RTU server
  • Loading branch information
bashwork committed Sep 26, 2015
2 parents 6c7edfc + 7a50def commit cd9da27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 9 additions & 0 deletions examples/common/synchronous-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

from pymodbus.transaction import ModbusRtuFramer
#---------------------------------------------------------------------------#
# configure the service logging
#---------------------------------------------------------------------------#
Expand Down Expand Up @@ -103,6 +104,14 @@
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))

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

# Ascii:
#StartSerialServer(context, identity=identity, port='/dev/pts/3', timeout=1)

# RTU:
#StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/pts/3', timeout=.005)
8 changes: 4 additions & 4 deletions pymodbus/other_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def decode(self, data):
'''
pass

def execute(self):
def execute(self, context):
''' Run a read exeception status request against the store
:returns: The populated response
Expand Down Expand Up @@ -143,7 +143,7 @@ def decode(self, data):
'''
pass

def execute(self):
def execute(self, context):
''' Run a read exeception status request against the store
:returns: The populated response
Expand Down Expand Up @@ -248,7 +248,7 @@ def decode(self, data):
'''
pass

def execute(self):
def execute(self, context):
''' Run a read exeception status request against the store
:returns: The populated response
Expand Down Expand Up @@ -358,7 +358,7 @@ def decode(self, data):
'''
pass

def execute(self):
def execute(self, context):
''' Run a read exeception status request against the store
:returns: The populated response
Expand Down
10 changes: 5 additions & 5 deletions test/test_other_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def testReadExceptionStatus(self):
request = ReadExceptionStatusRequest()
request.decode('\x12')
self.assertEqual(request.encode(), '')
self.assertEqual(request.execute().function_code, 0x07)
self.assertEqual(request.execute(None).function_code, 0x07)

response = ReadExceptionStatusResponse(0x12)
self.assertEqual(response.encode(), '\x12')
Expand All @@ -48,7 +48,7 @@ def testGetCommEventCounter(self):
request = GetCommEventCounterRequest()
request.decode('\x12')
self.assertEqual(request.encode(), '')
self.assertEqual(request.execute().function_code, 0x0b)
self.assertEqual(request.execute(None).function_code, 0x0b)

response = GetCommEventCounterResponse(0x12)
self.assertEqual(response.encode(), '\x00\x00\x00\x12')
Expand All @@ -63,7 +63,7 @@ def testGetCommEventLog(self):
request = GetCommEventLogRequest()
request.decode('\x12')
self.assertEqual(request.encode(), '')
self.assertEqual(request.execute().function_code, 0x0c)
self.assertEqual(request.execute(None).function_code, 0x0c)

response = GetCommEventLogResponse()
self.assertEqual(response.encode(), '\x06\x00\x00\x00\x00\x00\x00')
Expand All @@ -89,9 +89,9 @@ def testReportSlaveId(self):
request = ReportSlaveIdRequest()
request.decode('\x12')
self.assertEqual(request.encode(), '')
self.assertEqual(request.execute().function_code, 0x11)
self.assertEqual(request.execute(None).function_code, 0x11)

response = ReportSlaveIdResponse(request.execute().identifier, True)
response = ReportSlaveIdResponse(request.execute(None).identifier, True)
self.assertEqual(response.encode(), '\x0apymodbus\xff')
response.decode('\x03\x12\x00')
self.assertEqual(response.status, False)
Expand Down

0 comments on commit cd9da27

Please sign in to comment.