- Saved searches
- Use saved searches to filter your results more quickly
- License
- pymodbus-dev/pymodbus
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.rst
- About
- Saved searches
- Use saved searches to filter your results more quickly
- License
- sourceperl/pyModbusTCP
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.rst
- About
- pyModbusTCP 0.2.0
- Tests
- Documentation
- Setup
- Usage example
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A full modbus protocol written in python
License
pymodbus-dev/pymodbus
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.rst
PyModbus — A Python Modbus Stack
We are constantly working the modernize pymodbus and add new features, and we look for people who want to help a bit. There are challenges small and large not only programming but also documentation and testing.
Version 2.5.3 is the last 2.x release (python >= 2.7, no longer supported).
Version 3.4.0 is the current release (Tested with Python >= 3.8).
All API changes after 3.0.0 are documented in API_changes.rst
Pymodbus is a full Modbus protocol implementation using a synchronous or asynchronous (using asyncio) core.
The modbus protocol documentation can be found here
Supported modbus communication modes: tcp, rtu-over-tcp, udp, serial, tls
Pymodbus can be used without any third party dependencies (aside from pyserial) and is a very lightweight project.
Pymodbus also provides a lot of ready to use examples as well as a server/client simulator which can be controlled via a REST API and can be easily integrated into test suites.
The tests are run against Python 3.8, 3.9, 3.10, 3.11 on Windows, Linux and MacOS.
- Full read/write protocol on discrete and register
- Most of the extended protocol (diagnostic/file/pipe/setting/information)
- TCP, RTU-OVER-TCP, UDP, TLS, Serial ASCII, Serial RTU, and Serial Binary
- asynchronous(powered by asyncio) and synchronous versions
- Payload builder/decoder utilities
- Pymodbus REPL for quick tests
- Customizable framer to allow for custom implementations
- Can function as a fully implemented modbus server
- TCP, RTU-OVER-TCP, UDP, TLS, Serial ASCII, Serial RTU, and Serial Binary
- asynchronous and synchronous versions
- Full server control context (device information, counters, etc)
- A number of backend contexts as datastore
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:
For those of you that just want to get started fast, here you go:
from pymodbus.client import ModbusTcpClient client = ModbusTcpClient('127.0.0.1') client.connect() 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 repository. If you have created any utilities that meet a specific need, feel free to submit them so others can benefit.
Examples Directory structure
examples -> Essential examples guaranteed to work (tested with our CI) ├── v2.5.3 -> Examples not updated to version 3.0.0. ├── contrib -> Examples contributed by contributors.
Also, if you have a question, please create a post in discussions q&a topic, so that others can benefit from the results.
If you think, that something in the code is broken/not running well, please open an issue, read the Template-text first and then post your issue with your setup information.
Pymodbus REPL (Read Evaluate Print Loop)
Warning The Pymodbus REPL documentation is not updated.
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 Client refer Pymodbus REPL Client
Pymodbus also comes with a REPL server to quickly run an asynchronous server with additional capabilities out of the box like simulating errors, delay, mangled messages etc.
For more info on REPL Server refer Pymodbus REPL Server
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):
This will install a base version of pymodbus.
To install pymodbus with options run:
- repl, installs pymodbus REPL.
- serial, installs serial drivers.
- documentation, installs tools to generate documentation.
- development, installs development tools needed to enable test/check of pymodbus changes.
Or to install a specific release:
Otherwise you can pull the trunk source and install from there:
git clone git://github.com/pymodbus-dev/pymodbus.git cd pymodbus pip install -r requirements.txt
Before cloning the repo, you need to install python3 (preferable 3.10) and make a virtual environment:
python3 -m venv /path/to/new/virtual/environment
To activeate the virtual environment please do:
To get latest release (for now v3.0.0 with Python 3.8 support):
To get a specific version:
pip install -r requirements.txt
pip install -e .
pre-commit —install
This installs pymodbus in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed. It will also install pre-commit git hooks.
Either method will install all the required dependencies (at their appropriate versions) for your current python distribution.
- dev is where all development happens, this branch is not always stable.
- master is where are releases are kept.
- All releases are tagged with vX.Y.Z (e.g. v2.5.3)
- All prereleases are tagged with vX.Y.ZrcQ (e.g. v3.0.0.0rc1)
If a maintenance release of an old version is needed (e.g. v2.5.4), the release tag is used to create a branch with the same name, and maintenance development is merged here.
The maintenance team is very small with limited capacity and few modbus devices.
However, if you would like your device tested, we accept devices via mail or by IP address.
That said, the current work mainly involves polishing the library and solving issues:
- Fixing bugs/feature requests
- Architecture documentation
- Functional testing against any reference we can find
- The remaining edges of the protocol (that we think no one uses)
The current code base is compatible python >= 3.8. Here are some of the common commands to perform a range of activities
pip install -r requirements.txt install all requirements
pip install -e . source directory is «release», useful for testing
./check_ci run the same checks as CI runs on a pull request.
OBS: tox is no longer supported.
Just fork the repo and raise your PR against dev branch.
We always have more work than time, so feel free to open a discussion / issue on a theme you want to solve.
- 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
About
A full modbus protocol written in python
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple Modbus/TCP library for Python
License
sourceperl/pyModbusTCP
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.rst
A simple Modbus/TCP client library for Python. pyModbusTCP is pure Python code without any extension or external module dependency.
Since version 0.1.0, a server is also available for test purpose only (don’t use in project).
The module is currently test on Python 3.7, 3.8, 3.9, 3.10 and 3.11.
For Linux, Mac OS and Windows.
Documentation of the last release is available online at https://pymodbustcp.readthedocs.io/.
You can install this package from:
# install the last available release (stable) sudo pip install pyModbusTCP
# install a specific version (here release v0.1.10) sudo pip install pyModbusTCP==v0.1.10
# install a specific version (here release v0.1.10) directly from github servers sudo pip install git+https://github.com/sourceperl/pyModbusTCP.git@v0.1.10
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. Look at CHANGES for details on versions available.
See examples/ for full scripts.
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")
About
A simple Modbus/TCP library for Python
pyModbusTCP 0.2.0
A simple Modbus/TCP client library for Python. pyModbusTCP is pure Python code without any extension or external module dependency.
Since version 0.1.0, a server is also available for test purpose only (don’t use in project).
Tests
The module is currently test on Python 3.5, 3.6, 3.7, 3.8, 3.9 and 3.10.
For Linux, Mac OS and Windows.
Documentation
Documentation of the last release is available online at https://pymodbustcp.readthedocs.io/.
Setup
You can install this package from:
sudo pip install pyModbusTCP
sudo pip install From GitHub:
sudo pip install git+https://github.com/sourceperl/pyModbusTCP.git@v0.1.10
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. Look at CHANGES for details on versions available.
Usage example
See examples/ for full scripts.