Code Monkey home page Code Monkey logo

pymodbustcp's Introduction

pyModbusTCP badge_tests badge_docs

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.

Tests

The module is currently test on Python 3.5, 3.6, 3.7, 3.8, 3.9 and 3.10.

Setup

You can install this package from:

PyPI, the easy way:

# install the last available release
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/[email protected]

GitHub:

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

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.

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

Documentation

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

Know issue for older releases (v0.1.x) that support python 2

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:

sudo pip install win_inet_pton

import win_inet_pton at beginning of your code:

import win_inet_pton
from pyModbusTCP.client import ModbusClient

pymodbustcp's People

Contributors

sourceperl avatar sbonaime avatar andreascian avatar mfkenney avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.