Skip to content

Commit

Permalink
Dev (#164)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dhoomakethu authored May 17, 2017
1 parent 4afaff7 commit 221da92
Show file tree
Hide file tree
Showing 62 changed files with 1,069 additions and 672 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ pymodbus.egg-info/
.vscode
.idea
.noseids

.idea/
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Version 1.2.0
Version 1.3.0
------------------------------------------------------------

* Timing improvements over MODBUS Serial interface
* Modbus RTU use 3.5 char silence before and after transactions
* Bug fix on FifoTransactionManager , flush stray data before transaction
* Update repository information
* Added ability to ignore missing slaves
* Added ability to revert to ZeroMode
* Passed a number of extra options through the stack
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ License Information
Pymodbus is built on top of code developed from/by:
* Copyright (c) 2001-2005 S.W.A.C. GmbH, Germany.
* Copyright (c) 2001-2005 S.W.A.C. Bohemia s.r.o., Czech Republic.

* Hynek Petrak, https://github.com/HynekPetrak
* Twisted Matrix

Expand Down
2 changes: 1 addition & 1 deletion examples/common/asynchronous-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
StartTcpServer(context, identity=identity, address=("localhost", 502))
StartTcpServer(context, identity=identity, address=("localhost", 5020))
#StartUdpServer(context, identity=identity, address=("localhost", 502))
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusRtuFramer)
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusAsciiFramer)
6 changes: 3 additions & 3 deletions examples/common/modbus-payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#---------------------------------------------------------------------------#
# We are going to use a simple client to send our requests
#---------------------------------------------------------------------------#
client = ModbusClient('127.0.0.1')
client = ModbusClient('127.0.0.1', port=5020)
client.connect()

#---------------------------------------------------------------------------#
Expand All @@ -43,7 +43,7 @@
builder.add_bits([0,1,0,1,1,0,1,0])
payload = builder.build()
address = 0x01
result = client.write_registers(address, payload, skip_encode=True)
result = client.write_registers(address, payload, skip_encode=True, unit=1)

#---------------------------------------------------------------------------#
# If you need to decode a collection of registers in a weird layout, the
Expand All @@ -60,7 +60,7 @@
#---------------------------------------------------------------------------#
address = 0x01
count = 8
result = client.read_input_registers(address, count)
result = client.read_input_registers(address, count, unit=1)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Little)
decoded = {
'string': decoder.decode_string(8),
Expand Down
17 changes: 11 additions & 6 deletions examples/common/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from time import time
from multiprocessing import log_to_stderr
from pymodbus.client.sync import ModbusTcpClient
from pymodbus.client.sync import ModbusSerialClient

#---------------------------------------------------------------------------#
# choose between threads or processes
#---------------------------------------------------------------------------#
#from multiprocessing import Process as Worker
from threading import Thread as Worker

from threading import Lock
_thread_lock = Lock()
#---------------------------------------------------------------------------#
# initialize the test
#---------------------------------------------------------------------------#
Expand All @@ -29,8 +31,8 @@
# * cycles - the total number of requests to send
# * host - the host to send the requests to
#---------------------------------------------------------------------------#
workers = 1
cycles = 10000
workers = 10
cycles = 1000
host = '127.0.0.1'


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

try:
count = 0
client = ModbusTcpClient(host)
# client = ModbusTcpClient(host, port=5020)
client = ModbusSerialClient(method="rtu", port="/dev/ttyp0", baudrate=9600)
while count < cycles:
result = client.read_holding_registers(10, 1).getRegister(0)
count += 1
with _thread_lock:
result = client.read_holding_registers(10, 1, unit=1).getRegister(0)
count += 1
except: logger.exception("failed to run test successfully")
logger.debug("finished worker: %d" % os.getpid())

Expand All @@ -76,3 +80,4 @@ def single_client_test(host, cycles):
any(p.join() for p in procs) # wait for the workers to finish
stop = time()
print "%d requests/second" % ((1.0 * cycles) / (stop - start))
print "time taken to complete %s cycle by %s workers is %s seconds" % (cycles, workers, stop-start)
63 changes: 32 additions & 31 deletions examples/common/synchronous-client-ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#---------------------------------------------------------------------------#
# import the various server implementations
#---------------------------------------------------------------------------#
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
# from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

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

#---------------------------------------------------------------------------#
Expand Down Expand Up @@ -65,35 +66,35 @@
#---------------------------------------------------------------------------#
# information requests
#---------------------------------------------------------------------------#
rq = ReadDeviceInformationRequest()
rq = ReadDeviceInformationRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
assert(rr.function_code < 0x80) # test that we are not an error
assert(rr.information[0] == 'proconX Pty Ltd') # test the vendor name
assert(rr.information[1] == 'FT-MBSV') # test the product code
assert(rr.information[2] == 'EXPERIMENTAL') # test the code revision
assert(rr.information[0] == 'Pymodbus') # test the vendor name
assert(rr.information[1] == 'PM') # test the product code
assert(rr.information[2] == '1.0') # test the code revision

rq = ReportSlaveIdRequest()
rq = ReportSlaveIdRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
# assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.identifier == 0x00) # test the slave identifier
#assert(rr.status == 0x00) # test that the status is ok

rq = ReadExceptionStatusRequest()
rq = ReadExceptionStatusRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
assert(rr.function_code < 0x80) # test that we are not an error
assert(rr.status == 0x55) # test the status code
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.status == 0x55) # test the status code

