1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
================================
PyModbus - A Python Modbus Stack
================================
`Travis <https://travis-ci.org/riptideio/pymodbus>`_
`Gitter <https://gitter.im/pymodbus_dev/Lobby>`_
`Documentation Status <http://pymodbus.readthedocs.io/en/latest/?badge=latest>`_
`Downloads <http://pepy.tech/project/pymodbus>`_
.. important::
**Note This is a Major release and might affect your existing Async client implementation. Refer examples on how to use the latest async clients.**
------------------------------------------------------------
Summary
------------------------------------------------------------
Pymodbus is a full Modbus protocol implementation using twisted for its
asynchronous communications core. It can also be used without any third
party dependencies (aside from pyserial) if a more lightweight project is
needed. Furthermore, it should work fine under any python version > 2.7
(including python 3+)
------------------------------------------------------------
Features
------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~
Client Features
~~~~~~~~~~~~~~~~~~~~
* Full read/write protocol on discrete and register
* Most of the extended protocol (diagnostic/file/pipe/setting/information)
* TCP, UDP, Serial ASCII, Serial RTU, and Serial Binary
* asynchronous(powered by twisted/tornado/asyncio) and synchronous versions
* Payload builder/decoder utilities
* Pymodbus REPL for quick tests
~~~~~~~~~~~~~~~~~~~~
Server Features
~~~~~~~~~~~~~~~~~~~~
* Can function as a fully implemented modbus server
* TCP, UDP, Serial ASCII, Serial RTU, and Serial Binary
* asynchronous(powered by twisted) and synchronous versions
* Full server control context (device information, counters, etc)
* A number of backing contexts (database, redis, sqlite, a slave device)
------------------------------------------------------------
Use Cases
------------------------------------------------------------
Although most system administrators will find little need for a Modbus
server on any modern hardware, they may find the need to query devices on
their network for status (PDU, PDR, UPS, etc). Since the library is written
in python, it allows for easy scripting and/or integration into their existing
solutions.
Continuing, most monitoring software needs to be stress tested against
hundreds or even thousands of devices (why this was originally written), but
getting access to that many is unwieldy at best. The pymodbus server will allow
a user to test as many devices as their base operating system will allow (*allow*
in this case means how many Virtual IP addresses are allowed).
For more information please browse the project documentation:
http://riptideio.github.io/pymodbus/
or
http://readthedocs.org/docs/pymodbus/en/latest/index.html
------------------------------------------------------------
Example Code
------------------------------------------------------------
For those of you that just want to get started fast, here you go::
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('127.0.0.1')
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()
For more advanced examples, check out the examples included in the
respository. If you have created any utilities that meet a specific
need, feel free to submit them so others can benefit.
Also, if you have questions, please ask them on the mailing list
so that others can benefit from the results and so that I can
trace them. I get a lot of email and sometimes these requests
get lost in the noise: http://groups.google.com/group/pymodbus or
at gitter: https://gitter.im/pymodbus_dev/Lobby
------------------------------------------------------------
Pymodbus REPL (Read Evaluate Procee Loop)
------------------------------------------------------------
Starting with Pymodbus 2.x, pymodbus library comes with handy
Pymodbus REPL to quickly run the modbus clients in tcp/rtu modes.
Pymodbus REPL comes with many handy features such as payload decoder
to directly retrieve the values in desired format and supports all
the diagnostic function codes directly .
For more info on REPL refer `Pymodbus REPL <https://github.com/riptideio/pymodbus/tree/master/pymodbus/repl>`_
`asciinema <https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o>`_
------------------------------------------------------------
Installing
------------------------------------------------------------
You can install using pip or easy install by issuing the following
commands in a terminal window (make sure you have correct
permissions or a virtualenv currently running)::
easy_install -U pymodbus
pip install -U pymodbus
To Install pymodbus with twisted support run::
pip install -U pymodbus[twisted]
To Install pymodbus with tornado support run::
pip install -U pymodbus[tornado]
To Install pymodbus REPL::
pip install -U pymodbus[repl]
Otherwise you can pull the trunk source and install from there::
git clone git://github.com/bashwork/pymodbus.git
cd pymodbus
python setup.py install
Either method will install all the required dependencies
(at their appropriate versions) for your current python distribution.
If you would like to install pymodbus without the twisted dependency,
simply edit the setup.py file before running easy_install and comment
out all mentions of twisted. It should be noted that without twisted,
one will only be able to run the synchronized version as the
asynchronous versions uses twisted for its event loop.
------------------------------------------------------------
Current Work In Progress
------------------------------------------------------------
Since I don't have access to any live modbus devices anymore
it is a bit hard to test on live hardware. However, if you would
like your device tested, I accept devices via mail or by IP address.
That said, the current work mainly involves polishing the library as
I get time doing such tasks as:
* Make PEP-8 compatible and flake8 ready
* Fixing bugs/feature requests
* Architecture documentation
* Functional testing against any reference I can find
* The remaining edges of the protocol (that I think no one uses)
* Asynchronous clients with support to tornado , asyncio
------------------------------------------------------------
Development Instructions
------------------------------------------------------------
The current code base is compatible with both py2 and py3.
Use make to perform a range of activities
::
$ make
Makefile for pymodbus
Usage:
make install install the package in a virtual environment
make reset recreate the virtual environment
make check check coding style (PEP-8, PEP-257)
make test run the test suite, report coverage
make tox run the tests on all Python versions
make clean cleanup all temporary files
------------------------------------------------------------
Contributing
------------------------------------------------------------
Just fork the repo and raise your PR against `dev` branch.
------------------------------------------------------------
License Information
------------------------------------------------------------
Pymodbus is built on top of code developed from/by:
* Copyright (c) 2001-2005 S.W.A.C. GmbH, Germany.
* Copyright (c) 2001-2005 S.W.A.C. Bohemia s.r.o., Czech Republic.
* Hynek Petrak, https://github.com/HynekPetrak
* Twisted Matrix
Released under the BSD License
|