-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into poursuite_python3
- Loading branch information
Showing
43 changed files
with
1,852 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +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 <[email protected]> | ||
* Hynek Petrak, https://github.com/HynekPetrak | ||
* Twisted Matrix | ||
|
||
Released under the BSD License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Modbus Concurrent Client Example | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/contrib/concurrent-client.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Custom Datablock Example | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/common/custom-datablock.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Libmodbus Client Facade | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/contrib/libmodbus-client.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Modbus Payload Server Context Building Example | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/common/modbus-payload-server.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Remote Single Server Context | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/contrib/remote_server_context.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
================================================== | ||
Thread Safe Datastore Example | ||
================================================== | ||
|
||
.. literalinclude:: ../../../examples/contrib/thread_safe_datastore.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Pymodbus Server With Custom Datablock Side Effect | ||
-------------------------------------------------------------------------- | ||
This is an example of performing custom logic after a value has been | ||
written to the datastore. | ||
''' | ||
#---------------------------------------------------------------------------# | ||
# import the modbus libraries we need | ||
#---------------------------------------------------------------------------# | ||
from pymodbus.server.async import StartTcpServer | ||
from pymodbus.device import ModbusDeviceIdentification | ||
from pymodbus.datastore import ModbusSparseDataBlock | ||
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext | ||
from pymodbus.transaction import ModbusRtuFramer, ModbusAsciiFramer | ||
|
||
#---------------------------------------------------------------------------# | ||
# configure the service logging | ||
#---------------------------------------------------------------------------# | ||
|
||
import logging | ||
logging.basicConfig() | ||
log = logging.getLogger() | ||
log.setLevel(logging.DEBUG) | ||
|
||
#---------------------------------------------------------------------------# | ||
# create your custom data block here | ||
#---------------------------------------------------------------------------# | ||
|
||
class CustomDataBlock(ModbusSparseDataBlock): | ||
''' A datablock that stores the new value in memory | ||
and performs a custom action after it has been stored. | ||
''' | ||
|
||
def setValues(self, address, value): | ||
''' Sets the requested values of the datastore | ||
:param address: The starting address | ||
:param values: The new values to be set | ||
''' | ||
super(ModbusSparseDataBlock, self).setValues(address, value) | ||
|
||
# whatever you want to do with the written value is done here, | ||
# however make sure not to do too much work here or it will | ||
# block the server, espectially if the server is being written | ||
# to very quickly | ||
print "wrote {} to {}".format(value, address) | ||
|
||
|
||
#---------------------------------------------------------------------------# | ||
# initialize your data store | ||
#---------------------------------------------------------------------------# | ||
|
||
block = CustomDataBlock() | ||
store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block) | ||
context = ModbusServerContext(slaves=store, single=True) | ||
|
||
#---------------------------------------------------------------------------# | ||
# initialize the server information | ||
#---------------------------------------------------------------------------# | ||
|
||
identity = ModbusDeviceIdentification() | ||
identity.VendorName = 'pymodbus' | ||
identity.ProductCode = 'PM' | ||
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/' | ||
identity.ProductName = 'pymodbus Server' | ||
identity.ModelName = 'pymodbus Server' | ||
identity.MajorMinorRevision = '1.0' | ||
|
||
#---------------------------------------------------------------------------# | ||
# run the server you want | ||
#---------------------------------------------------------------------------# | ||
|
||
p = Process(target=device_writer, args=(queue,)) | ||
p.start() | ||
StartTcpServer(context, identity=identity, address=("localhost", 5020)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
''' | ||
Pymodbus Server Payload Example | ||
-------------------------------------------------------------------------- | ||
If you want to initialize a server context with a complicated memory | ||
layout, you can actually use the payload builder. | ||
''' | ||
#---------------------------------------------------------------------------# | ||
# import the various server implementations | ||
#---------------------------------------------------------------------------# | ||
from pymodbus.server.sync import StartTcpServer | ||
|
||
from pymodbus.device import ModbusDeviceIdentification | ||
from pymodbus.datastore import ModbusSequentialDataBlock | ||
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext | ||
|
||
#---------------------------------------------------------------------------# | ||
# import the payload builder | ||
#---------------------------------------------------------------------------# | ||
|
||
from pymodbus.constants import Endian | ||
from pymodbus.payload import BinaryPayloadDecoder | ||
from pymodbus.payload import BinaryPayloadBuilder | ||
|
||
#---------------------------------------------------------------------------# | ||
# configure the service logging | ||
#---------------------------------------------------------------------------# | ||
import logging | ||
logging.basicConfig() | ||
log = logging.getLogger() | ||
log.setLevel(logging.DEBUG) | ||
|
||
#---------------------------------------------------------------------------# | ||
# build your payload | ||
#---------------------------------------------------------------------------# | ||
builder = BinaryPayloadBuilder(endian=Endian.Little) | ||
builder.add_string('abcdefgh') | ||
builder.add_32bit_float(22.34) | ||
builder.add_16bit_uint(0x1234) | ||
builder.add_8bit_int(0x12) | ||
builder.add_bits([0,1,0,1,1,0,1,0]) | ||
|
||
#---------------------------------------------------------------------------# | ||
# use that payload in the data store | ||
#---------------------------------------------------------------------------# | ||
# Here we use the same reference block for each underlying store. | ||
#---------------------------------------------------------------------------# | ||
|
||
block = ModbusSequentialDataBlock(1, builder.to_registers()) | ||
store = ModbusSlaveContext(di = block, co = block, hr = block, ir = block) | ||
context = ModbusServerContext(slaves=store, single=True) | ||
|
||
#---------------------------------------------------------------------------# | ||
# initialize the server information | ||
#---------------------------------------------------------------------------# | ||
# If you don't set this or any fields, they are defaulted to empty strings. | ||
#---------------------------------------------------------------------------# | ||
identity = ModbusDeviceIdentification() | ||
identity.VendorName = 'Pymodbus' | ||
identity.ProductCode = 'PM' | ||
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/' | ||
identity.ProductName = 'Pymodbus Server' | ||
identity.ModelName = 'Pymodbus Server' | ||
identity.MajorMinorRevision = '1.0' | ||
|
||
#---------------------------------------------------------------------------# | ||
# run the server you want | ||
#---------------------------------------------------------------------------# | ||
StartTcpServer(context, identity=identity, address=("localhost", 5020)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.