rq = GetCommEventCounterRequest()
rq = GetCommEventCounterRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
#assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
#assert(rr.status == True) # test the status code
#assert(rr.count == 0x00) # test the status code

rq = GetCommEventLogRequest()
rq = GetCommEventLogRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
#assert(rr.function_code < 0x80) # test that we are not an error
Expand All @@ -105,68 +106,68 @@
#---------------------------------------------------------------------------#
# diagnostic requests
#---------------------------------------------------------------------------#
rq = ReturnQueryDataRequest()
rq = ReturnQueryDataRequest(unit=1)
rr = client.execute(rq)
assert(rr == None) # not supported by reference
# assert(rr == None) # not supported by reference
#assert(rr.message[0] == 0x0000) # test the resulting message

rq = RestartCommunicationsOptionRequest()
rq = RestartCommunicationsOptionRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference
#assert(rr.message == 0x0000) # test the resulting message

rq = ReturnDiagnosticRegisterRequest()
rq = ReturnDiagnosticRegisterRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ChangeAsciiInputDelimiterRequest()
rq = ChangeAsciiInputDelimiterRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ForceListenOnlyModeRequest()
rq = ForceListenOnlyModeRequest(unit=1)
client.execute(rq) # does not send a response

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

rq = ReturnBusCommunicationErrorCountRequest()
rq = ReturnBusCommunicationErrorCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnBusExceptionErrorCountRequest()
rq = ReturnBusExceptionErrorCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveMessageCountRequest()
rq = ReturnSlaveMessageCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveNoResponseCountRequest()
rq = ReturnSlaveNoResponseCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveNAKCountRequest()
rq = ReturnSlaveNAKCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveBusyCountRequest()
rq = ReturnSlaveBusyCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnSlaveBusCharacterOverrunCountRequest()
rq = ReturnSlaveBusCharacterOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ReturnIopOverrunCountRequest()
rq = ReturnIopOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = ClearOverrunCountRequest()
rq = ClearOverrunCountRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

rq = GetClearModbusPlusRequest()
rq = GetClearModbusPlusRequest(unit=1)
rr = client.execute(rq)
#assert(rr == None) # not supported by reference

Expand Down
39 changes: 23 additions & 16 deletions examples/common/synchronous-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#---------------------------------------------------------------------------#
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#from pymodbus.client.sync import ModbusUdpClient as ModbusClient
#from pymodbus.client.sync import ModbusSerialClient as ModbusClient
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient

#---------------------------------------------------------------------------#
# configure the client logging
Expand Down Expand Up @@ -55,9 +55,9 @@
#
# client = ModbusClient('localhost', retries=3, retry_on_empty=True)
#---------------------------------------------------------------------------#
client = ModbusClient('localhost', port=502)
client = ModbusClient('localhost', port=5020)
#client = ModbusClient(method='ascii', port='/dev/pts/2', timeout=1)
#client = ModbusClient(method='rtu', port='/dev/pts/2', timeout=1)
# client = ModbusClient(method='rtu', port='/dev/ttyp0', timeout=1)
client.connect()

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

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

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

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

rq = client.write_register(1, 10)
rr = client.read_holding_registers(1,1)

rr = client.read_discrete_inputs(0, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error

rq = client.write_register(1, 10, unit=1)
rr = client.read_holding_registers(1, 1, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.registers[0] == 10) # test the expected value

rq = client.write_registers(1, [10]*8)
rr = client.read_input_registers(1,8)
rq = client.write_registers(1, [10]*8, unit=1)
rr = client.read_holding_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rr.registers == [10]*8) # test the expected value

rr = client.read_input_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error

arguments = {
'read_address': 1,
'read_count': 8,
'write_address': 1,
'write_registers': [20]*8,
}
rq = client.readwrite_registers(**arguments)
rr = client.read_input_registers(1,8)
rq = client.readwrite_registers(unit=1, **arguments)
rr = client.read_holding_registers(1, 8, unit=1)
assert(rq.function_code < 0x80) # test that we are not an error
assert(rq.registers == [20]*8) # test the expected value
assert(rr.registers == [20]*8) # test the expected value
Expand Down
8 changes: 4 additions & 4 deletions examples/common/synchronous-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.VendorUrl = 'http://github.com/riptideio/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'

#---------------------------------------------------------------------------#
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=identity, address=("localhost", 5020))
# StartTcpServer(context, identity=identity, address=("localhost", 5020))

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

# RTU:
#StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/pts/3', timeout=.005)
StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, port='/dev/ptyp0', timeout=.005, baudrate=9600)
2 changes: 2 additions & 0 deletions examples/contrib/modicon-payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class ModiconPayloadDecoder(object):
'''

def __init__(self, payload, endian):

''' Initialize a new payload decoder
:param payload: The payload to decode with
Expand All @@ -164,6 +165,7 @@ def __init__(self, payload, endian):
self._pointer = 0x00
self._endian = endian


@staticmethod
def fromRegisters(registers, endian=Endian.Little):
''' Initialize a payload decoder with the result of
Expand Down
Loading

0 comments on commit 221da92

Please sign in to comment.