AdvancedClimateSystems / Umodbus

Licence: mpl-2.0
Python implementation of the Modbus protocol.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Umodbus

Docker Mailman
Dockerfiles for the mailman suite.
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Ookii Dialogs Winforms
Common dialog classes for Windows Forms applications
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Gadfly.jl
Crafty statistical graphics for Julia.
Stars: ✭ 1,724 (+1236.43%)
Mutual labels:  hacktoberfest
Ember Data Url Templates
an ember-addon to allow building urls with url templates instead of defining buildURL
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Skip Silence
🔇 Chrome extension to skip silent parts in videos and audio files on any webpage
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Linearprogressbar
Material Linear Progress Bar for your iOS apps
Stars: ✭ 131 (+1.55%)
Mutual labels:  hacktoberfest
Typescript Vs Flowtype
Differences between Flowtype and TypeScript -- syntax and usability
Stars: ✭ 1,671 (+1195.35%)
Mutual labels:  hacktoberfest
Health
Laravel Health Panel
Stars: ✭ 1,774 (+1275.19%)
Mutual labels:  hacktoberfest
Cicerone
🏛️ Give tours of your Shiny apps
Stars: ✭ 131 (+1.55%)
Mutual labels:  hacktoberfest
Zebrunner
Zebrunner is a Test Automation Management Tool
Stars: ✭ 131 (+1.55%)
Mutual labels:  hacktoberfest
Easy Build
Collection of Dockerfiles for building embedded software distributions
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Amplitude Android
Native Android SDK for Amplitude
Stars: ✭ 129 (+0%)
Mutual labels:  hacktoberfest
Docker Influxdb Grafana
A Docker container which runs InfluxDB and Grafana ready for persisting data
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Adonis Cli
adonis cli module to generate new application
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Homebrew Openjdk
AdoptOpenJDK HomeBrew Tap
Stars: ✭ 1,798 (+1293.8%)
Mutual labels:  hacktoberfest
Mail
Mail app designed for elementary OS
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest
Fossurl
Your Own Url Shortner Without any fancy server side processing and support for custom url , which can even be hosted on GitHub Pages
Stars: ✭ 131 (+1.55%)
Mutual labels:  hacktoberfest
Shuffle
Shuffle every song in existence from YouTube
Stars: ✭ 131 (+1.55%)
Mutual labels:  hacktoberfest
Picsum Photos
Lorem Ipsum... but for photos.
Stars: ✭ 1,751 (+1257.36%)
Mutual labels:  hacktoberfest
Showmethexaml
A WPF component making it easy to show the corresponding XAML for WPF custom styles and controls
Stars: ✭ 130 (+0.78%)
Mutual labels:  hacktoberfest

.. image:: https://travis-ci.org/AdvancedClimateSystems/uModbus.svg :target: https://travis-ci.org/AdvancedClimateSystems/uModbus

.. image:: https://coveralls.io/repos/AdvancedClimateSystems/uModbus/badge.svg?service=github :target: https://coveralls.io/github/AdvancedClimateSystems/uModbus

.. image:: https://img.shields.io/pypi/v/uModbus.svg :target: https://pypi.python.org/pypi/uModbus

.. image:: https://img.shields.io/pypi/pyversions/uModbus.svg :target: https://pypi.python.org/pypi/uModbus

uModbus

uModbus or (μModbus) is a pure Python implementation of the Modbus protocol as described in the MODBUS Application Protocol Specification V1.1b3. uModbus implements both a Modbus client (both TCP and RTU) and a Modbus server (both TCP and RTU). The "u" or "μ" in the name comes from the the SI prefix "micro-". uModbus is very small and lightweight. The source can be found on GitHub. Documentation is available at Read the Docs_.

Quickstart

Creating a Modbus TCP server is easy:

.. Because GitHub doesn't support the include directive the source of scripts/examples/simple_tcp_server.py has been copied to this file.

.. code:: python

#!/usr/bin/env python
# scripts/examples/simple_tcp_server.py
import logging
from socketserver import TCPServer
from collections import defaultdict
from argparse import ArgumentParser

from umodbus import conf
from umodbus.server.tcp import RequestHandler, get_server
from umodbus.utils import log_to_stream

# Add stream handler to logger 'uModbus'.
log_to_stream(level=logging.DEBUG)

# A very simple data store which maps addresses against their values.
data_store = defaultdict(int)

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

# Parse command line arguments
parser = ArgumentParser()
parser.add_argument("-b", "--bind", default="localhost:502")

args = parser.parse_args()
if ":" not in args.bind:
    args.bind += ":502"
host, port = args.bind.rsplit(":", 1)
port = int(port)

TCPServer.allow_reuse_address = True
try:
    app = get_server(TCPServer, (host, port), RequestHandler)
except PermissionError:
    print("You don't have permission to bind on {}".format(args.bind))
    print("Hint: try with a different port (ex: --bind localhost:50200)")
    exit(1)

@app.route(slave_ids=[1], function_codes=[1, 2], addresses=list(range(0, 10)))
def read_data_store(slave_id, function_code, address):
    """" Return value of address. """
    return data_store[address]


@app.route(slave_ids=[1], function_codes=[5, 15], addresses=list(range(0, 10)))
def write_data_store(slave_id, function_code, address, value):
    """" Set value for address. """
    data_store[address] = value

if __name__ == '__main__':
    try:
        app.serve_forever()
    finally:
        app.shutdown()
        app.server_close()

Doing a Modbus request requires even less code:

.. Because GitHub doesn't support the include directive the source of scripts/examples/simple_data_store.py has been copied to this file.

.. code:: python

#!/usr/bin/env python
# scripts/examples/simple_tcp_client.py
from argparse import ArgumentParser
from socket import create_connection

from umodbus import conf
from umodbus.client import tcp

# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True

# Parse command line arguments
parser = ArgumentParser()
parser.add_argument("-a", "--address", default="localhost:502")

args = parser.parse_args()
if ":" not in args.address:
    args.address += ":502"
host, port = args.address.rsplit(":", 1)
port = int(port)

# Returns a message or Application Data Unit (ADU) specific for doing
# Modbus TCP/IP.
message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1])

with create_connection((host, port)) as sock:
    # Response depends on Modbus function code. This particular returns the
    # amount of coils written, in this case it is.
    response = tcp.send_message(message, sock)

Features

The following functions have been implemented for Modbus TCP and Modbus RTU:

  • 01: Read Coils
  • 02: Read Discrete Inputs
  • 03: Read Holding Registers
  • 04: Read Input Registers
  • 05: Write Single Coil
  • 06: Write Single Register
  • 15: Write Multiple Coils
  • 16: Write Multiple Registers

Other featues:

  • Support for signed and unsigned register values.

License

uModbus software is licensed under Mozilla Public License. © 2018 Advanced Climate Systems.

.. External References: .. _Advanced Climate Systems: http://www.advancedclimate.nl/ .. _GitHub: https://github.com/AdvancedClimateSystems/uModbus/ .. _MODBUS Application Protocol Specification V1.1b3: http://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf .. _Mozilla Public License: https://github.com/AdvancedClimateSystems/uModbus/blob/develop/LICENSE .. _Read the Docs: http://umodbus.readthedocs.org/en/latest/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].