Skip to main content

A simple Modbus/TCP library for Python

Project description

A simple Modbus/TCP client library for Python.

Since version 0.1.0, a server is also available for test purpose only (don’t use in project).

pyModbusTCP is pure Python code without any extension or external module dependency.

Test

The module is currently test on Python 2.6, 2.7, 3.2, 3.3 and 3.4.

Status:

https://api.travis-ci.org/sourceperl/pyModbusTCP.svg?branch=master

Setup

You can install this package from:

PyPI, the easy way:

sudo pip install pyModbusTCP

GitHub:

git clone https://github.com/sourceperl/pyModbusTCP.git
cd pyModbusTCP
sudo python setup.py install

Install the current devel-release:

sudo pip install git+https://github.com/sourceperl/pyModbusTCP.git@devel

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, 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)

module init (with accessor functions)

c = ModbusClient()
c.host("localhost")
c.port(502)
# managing TCP sessions with call to c.open()/c.close()
c.open()

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")

Documentation

Documentation available online at http://pythonhosted.org/pyModbusTCP and on doc/html/index.html.

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.1.2.tar.gz (13.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pyModbusTCP-0.1.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyModbusTCP-0.1.2.tar.gz
Algorithm Hash digest
SHA256 422b6fc67e3bed641563e9e304aaa6ccd1d15e28cf34900996356e5ce958fa6e
MD5 b3e6a2ee20b62614f4f9a74837f21a4f
BLAKE2b-256 7786ce121e9ee69fac5c980b52e201ab8059c3d8d83a031f6c3e3961e53349e4

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