uModbus


NameuModbus JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/AdvancedClimateSystems/umodbus/
SummaryImplementation of the Modbus protocol in pure Python.
upload_time2020-08-27 20:21:53
maintainer
docs_urlNone
authorAuke Willem Oosterhoff
requires_python
licenseMPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. 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 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 addresss against their values.
    data_store = defaultdict(int)

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

    TCPServer.allow_reuse_address = True
    app = get_server(TCPServer, ('localhost', 502), RequestHandler)


    @app.route(slave_ids=[1], function_codes=[3, 4], 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=[6, 16], 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
    import socket

    from umodbus import conf
    from umodbus.client import tcp

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

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(('localhost', 502))

    # 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])

    # 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)

    sock.close()

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/



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AdvancedClimateSystems/umodbus/",
    "name": "uModbus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Auke Willem Oosterhoff",
    "author_email": "a.oosterhoff@climotion.com",
    "download_url": "https://files.pythonhosted.org/packages/c1/13/5eb635dd6ab67fedcfe5147209135a737d33c1220fdf4ad735a224a8a684/uModbus-1.0.4.tar.gz",
    "platform": "",
    "description": ".. image:: https://travis-ci.org/AdvancedClimateSystems/uModbus.svg\n   :target: https://travis-ci.org/AdvancedClimateSystems/uModbus\n\n.. image:: https://coveralls.io/repos/AdvancedClimateSystems/uModbus/badge.svg?service=github\n    :target: https://coveralls.io/github/AdvancedClimateSystems/uModbus\n\n.. image:: https://img.shields.io/pypi/v/uModbus.svg\n    :target: https://pypi.python.org/pypi/uModbus\n\n.. image:: https://img.shields.io/pypi/pyversions/uModbus.svg\n    :target: https://pypi.python.org/pypi/uModbus\n\nuModbus\n=======\n\nuModbus or (\u03bcModbus) is a pure Python implementation of the Modbus protocol as\ndescribed in the `MODBUS Application Protocol Specification V1.1b3`_. uModbus\nimplements both a Modbus client (both TCP and RTU) and a Modbus server (both\nTCP and RTU). The \"u\" or \"\u03bc\" in the name comes from the the SI prefix \"micro-\".\nuModbus is very small and lightweight. The source can be found on GitHub_.\nDocumentation is available at `Read the Docs`_.\n\nQuickstart\n----------\n\nCreating a Modbus TCP server is easy:\n\n..\n    Because GitHub doesn't support the include directive the source of\n    scripts/examples/simple_tcp_server.py has been copied to this file.\n\n.. code:: python\n\n    #!/usr/bin/env python\n    # scripts/examples/simple_tcp_server.py\n    import logging\n    from socketserver import TCPServer\n    from collections import defaultdict\n\n    from umodbus import conf\n    from umodbus.server.tcp import RequestHandler, get_server\n    from umodbus.utils import log_to_stream\n\n    # Add stream handler to logger 'uModbus'.\n    log_to_stream(level=logging.DEBUG)\n\n    # A very simple data store which maps addresss against their values.\n    data_store = defaultdict(int)\n\n    # Enable values to be signed (default is False).\n    conf.SIGNED_VALUES = True\n\n    TCPServer.allow_reuse_address = True\n    app = get_server(TCPServer, ('localhost', 502), RequestHandler)\n\n\n    @app.route(slave_ids=[1], function_codes=[3, 4], addresses=list(range(0, 10)))\n    def read_data_store(slave_id, function_code, address):\n        \"\"\"\" Return value of address. \"\"\"\n        return data_store[address]\n\n\n    @app.route(slave_ids=[1], function_codes=[6, 16], addresses=list(range(0, 10)))\n    def write_data_store(slave_id, function_code, address, value):\n        \"\"\"\" Set value for address. \"\"\"\n        data_store[address] = value\n\n    if __name__ == '__main__':\n        try:\n            app.serve_forever()\n        finally:\n            app.shutdown()\n            app.server_close()\n\nDoing a Modbus request requires even less code:\n\n..\n    Because GitHub doesn't support the include directive the source of\n    scripts/examples/simple_data_store.py has been copied to this file.\n\n.. code:: python\n\n    #!/usr/bin/env python\n    # scripts/examples/simple_tcp_client.py\n    import socket\n\n    from umodbus import conf\n    from umodbus.client import tcp\n\n    # Enable values to be signed (default is False).\n    conf.SIGNED_VALUES = True\n\n    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    sock.connect(('localhost', 502))\n\n    # Returns a message or Application Data Unit (ADU) specific for doing\n    # Modbus TCP/IP.\n    message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1])\n\n    # Response depends on Modbus function code. This particular returns the\n    # amount of coils written, in this case it is.\n    response = tcp.send_message(message, sock)\n\n    sock.close()\n\nFeatures\n--------\n\nThe following functions have been implemented for Modbus TCP and Modbus RTU:\n\n* 01: Read Coils\n* 02: Read Discrete Inputs\n* 03: Read Holding Registers\n* 04: Read Input Registers\n* 05: Write Single Coil\n* 06: Write Single Register\n* 15: Write Multiple Coils\n* 16: Write Multiple Registers\n\nOther featues:\n\n* Support for signed and unsigned register values.\n\nLicense\n-------\n\nuModbus software is licensed under `Mozilla Public License`_. \u00a9 2018 `Advanced\nClimate Systems`_.\n\n.. External References:\n.. _Advanced Climate Systems: http://www.advancedclimate.nl/\n.. _GitHub: https://github.com/AdvancedClimateSystems/uModbus/\n.. _MODBUS Application Protocol Specification V1.1b3: http://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf\n.. _Mozilla Public License: https://github.com/AdvancedClimateSystems/uModbus/blob/develop/LICENSE\n.. _Read the Docs: http://umodbus.readthedocs.org/en/latest/\n\n\n",
    "bugtrack_url": null,
    "license": "MPL",
    "summary": "Implementation of the Modbus protocol in pure Python.",
    "version": "1.0.4",
    "project_urls": {
        "Homepage": "https://github.com/AdvancedClimateSystems/umodbus/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1b9664b226d34cc5154dfd0f92ccfaa6cb03dd3d2f77951c0d67eedb74ace5b",
                "md5": "3c5f74cdeb60849aaf999c740e4d470e",
                "sha256": "aab3e61488d8bef638466687b360192ddf046a23b61a9ba3734b4f48d31efe16"
            },
            "downloads": -1,
            "filename": "uModbus-1.0.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3c5f74cdeb60849aaf999c740e4d470e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 31500,
            "upload_time": "2020-08-27T20:21:50",
            "upload_time_iso_8601": "2020-08-27T20:21:50.207373Z",
            "url": "https://files.pythonhosted.org/packages/d1/b9/664b226d34cc5154dfd0f92ccfaa6cb03dd3d2f77951c0d67eedb74ace5b/uModbus-1.0.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1135eb635dd6ab67fedcfe5147209135a737d33c1220fdf4ad735a224a8a684",
                "md5": "96d1742479fcbfb12e51eb0161b2ae95",
                "sha256": "26bbbeff02d6d8a3e29bb0f9d9044c672d55fc1687afe4297a2f7d68175103a7"
            },
            "downloads": -1,
            "filename": "uModbus-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "96d1742479fcbfb12e51eb0161b2ae95",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19423,
            "upload_time": "2020-08-27T20:21:53",
            "upload_time_iso_8601": "2020-08-27T20:21:53.162783Z",
            "url": "https://files.pythonhosted.org/packages/c1/13/5eb635dd6ab67fedcfe5147209135a737d33c1220fdf4ad735a224a8a684/uModbus-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-27 20:21:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AdvancedClimateSystems",
    "github_project": "umodbus",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "umodbus"
}
        
Elapsed time: 3.43367s