Skip to main content

A Python3 MODBUS TCP server for testing purposes

Project description

modbus-tcp-server

PyPI PyPI version PyPI Wheel

A thread-based MODBUS TCP server for testing purposes.

Installation

Just type

pip install modbus-tcp-server

And to run it

modbus-tcp-server 127.0.0.1 502

Port is optional, it will be assumed to be 502 by default.

Just run it without any arguments to see the command line.

If you want verbosity, you can drop -v or -vv after providing port number. Note that in this case giving port number is mandatory.

Limitations

It does only the commands related to reading and writing analog inputs, discrete inputs, holding registers and coils, so only commands 1-6 and 15-16 are supported.

Also, it spawns a thread per a client. This might be unacceptable to you, however it can also with with gevent.

Client connections will be closed after 60 seconds of inactivity.

Custom data provider

To implement a custom data provider, just extend BaseDataSource to provide data of your choosing and launch it that way:

from modbus_tcp_server.network import ModbusTCPServer
from modbus_tcp_server.data_source import BaseDataSource

class CustomDB(BaseDataSource):
    ...

c_db = CustomDB()

at = ModbusTCPServer('0.0.0.0', 502, c_db).start()

Note that since everything is handled in a single thread, if your reads or writes take too long this will hang on them. File a Issue if you've got a problem with that.

Change log

v0.5

  • TBA

v0.4

  • added automatic connection termination after 60 seconds of inactivity
  • better error detection on connections
  • bugfix: fixed CustomMODBUSError

v0.3

  • added CustomMODBUSError
  • renamed AcceptThread to ModbusTCPServer

v0.2

  • added support for commands 15 and 16
  • added exceptions GatewayPathUnavailable and GatewayTargetDeviceFailedToRespond

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modbus_tcp_server-0.5-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file modbus_tcp_server-0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: modbus_tcp_server-0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for modbus_tcp_server-0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72f61dca5c9224583a1a681e361d31a8dfbab35b5e0759e7dc4f1790c5c30006
MD5 fcdcd53669ccbd21431a884f5a337d73
BLAKE2b-256 51a7ec5a787e963762d6dde277e8055bbafa64c683e35c53724f173c4b599920

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page