Skip to main content

A simple Modbus/TCP library for Python

Project description

A simple Modbus/TCP client library for Python. pyModbusTCP is pure Python code without any extension or external module dependency.

Since version 0.1.0, a server is also available.

Tests

The module is currently test on Python 3.8, 3.9, 3.10, 3.11 and 3.12.

For Linux, Mac OS and Windows.

Documentation

Documentation of the last release is available online at https://pymodbustcp.readthedocs.io/.

Setup

You can install this package from:

PyPI, the easy way:

# install the last available release (stable)
sudo pip install pyModbusTCP
# install a specific version (here release v0.1.10)
sudo pip install pyModbusTCP==v0.1.10

From GitHub:

# install a specific version (here release v0.1.10) directly from github servers
sudo pip install git+https://github.com/sourceperl/pyModbusTCP.git@v0.1.10

Note on the use of versions:

Over time, some things can change. So, it’s a good practice that you always use a specific version of a package for your project, instead of just relying on the default behavior. Without precision, the installation tools will always install the latest version available for a package, this may have some drawbacks. For example, in pyModbusTCP, the TCP automatic open mode will be active by default from version 0.2.0. It is not the case with previous versions and it just doesn’t exist before the 0.0.12. This can lead to some strange behaviour of your application if you are not aware of the change. Look at CHANGES for details on versions available.

Usage example

See examples/ for full scripts.

include (for all samples)

from pyModbusTCP.client import ModbusClient

module init (TCP always open)

# TCP auto connect on first modbus request
c = ModbusClient(host="localhost", port=502, unit_id=1, auto_open=True)

module init (TCP open/close for each request)

# TCP auto connect on modbus request, close after it
c = ModbusClient(host="127.0.0.1", auto_open=True, auto_close=True)

Read 2x 16 bits registers at modbus address 0 :

regs = c.read_holding_registers(0, 2)

if regs:
    print(regs)
else:
    print("read error")

Write value 44 and 55 to registers at modbus address 10 :

if c.write_multiple_registers(10, [44,55]):
    print("write ok")
else:
    print("write error")

Project details


Download files

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

Source Distribution

pyModbusTCP-0.3.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

pyModbusTCP-0.3.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file pyModbusTCP-0.3.0.tar.gz.

File metadata

  • Download URL: pyModbusTCP-0.3.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for pyModbusTCP-0.3.0.tar.gz
Algorithm Hash digest
SHA256 893a4d88f6a63af21bd35b2b22061355e74005ea27fefc104e8f9bdb4ce81a04
MD5 95e62d676057aa588185d20d197a8a26
BLAKE2b-256 9bc6d3f3842696607a09f6cf3c2a668c0e05731caf3013b118ecd75deddc548c

See more details on using hashes here.

File details

Details for the file pyModbusTCP-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyModbusTCP-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for pyModbusTCP-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b0086fa7ed4bd1bf6956d56a0979937008c48091f052310ad8826647fe30180
MD5 a2b8463d8cfc1deca4428bf475dc80b7
BLAKE2b-256 6c0f343d4902b01989131aa7ef8a9aa253731c16814c789e49f5ff9b4bb66334

See more details on using hashes here.

Supported by

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