Skip to main content

Implementation of the Modbus protocol in pure Python.

Project description

https://travis-ci.org/AdvancedClimateSystems/uModbus.svg https://coveralls.io/repos/AdvancedClimateSystems/uModbus/badge.svg?service=github https://img.shields.io/pypi/v/uModbus.svg

uModbus

uModbus or (μModbus) is a pure Python implementation of the Modbus protcol as described in the MODBUS Application Protocol Specification V1.1b3. 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

Routing Modbus requests is easy:

#!/usr/bin/env python
# scripts/examples/simple_data_store.py
import logging
from collections import defaultdict

from umodbus import get_server, conf
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 addresss against their values.
data_store = defaultdict(int)

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

app = get_server('localhost', 502)


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


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

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

Features

The following Modbus functions have been implemented:

  • 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.

Roadmap

uModbus is far from complete. The next, unordered list shows what is going to be implemented in the future:

  • Support for all Modbus functions

  • Modbus RTU

  • Use asyncio for handling of requests

  • Other Modbus ‘flavours’, so uModbus is able to handle 32 bit values.

License

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uModbus-0.3.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uModbus-0.3.1-py2.py3-none-any.whl (16.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file uModbus-0.3.1.tar.gz.

File metadata

  • Download URL: uModbus-0.3.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for uModbus-0.3.1.tar.gz
Algorithm Hash digest
SHA256 184345e108eb3665a57e20187041cc5a07005660494028dc227dc0d1cf99cf23
MD5 dec980dee86c56887754954b9dc6aaac
BLAKE2b-256 b6b970af789edfa1e1cb5bdf043aa61ddc90f82c4dff618bb9270a007ff12cdf

See more details on using hashes here.

File details

Details for the file uModbus-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for uModbus-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6be50b817524834e2dc3d642e7db1a316f41ce957fa9e2ff3e95cb3654b66497
MD5 45deea7077e1b26c770a464a8c1e711f
BLAKE2b-256 f0e3d43ac7a55fbf78fc5b7cd6fe0ee219c8f55a840c364dc6c7f9335531c2f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page