Skip to content

Commit 6ef6787

Browse files
authored
Dev (#164)
* Refactored and simplified calculation of RTU frames, added missing unit tests * - fixing a few small issues - bringing a few areas of coverage back up * adding installer test script * enabling the checksum tests in check frame, fixing tests * * Updating documentation * Adding code to handle messages that do not respond * Fixes issue 41 * cleaning up the build tools a bit * Adding more commands to the setup.py - pep8, lint, 2to3 Fixed a few pep8/lint bugs to test * moving files around * pep8 and cleanup * more cleanup * Fixes issue 47 * adding another quick example * cutting 200 pep8 errors * working on py3 merge * updating to python3 * reverting back changes, remember Switch flag next time * adding some magic methods, just cause * adding documentation pdf * Fixes issue 49 * Adds True and False constants for older python versions. Update issue 50 * adding tests for a few fixes * Fixes issue 51 * fixing tests broken by interface change * Updates issue 52 * Fixes issue 53 * Fix to add Python < 2.5 compatibility This fix simply removes all the ternaries that were added in Python 2.5. Fixes issue 50 * adding a mostly complete diagnostic register implementation * Adding more documentation and helpful factory methods. The documentation added was to address some questions with the synchronous and asynchrounous server implementations as well as the functionality of the data contexts. The factory methods were added by request to simplify the creation of a fully populated DataBlock address space. * adding modbus plus registers * adding endian ability to payload builder * Finishing the remaining modbus protocol * Adding the remaining portions of the protocol (request/response) * Tieing these into the factory decoder * Adding tests to cover the new code (need more) * Fixing a few bugs found along the way * finished file read/write record requests * documentation, more tests, fixing extra commands * adding more tests * Fixing the client/server async/sync implementations - asynchronous client/server for tcp working and tested - synchronous client/server for tcp/udp working and tested - adding tests to exercise the synchronous client/server - more documentation * adding test stubs to get full coverage count * working on jamod, need to set up more complete project * adding GetDeviceInformationRequest * adding read device information to decoder factory * fixing some example errors * working on the serial implementations * fixing the synchronous server implementation * updating functional tests and documentation for sync-serial * updating tac files * Updating the documentation for the serial client/servers * adding readme to root * Fixes issue 56 * Fixes issue 1 * adding a requirements file for virtualenv folk * adding more cohesive code to the payload utilities * forgot to add the new example to the doc index * Fixing the rtu size calculation isse #55 on google code * using the endian flag in register factory * fixing bad documentation * fixing issue 58 on google code * Fix binary framer and add start and end tokens Fixes a TypeError occuring while escaping token bytes in the message and adds the start and end tokens to the packet. * Adding checking in the client for an unconnected socket. * Fixing issue 60 on google code (including ez_setup) * fixing github issue #7 * adding tests and two utilities * adding message parser utility * Fixing extended message decoding * Now correctly decoding sub function messages (diagnostic) * Message parser now finished and documented * Fixed broken logger unit test * ModbusSparseDataBlock handled dictionaries incorrectly (they have an __iter__ attribute). Changed 'if' to 'elif' * Updating the Readme.rst to explain how to install in zero dependency mode. * Fixing issue #10 * updating the client documentation * updating the server context documentation * fixes #9 on github * fixing the factory decoding and adding examples * pushing to version 1.0 * Fixing a bug in the asynchronous client that slipped through. * complete tests for the sync client * cleaning up some pep8 errors * finished unit tests for async client * adding another test to the test-install script * finished covering sync client * updating documentation * adding another example, adding debug checks * Fixing the serial implementation of everything * updating lots of reference documentation * fixing the fifo semantics of serial clients * using transaction manager in async clients * fixing references * fixing incorrect rtu lenght calculation * Add optional server_address to Sync and Async TCP/UDP Server API * Improve erver_address defaults to passing None * adding a few messages * Adding a message encoding generator for testing. - fixed messages not passing **kwargs to base - fixed binary framer off by 1 - fixed mei_message rtu size tests - added a message generator to use with message parser - fixed message parser with ascii - tested message parser with all formats (added to messages) * adding documentation for message formats * updating documentation and being pedantic * Allowing overloading of message encoding * allow codes like payload builder to encode * added IPayloadBuilder interface (future) * renamed builder methods to reflect vision * added error code decoding to name * fixed affected tests * Cleaning up the build tools - moving custom datastores to examples - bumping required versions - making the debug server console optional - updating documentation * adding support for pydev * fixing broken nosetest (/dev/pts) and pydev issues * adding bcd payload builder * reworking contrib packages * adding bcd payload contrib * moving complex examples to contrib * syncing version on pypi * adding server rest api * moving web -> bottle * fixing documentation * adding gui base * adding initial manager page * adding data view * fixing error in example * adding the ability to override sync client framer * updating the performance test * fixing documentation * fixing memory leak in sync client * adding modicon encoder/decoder * Fix bogus calculation in ModbusSocketFramer.checkFrame (one of the tests also seemed wrong, I had to fix it) * Adding sunspec client example * Changing @staticmethod to @classmethod to fix inheritance * adding method to retrieve all the device blocks * adding the initial mapper interface * adding ideas in progress * adding a modbus datastore saver * making lrc/crc read stdin * adding the callback server example * adding a periodic updating example * fixing documentation * adding fix for stuck RTU streams * fixing documentation error * Adding an example for changing framers - new example changing-framers.py - added documentation link * Reworking the transaction managers to be explicit - Serial framers use the FIFO manager (results in order) - Socket framers use the Dict manager (tid -> result) - Fixed tests and removed bad global managers - Managers no longer use global state (now instance) * Bumping the version and adding a changelog * Fixing a logic error in client code - Now correctly choosing transaction manager * Fixing 2to3 common warnings * Fixed example typo in readme * Adding slave context delete ability - Fixes #20 * Fixing google code issue 69 - custom-message example had bugs - http://code.google.com/p/pymodbus/issues/detail?id=69 * Fixed docstring in synchronous serial client connect() method I think there was a copy/paste error in the docstring. It said tcp but I think it is supposed to be serial. * Fix for issue #21 * Allowing options to be passed through - This fixes issue #21 - Options now go to the transaction manager * Adding source_address to TCP client inputs * Typo * Typo * Typo * Typo * Adding some new examples * modbus scraper (and documentation) * thread safe datastore (and documentation) * Adding a concurrent client example * Allow specification of client connection handler in Modbus...Server o ModbusTcpServer and ModbusUdpServer allows handler class other than default Modbus{Connected,Disconnected}RequestHandler o Add debug logging on request failure, to help diagnose root causes * Fixes #46 * Fixes #48 * Adds the option to drop into zero mode for slaves * Fixes #42 * Bumping the version to 1.3.0 * add missing self operator The parameter values of the constructor within class WriteMultipleRegistersRequest can specified as single value or list of values. But if a single value is given the missing self operator on line 137 leads to crash in line 138 with error: TypeError("object of type 'int' has no len()",) * typo: fix spelling of Parameter Signed-off-by: Karl Palsson <[email protected]> * async: missing slaves: add missing imports 1e0bcde is missing imports into the async server, the import was only added to the sync server. Further fix for #42 Signed-off-by: Karl Palsson <[email protected]> * Fix zero_mode argument for ModbusSlaveContext Using "-" in the argument name causes SyntaxError 'non-keyword arg after keyword arg' * Fix typo in constants * Adding an example and adding tcp timeout * fixes #70 * Endianness now used in packing bytes * Adding a libmodbus wrapper * adding new contrib example of libmodbus client * updating example documentation so users can find it * closes #73 * 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. * Add Modbus RTU syncronous server example * Signal handlers to stop in shutdown(). * WriteMultipleRegistersRequest: Handle values=None case Currently, if None is passed in explicitly, or if values is not given, the 'values' object is correctly identified as *not* having an __iter__ attribute, but is incorrectly identified as being a valid register value. This breaks testInvalidWriteMultipleRegistersRequest. Solution: if we see None, replace this with [] and skip the check for __iter__. * Fix payload tests. Looking at the "encoded" string, it looks identical to that of the big endian encoding string, and my understanding is that the data shown in "encoded" *IS* big-endian, not little-endian. I have no idea how this passed before, but it passes now. * sync.ModbusUdpClient: Correct reference to settimeout. I could not find a 'settimeout' (case-insensitive) anywhere in the codebase other than on this line, but I *did* see it was a method of socket.socket. So I'll assume that this was *supposed* to be calling socket.socket.settimeout. * test-client-sync: Fix UDP connection test. Rather than passing in a vanilla object, we should pass in something that implements the settimeout method. * Lazily initialize InstallManagementConsole Simply importing the management console takes ~0.3 sec on an 1GHz Atom. Since it is (I suspect) often not used, lazily importing it should help startup for many programs. * Fixes the UDP client socket timeout bug fixes #51 * Implement mask_write_register method in client mixin * Workaround for bug 101 #101 * Workaround for bug 101 #101 * Riptide 1.3.0 pymodbus internal pre-release (riptide1) with dhoomakethu's fix for bashwork#101. * Riptide 1.3.0 pymodbus internal pre-release (riptide1) with dhoomakethu's fix for bashwork#101. * Use a PEP 404 compliant version. Start at rc93101 to usurp any other real release candidates. * Use a PEP 404 compliant version. Start at rc93101 to usurp any other real release candidates. * Document Riptide specific instructions. * Include Workaround for bug 101 bashwork#101 * Include Workaround for bug 101 bashwork#101 * Better tag names. * pymodbus fix for modes RTU error cases. * version bumped to c93103 * version bumped to c93103 * fixed issue with pymodbus timing over serial * fixed issue with pymodbus timing over serial * Add RIPTIDE.md to .gitignore * bump version to rc93105 * fix merge conflicts * fix version file * fix unit test failures * cleanup * #121 changelog updated * Misc update Add __maintainer__ field in setup.py * 1. #162, creating universal distribution for py2 and py3 2. Merge PR #152 , create compatible versions * fix test failures * fix ReadDeviceInformationRequest encoding probelm
1 parent c3d4685 commit 6ef6787

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1069
-672
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ pymodbus.egg-info/
77
.vscode
88
.idea
99
.noseids
10+
11+
.idea/

CHANGELOG.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
Version 1.2.0
1+
Version 1.3.0
22
------------------------------------------------------------
3-
3+
* Timing improvements over MODBUS Serial interface
4+
* Modbus RTU use 3.5 char silence before and after transactions
5+
* Bug fix on FifoTransactionManager , flush stray data before transaction
6+
* Update repository information
47
* Added ability to ignore missing slaves
58
* Added ability to revert to ZeroMode
69
* Passed a number of extra options through the stack

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ License Information
123123
Pymodbus is built on top of code developed from/by:
124124
* Copyright (c) 2001-2005 S.W.A.C. GmbH, Germany.
125125
* Copyright (c) 2001-2005 S.W.A.C. Bohemia s.r.o., Czech Republic.
126+
126127
* Hynek Petrak, https://github.com/HynekPetrak
127128
* Twisted Matrix
128129

examples/common/asynchronous-server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
#---------------------------------------------------------------------------#
104104
# run the server you want
105105
#---------------------------------------------------------------------------#
106-
StartTcpServer(context, identity=identity, address=("localhost", 502))
106+
StartTcpServer(context, identity=identity, address=("localhost", 5020))
107107
#StartUdpServer(context, identity=identity, address=("localhost", 502))
108108
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusRtuFramer)
109109
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusAsciiFramer)

