modbus_server
A ModbusTCP server implementation in pure Python.
Installation
pip install modbus_server
Minimal Example
import modbus_server
s = modbus_server.Server(port=5020)
s.start()
s.set_coil(1,True)
Functions
Server Object
s = modbus_server.Server(host='localhost', port=502, datastore=None, loglevel="INFO", autostart=False)
Initializes a Server instance. If the datastore is not explicitly given, an empty DictDatastore is instantiated and used.
s.start()
s.stop()
Start and stop the server thread which accepts requests. The thread does not block the main thread, but it prevents the program from exiting until s.stop() is called.
Set Coils and Discrete Input
set_coil(address, value)
set_discrete_input(address, value)
Set the coil or discrete_input at address to value. This function can only process one value.
set_coils(start_address, values)
set_discrete_inputs(start_address, values)
Set Input and Holding Registers
set_input_register(address, value, encoding)
set_holding_register(address, value, encoding)
Set the input or holding register at address to value using encoding. This function can only process one value.
set_input_registers(start_address, values, encoding)
set_holding_registers(start_address, values, encoding)
Datastore Object
The modbus_server pulls the data it serves from a datastore. The simplest datastore is just a dictionary that is filled from the Server object using the various set_-functions described below. In that case, the data needs to be ingested directly in the program that starts the server as in the minimal example above.
datastore = modbus_server.DictDatastore()
An alternative is using redis to hold the data. That way, other processes in the system can change the data in the datastore and the modbus_server always has up to data from e.g. a measurement process. In order to link keys in redis with modbus object references (coil, discrete input, input register, and holding register) and addresses, the RedisDatastore object uses a modbus_address_map, a dictionary that follows a special convention.
datastore = modbus_server.RedisDatastore(modbus_address_map={}, redis_host="localhost", redis_port=6379, redis_db=0)
Development:
For testing, install a symlink to the package in the python environment using flit:
flit install . -s
Metadata
Release files for modbus_server 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modbus_server-0.2.3.tar.gz | 11.0 kB | Without provenance | Details for modbus_server-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modbus_server-0.2.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for modbus_server-0.2.3-py2.py3-none-any.whl |
Total release size: 18.9 kB
Release files / modbus_server-0.2.3.tar.gz
| Download URL | modbus_server-0.2.3.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8b62005ba61eaab7ab185c8422958d439797ff501aa7f67e4220072b51305a9
|
|
BLAKE2b-256 checksum How to use checksums |
122fd9d05e7945d4df5b15f5334652c555c4ce385e11d050de09dde4c3bde86d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.27.1
|
Release files / modbus_server-0.2.3-py2.py3-none-any.whl
| Download URL | modbus_server-0.2.3-py2.py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
7407d4e6d3d6cac2acfd3a5298d2078d22be1efb1122fd22730d6d3299e932b6
|
|
BLAKE2b-256 checksum How to use checksums |
a0c520976b65222ba7410619f7fea4fae9afa30078a8c6405d529075099a3fa7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.27.1
|
Security for modbus_server 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.