Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - jcameron-sso/pymodbus: Fork of a full modbus protocol written in python · GitHub
Skip to content

Repository files navigation

PyModbus - A Python Modbus Stack

https://github.com/pymodbus-dev/pymodbus/actions/workflows/ci.yml/badge.svg?branch=devDocumentation StatusDownloads

Pymodbus is a full Modbus protocol implementation offering client/server with synchronous/asynchronous API a well as simulators.

Current release is 3.6.8.

Bleeding edge (not released) is dev.

All changes are described in release notes and all API changes are documented

A big thanks to all the volunteers that helps make pymodbus a great project.

Source code on github

Pymodbus in a nutshell

Pymodbus consist of 5 parts:

  • client, connect to your favorite device(s)
  • server, simulate your favorite device(s)
  • repl, a commandline text based client/server simulator
  • simulator, an html based server simulator
  • examples, showing both simple and advances usage

Common features

  • Full modbus standard protocol implementation
  • Support for custom function codes
  • support serial (rs-485), tcp, tls and udp communication
  • support all standard frames: socket, rtu, rtu-over-tcp, tcp and ascii
  • does not have third party dependencies, apart from pyserial (optional)
  • very lightweight project
  • requires Python >= 3.9
  • thorough test suite, that test all corners of the library
  • automatically tested on Windows, Linux and MacOS combined with python 3.9 - 3.12
  • strongly typed API (py.typed present)

The modbus protocol specification: Modbus_Application_Protocol_V1_1b3.pdf can be found on modbus org

Client Features

  • asynchronous API and synchronous API for applications
  • very simple setup and call sequence (just 6 lines of code)
  • utilities to convert int/float to/from multiple registers
  • payload builder/decoder to help with complex data

Client documentation

Server Features

  • asynchronous implementation for high performance
  • synchronous API classes for convenience
  • simulate real life devices
  • full server control context (device information, counters, etc)
  • different backend datastores to manage register values
  • callback to intercept requests/responses
  • work on RS485 in parallel with other devices

Server documentation

REPL Features

  • server/client commandline emulator
  • easy test of real device (client)
  • easy test of client app (server)
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

REPL documentation

Simulator Features

  • server simulator with WEB interface
  • configure the structure of a real device
  • monitor traffic online
  • allow distributed team members to work on a virtual device using internet
  • simulation of broken requests/responses
  • simulation of error responses (hard to provoke in real devices)

Simulator documentation

Use Cases

The client is the most typically used. It is embedded into applications, where it abstract the modbus protocol from the application by providing an easy to use API. The client is integrated into some well known projects like home-assistant.

Although most system administrators will find little need for a Modbus server, the server is handy to verify the functionality of an application.

The simulator and/or server is often used to simulate real life devices testing applications. The server is excellent to perform high volume testing (e.g. houndreds of devices connected to the application). The advantage of the server is that it runs not only a "normal" computers but also on small ones like Raspberry PI.

Since the library is written in python, it allows for easy scripting and/or integration into their existing solutions.

For more information please browse the project documentation:

https://readthedocs.org/docs/pymodbus/en/latest/index.html

Install

The library is available on pypi.org and github.com to install with

  • pip for those who just want to use the library
  • git clone for those who wants to help or just are curious

Be aware that there are a number of project, who have forked pymodbus and

  • seems just to provide a version frozen in time
  • extended pymodbus with extra functionality

The latter is not because we rejected the extra functionality (we welcome all changes), but because the codeowners made that decision.

In both cases, please understand, we cannot offer support to users of these projects as we do not known what have been changed nor what status the forked code have.

A growing number of Linux distributions include pymodbus in their standard installation.

You need to have python3 installed, preferable 3.11.

Install with pip

You can install using pip by issuing the following commands in a terminal window:

pip install pymodbus

If you want to use the serial interface:

pip install pymodbus[serial]

This will install pymodbus with the pyserial dependency.

Pymodbus offers a number of extra options:

  • repl, needed by pymodbus.repl
  • serial, needed for serial communication
  • simulator, needed by pymodbus.simulator
  • documentation, needed to generate documentation
  • development, needed for development
  • all, installs all of the above

which can be installed as:

pip install pymodbus[<option>,...]

It is possible to install old releases if needed:

pip install pymodbus==3.5.4

Install with github

On github, fork https://github.com/pymodbus-dev/pymodbus.git

Clone the source, and make a virtual environment:

git clone git://github.com/<your account>/pymodbus.git
cd pymodbus
python3 -m venv .venv

Activate the virtual environment, this command needs repeated in every new terminal:

source .venv/bin/activate

To get a specific release:

git checkout v3.5.2

or the bleeding edge:

git checkout dev

Some distributions have an old pip, which needs to be upgraded:

pip install --upgrade pip

Install required development tools:

pip install ".[development]"

Install all (allows creation of documentation etc):

pip install ".[all]"

Install git hooks, that helps control the commit and avoid errors when submitting a Pull Request:

cp githooks/* .git/hooks

This installs dependencies in your virtual environment with pointers directly to the pymodbus directory, so any change you make is immediately available as if installed.

The repository contains a number of important branches and tags.
  • dev is where all development happens, this branch is not always stable.
  • master is where are releases are kept.
  • vX.Y.Z (e.g. v2.5.3) is a specific release

Example Code

For those of you that just want to get started fast, here you go:

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan')
client.connect()
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()

We provide a couple of simple ready to go clients:

For more advanced examples, check out 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.

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.

Example documentation

Contributing

Just fork the repo and raise your Pull Request 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.

If your company would like your device tested or have a cloud based device simulation, feel free to contact us. We are happy to help your company solve your modbus challenges.

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

There are 2 bigger projects ongoing:

  • rewriting the internal part of all clients (both sync and async)
  • Add features to and simulator, and enhance the web design

Development instructions

The current code base is compatible with python >= 3.9.

Here are some of the common commands to perform a range of activities:

source .venv/bin/activate <-- Activate the virtual environment
./check_ci.sh <-- run the same checks as CI runs on a pull request.

Make a pull request:

git checkout dev <-- activate development branch
git pull <-- update branch with newest changes
git checkout -b feature <-- make new branch for pull request
... make source changes
git commit <-- commit change to git
git push <-- push to your account on github
on github open a pull request, check that CI turns green and then wait for review comments.

Test your changes:

cd test
pytest

you can also do extended testing:

pytest --cov <-- Coverage html report in build/html
pytest --profile <-- Call profile report in prof

Internals

There are no documentation of the architecture (help is welcome), but most classes and methods are documented:

Pymodbus internals

Generate documentation

Remark Assumes that you have installed documentation tools:;

pip install ".[documentation]"

to build do:

cd doc
./build_html

The documentation is available in <root>/build/html

Remark: this generates a new zip/tgz file of examples which are uploaded.

License Information

Released under the BSD License

About

Fork of a full modbus protocol written in python

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages