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.
The module is currently test on Python 2.6, 2.7, 3.2, 3.3, 3.4 and 3.5.
Status:
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
See examples/ for full scripts.
from pyModbusTCP.client import ModbusClient
# TCP auto connect on first modbus request c = ModbusClient(host="localhost", port=502, auto_open=True)
# TCP auto connect on modbus request, close after it c = ModbusClient(host="127.0.0.1", auto_open=True, auto_close=True)
c = ModbusClient() c.host("localhost") c.port(502) # managing TCP sessions with call to c.open()/c.close() c.open()
regs = c.read_holding_registers(0, 2) if regs: print(regs) else: print("read error")
if c.write_multiple_registers(10, [44,55]): print("write ok") else: print("write error")
Documentation available online at http://pymodbustcp.readthedocs.io/.