From a2f0d0af3adb9eb16e1e228010155001fa88c8db Mon Sep 17 00:00:00 2001 From: Bart de Waal Date: Thu, 2 Apr 2015 22:14:55 +0200 Subject: [PATCH 1/2] Execute methods of Requests accept context There were errors whenever a request that got handles in other_message.py got it's execute method called, as it was being called with a context parameter. The functions now accept this parameter, although they don't do anything with it. The tests have also been updated. --- pymodbus/other_message.py | 8 ++++---- test/test_other_messages.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pymodbus/other_message.py b/pymodbus/other_message.py index 88e1be2ec..c122bb019 100644 --- a/pymodbus/other_message.py +++ b/pymodbus/other_message.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/test_other_messages.py b/test/test_other_messages.py index 67e07a2ed..efa80c0dc 100644 --- a/test/test_other_messages.py +++ b/test/test_other_messages.py @@ -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') @@ -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') @@ -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') @@ -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) From 7a50def9c1cf0be29a8fe3a986bda91e12b9871d Mon Sep 17 00:00:00 2001 From: Bart de Waal Date: Thu, 2 Apr 2015 22:25:39 +0200 Subject: [PATCH 2/2] Add Modbus RTU syncronous server example --- examples/common/synchronous-server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/common/synchronous-server.py b/examples/common/synchronous-server.py index d10d78d8e..f46386472 100755 --- a/examples/common/synchronous-server.py +++ b/examples/common/synchronous-server.py @@ -19,6 +19,7 @@ from pymodbus.datastore import ModbusSequentialDataBlock from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext +from pymodbus.transaction import ModbusRtuFramer #---------------------------------------------------------------------------# # configure the service logging #---------------------------------------------------------------------------# @@ -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)