Metadata-Version: 2.1
Name: pyModbusTCP
Version: 0.1.10
Summary: A simple Modbus/TCP library for Python
Home-page: https://github.com/sourceperl/pyModbusTCP
Author: Loic Lefebvre
Author-email: loic.celine@free.fr
License: MIT
Platform: any
License-File: LICENSE

pyModbusTCP
===========

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.7, 3.4, 3.5, 3.6, 3.7, 3.8 and 3.9.

Status:

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

.. image:: https://readthedocs.org/projects/pymodbustcp/badge/?version=latest
  :target: http://pymodbustcp.readthedocs.io/en/latest/?badge=latest

Setup
-----

You can install this package from:

PyPI, the easy way:

.. code-block:: bash

    sudo pip install pyModbusTCP

GitHub:

.. code-block:: bash

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

GitHub with pip:

.. code-block:: bash

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

Usage example
-------------

See examples/ for full scripts.

include (for all samples)
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    from pyModbusTCP.client import ModbusClient

module init (TCP always open)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    # 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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    # 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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

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

Read 2x 16 bits registers at modbus address 0 :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    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 :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

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

Documentation
-------------

Documentation available online at http://pymodbustcp.readthedocs.io/.

Know issue
----------

On windows OS with older Python version (<3), win_inet_pton module is require. This avoid exception "AttributeError:
'module' object has no attribute 'inet_pton'".

install win_inet_pton:

.. code-block:: bash

    sudo pip install win_inet_pton

import win_inet_pton at beginning of your code:

.. code-block:: python

    import win_inet_pton
    from pyModbusTCP.client import ModbusClient