examples/common/modbus-payload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#---------------------------------------------------------------------------#
2020
# We are going to use a simple client to send our requests
2121
#---------------------------------------------------------------------------#
22-
client = ModbusClient('127.0.0.1')
22+
client = ModbusClient('127.0.0.1', port=5020)
2323
client.connect()
2424

2525
#---------------------------------------------------------------------------#
@@ -43,7 +43,7 @@
4343
builder.add_bits([0,1,0,1,1,0,1,0])
4444
payload = builder.build()
4545
address = 0x01
46-
result = client.write_registers(address, payload, skip_encode=True)
46+
result = client.write_registers(address, payload, skip_encode=True, unit=1)
4747

4848
#---------------------------------------------------------------------------#
4949
# If you need to decode a collection of registers in a weird layout, the
@@ -60,7 +60,7 @@
6060
#---------------------------------------------------------------------------#
6161
address = 0x01
6262
count = 8
63-
result = client.read_input_registers(address, count)
63+
result = client.read_input_registers(address, count, unit=1)
6464
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Little)
6565
decoded = {
6666
'string': decoder.decode_string(8),

examples/common/performance.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
from time import time
1414
from multiprocessing import log_to_stderr
1515
from pymodbus.client.sync import ModbusTcpClient
16+
from pymodbus.client.sync import ModbusSerialClient
1617

1718
#---------------------------------------------------------------------------#
1819
# choose between threads or processes
1920
#---------------------------------------------------------------------------#
2021
#from multiprocessing import Process as Worker
2122
from threading import Thread as Worker
22-
23+
from threading import Lock
24+
_thread_lock = Lock()
2325
#---------------------------------------------------------------------------#
2426
# initialize the test
2527
#---------------------------------------------------------------------------#
@@ -29,8 +31,8 @@
2931
# * cycles - the total number of requests to send
3032
# * host - the host to send the requests to
3133
#---------------------------------------------------------------------------#
32-
workers = 1
33-
cycles = 10000
34+
workers = 10
35+
cycles = 1000
3436
host = '127.0.0.1'
3537

3638

@@ -54,10 +56,12 @@ def single_client_test(host, cycles):
5456

5557
try:
5658
count = 0
57-
client = ModbusTcpClient(host)
59+
# client = ModbusTcpClient(host, port=5020)
60+
client = ModbusSerialClient(method="rtu", port="/dev/ttyp0", baudrate=9600)
5861
while count < cycles:
59-
result = client.read_holding_registers(10, 1).getRegister(0)
60-
count += 1
62+
with _thread_lock:
63+
result = client.read_holding_registers(10, 1, unit=1).getRegister(0)
64+
count += 1
6165
except: logger.exception("failed to run test successfully")
6266
logger.debug("finished worker: %d" % os.getpid())
6367

@@ -76,3 +80,4 @@ def single_client_test(host, cycles):
7680
any(p.join() for p in procs) # wait for the workers to finish
7781
stop = time()
7882
print "%d requests/second" % ((1.0 * cycles) / (stop - start))
83+
print "time taken to complete %s cycle by %s workers is %s seconds" % (cycles, workers, stop-start)

examples/common/synchronous-client-ext.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#---------------------------------------------------------------------------#
1111
# import the various server implementations
1212
#---------------------------------------------------------------------------#
13-
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
13+
# from pymodbus.client.sync import ModbusTcpClient as ModbusClient
1414
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
15-
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
15+
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
1616

1717
#---------------------------------------------------------------------------#
1818
# configure the client logging
@@ -32,7 +32,8 @@
3232
# It should be noted that you can supply an ipv4 or an ipv6 host address for
3333
# both the UDP and TCP clients.
3434
#---------------------------------------------------------------------------#
35-
client = ModbusClient('127.0.0.1')
35+
client = ModbusClient(method='rtu', port="/dev/ttyp0")
36+
# client = ModbusClient('127.0.0.1', port=5020)
3637
client.connect()
3738

3839
#---------------------------------------------------------------------------#
@@ -65,35 +66,35 @@
6566
#---------------------------------------------------------------------------#
6667
# information requests
6768
#---------------------------------------------------------------------------#
68-
rq = ReadDeviceInformationRequest()
69+
rq = ReadDeviceInformationRequest(unit=1)
6970
rr = client.execute(rq)
7071
#assert(rr == None) # not supported by reference
7172
assert(rr.function_code < 0x80) # test that we are not an error
72-
assert(rr.information[0] == 'proconX Pty Ltd') # test the vendor name
73-
assert(rr.information[1] == 'FT-MBSV') # test the product code
74-
assert(rr.information[2] == 'EXPERIMENTAL') # test the code revision
73+
assert(rr.information[0] == 'Pymodbus') # test the vendor name
74+
assert(rr.information[1] == 'PM') # test the product code
75+
assert(rr.information[2] == '1.0') # test the code revision
7576

76-
rq = ReportSlaveIdRequest()
77+
rq = ReportSlaveIdRequest(unit=1)
7778
rr = client.execute(rq)
78-
assert(rr == None) # not supported by reference
79+
# assert(rr == None) # not supported by reference
7980
#assert(rr.function_code < 0x80) # test that we are not an error
8081
#assert(rr.identifier == 0x00) # test the slave identifier
8182
#assert(rr.status == 0x00) # test that the status is ok
8283

83-
rq = ReadExceptionStatusRequest()
84+
rq = ReadExceptionStatusRequest(unit=1)
8485
rr = client.execute(rq)
8586
#assert(rr == None) # not supported by reference
86-
assert(rr.function_code < 0x80) # test that we are not an error
87-
assert(rr.status == 0x55) # test the status code
87+
#assert(rr.function_code < 0x80) # test that we are not an error
88+
#assert(rr.status == 0x55) # test the status code
8889

89-
rq = GetCommEventCounterRequest()
90+
rq = GetCommEventCounterRequest(unit=1)
9091
rr = client.execute(rq)
91-
assert(rr == None) # not supported by reference
92+
#assert(rr == None) # not supported by reference
9293
#assert(rr.function_code < 0x80) # test that we are not an error
9394
#assert(rr.status == True) # test the status code
9495
#assert(rr.count == 0x00) # test the status code
9596

96-
rq = GetCommEventLogRequest()
97+
rq = GetCommEventLogRequest(unit=1)
9798
rr = client.execute(rq)
9899
#assert(rr == None) # not supported by reference
99100
#assert(rr.function_code < 0x80) # test that we are not an error
@@ -105,68 +106,68 @@
105106
#---------------------------------------------------------------------------#
106107
# diagnostic requests
107108
#---------------------------------------------------------------------------#
108-
rq = ReturnQueryDataRequest()
109+
rq = ReturnQueryDataRequest(unit=1)
109110
rr = client.execute(rq)
110-
assert(rr == None) # not supported by reference
111+
# assert(rr == None) # not supported by reference
111112
#assert(rr.message[0] == 0x0000) # test the resulting message
112113

113-
rq = RestartCommunicationsOptionRequest()
114+
rq = RestartCommunicationsOptionRequest(unit=1)
114115
rr = client.execute(rq)
115116
#assert(rr == None) # not supported by reference
116117
#assert(rr.message == 0x0000) # test the resulting message
117118

118-
rq = ReturnDiagnosticRegisterRequest()
119+
rq = ReturnDiagnosticRegisterRequest(unit=1)
119120
rr = client.execute(rq)
120121
#assert(rr == None) # not supported by reference
121122

122-
rq = ChangeAsciiInputDelimiterRequest()
123+
rq = ChangeAsciiInputDelimiterRequest(unit=1)
123124
rr = client.execute(rq)
124125
#assert(rr == None) # not supported by reference
125126

126-
rq = ForceListenOnlyModeRequest()
127+
rq = ForceListenOnlyModeRequest(unit=1)
127128
client.execute(rq) # does not send a response
128129

129130
rq = ClearCountersRequest()
130131
rr = client.execute(rq)
131132
#assert(rr == None) # not supported by reference
132133

133-
rq = ReturnBusCommunicationErrorCountRequest()
134+
rq = ReturnBusCommunicationErrorCountRequest(unit=1)
134135
rr = client.execute(rq)
135136
#assert(rr == None) # not supported by reference
136137

137-
rq = ReturnBusExceptionErrorCountRequest()
138+
rq = ReturnBusExceptionErrorCountRequest(unit=1)
138139
rr = client.execute(rq)
139140
#assert(rr == None) # not supported by reference
140141

141-
rq = ReturnSlaveMessageCountRequest()
142+
rq = ReturnSlaveMessageCountRequest(unit=1)
142143
rr = client.execute(rq)
143144
#assert(rr == None) # not supported by reference
144145

145-
rq = ReturnSlaveNoResponseCountRequest()
146+
rq = ReturnSlaveNoResponseCountRequest(unit=1)
146147
rr = client.execute(rq)
147148
#assert(rr == None) # not supported by reference
148149

149-
rq = ReturnSlaveNAKCountRequest()
150+
rq = ReturnSlaveNAKCountRequest(unit=1)
150151
rr = client.execute(rq)
151152
#assert(rr == None) # not supported by reference
152153

153-
rq = ReturnSlaveBusyCountRequest()
154+
rq = ReturnSlaveBusyCountRequest(unit=1)
154155
rr = client.execute(rq)
155156
#assert(rr == None) # not supported by reference
156157

157-
rq = ReturnSlaveBusCharacterOverrunCountRequest()
158+
rq = ReturnSlaveBusCharacterOverrunCountRequest(unit=1)
158159
rr = client.execute(rq)
159160
#assert(rr == None) # not supported by reference
160161

161-
rq = ReturnIopOverrunCountRequest()
162+
rq = ReturnIopOverrunCountRequest(unit=1)
162163
rr = client.execute(rq)
163164
#assert(rr == None) # not supported by reference
164165

165-
rq = ClearOverrunCountRequest()
166+
rq = ClearOverrunCountRequest(unit=1)
166167
rr = client.execute(rq)
167168
#assert(rr == None) # not supported by reference
168169

169-
rq = GetClearModbusPlusRequest()
170+
rq = GetClearModbusPlusRequest(unit=1)
170171
rr = client.execute(rq)
171172
#assert(rr == None) # not supported by reference
172173

examples/common/synchronous-client.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#---------------------------------------------------------------------------#
1919
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
2020
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
21-
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
21+
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient
2222

2323
#---------------------------------------------------------------------------#
2424
# configure the client logging
@@ -55,9 +55,9 @@
5555
#
5656
# client = ModbusClient('localhost', retries=3, retry_on_empty=True)
5757
#---------------------------------------------------------------------------#
58-
client = ModbusClient('localhost', port=502)
58+
client = ModbusClient('localhost', port=5020)
5959
#client = ModbusClient(method='ascii', port='/dev/pts/2', timeout=1)
60-
#client = ModbusClient(method='rtu', port='/dev/pts/2', timeout=1)
60+
# client = ModbusClient(method='rtu', port='/dev/ttyp0', timeout=1)
6161
client.connect()
6262

6363
#---------------------------------------------------------------------------#
@@ -67,7 +67,7 @@
6767
# individual request. This can be done by specifying the `unit` parameter
6868
# which defaults to `0x00`
6969
#---------------------------------------------------------------------------#
70-
rr = client.read_coils(1, 1, unit=0x02)
70+
rr = client.read_coils(1, 1, unit=0x01)
7171

7272
#---------------------------------------------------------------------------#
7373
# example requests
@@ -81,39 +81,46 @@
8181
# Keep both of these cases in mind when testing as the following will
8282
# _only_ pass with the supplied async modbus server (script supplied).
8383
#---------------------------------------------------------------------------#
84-
rq = client.write_coil(1, True)
85-
rr = client.read_coils(1,1)
84+
rq = client.write_coil(0, True, unit=1)
85+
rr = client.read_coils(0, 1, unit=1)
8686
assert(rq.function_code < 0x80) # test that we are not an error
8787
assert(rr.bits[0] == True) # test the expected value
8888

89-
rq = client.write_coils(1, [True]*8)
90-
rr = client.read_coils(1,8)
89+
rq = client.write_coils(1, [True]*8, unit=1)
90+
rr = client.read_coils(1, 8, unit=1)
9191
assert(rq.function_code < 0x80) # test that we are not an error
9292
assert(rr.bits == [True]*8) # test the expected value
9393

94-
rq = client.write_coils(1, [False]*8)
95-
rr = client.read_discrete_inputs(1,8)
94+
rq = client.write_coils(1, [False]*8, unit=1)
95+
rr = client.read_coils(1, 8, unit=1)
9696
assert(rq.function_code < 0x80) # test that we are not an error
9797
assert(rr.bits == [False]*8) # test the expected value
9898

99-
rq = client.write_register(1, 10)
100-
rr = client.read_holding_registers(1,1)
99+
100+
rr = client.read_discrete_inputs(0, 8, unit=1)
101+
assert(rq.function_code < 0x80) # test that we are not an error
102+
103+
rq = client.write_register(1, 10, unit=1)
104+
rr = client.read_holding_registers(1, 1, unit=1)
101105
assert(rq.function_code < 0x80) # test that we are not an error
102106
assert(rr.registers[0] == 10) # test the expected value
103107

104-
rq = client.write_registers(1, [10]*8)
105-
rr = client.read_input_registers(1,8)
108+
rq = client.write_registers(1, [10]*8, unit=1)
109+
rr = client.read_holding_registers(1, 8, unit=1)
106110
assert(rq.function_code < 0x80) # test that we are not an error
107111
assert(rr.registers == [10]*8) # test the expected value
108112

113+
rr = client.read_input_registers(1, 8, unit=1)
114+
assert(rq.function_code < 0x80) # test that we are not an error
115+
109116
arguments = {
110117
'read_address': 1,
111118
'read_count': 8,
112119
'write_address': 1,
113120
'write_registers': [20]*8,
114121
}
115-
rq = client.readwrite_registers(**arguments)
116-
rr = client.read_input_registers(1,8)
122+
rq = client.readwrite_registers(unit=1, **arguments)
123+
rr = client.read_holding_registers(1, 8, unit=1)
117124
assert(rq.function_code < 0x80) # test that we are not an error
118125
assert(rq.registers == [20]*8) # test the expected value
119126
assert(rr.registers == [20]*8) # test the expected value

examples/common/synchronous-server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@
9696
identity = ModbusDeviceIdentification()
9797
identity.VendorName = 'Pymodbus'
9898
identity.ProductCode = 'PM'
99-
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
99+
identity.VendorUrl = 'http://github.com/riptideio/pymodbus/'
100100
identity.ProductName = 'Pymodbus Server'
101101
identity.ModelName = 'Pymodbus Server'
102102
identity.MajorMinorRevision = '1.0'
103103

104-
#---------------------------------------------------------------------------#
104+
#---------------------------------------------------------------------------#
105105
# run the server you want
106106
#---------------------------------------------------------------------------#
107107
# Tcp:
108-
StartTcpServer(context, identity=identity, address=("localhost", 5020))
108+
# StartTcpServer(context, identity=identity, address=("localhost", 5020))
109109

110110
# Udp:
111111
#StartUdpServer(context, identity=identity, address=("localhost", 502))
@@ -114,4 +114,4 @@
114114
#StartSerialServer(context, identity=identity, port='/dev/pts/3', timeout=1)
115115

116116
# RTU:
117-
#StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/pts/3', timeout=.005)
117+
StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/ptyp0', timeout=.005, baudrate=9600)

examples/contrib/modicon-payload.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class ModiconPayloadDecoder(object):
156156
'''
157157

158158
def __init__(self, payload, endian):
159+
159160
''' Initialize a new payload decoder
160161
161162
:param payload: The payload to decode with
@@ -164,6 +165,7 @@ def __init__(self, payload, endian):
164165
self._pointer = 0x00
165166
self._endian = endian
166167

168+
167169
@staticmethod
168170
def fromRegisters(registers, endian=Endian.Little):
169171
''' Initialize a payload decoder with the result of

0 commit comments

Comments
 (0)