Skip to content

Commit

Permalink
Add sections Usage and Functions to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeTux committed Nov 8, 2015
1 parent 67dffab commit 51753df
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 261 deletions.
17 changes: 2 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,9 @@ License`_. The source can be found on GitHub_.

Routing Modbus requests is easy:

.. code:: python
.. include:: ../../scripts/examples/simple_data_store.py
:code: python

from umodbus import get_server
server = get_server('localhost', 502)
@server.route(slave_ids=[1], function_codes=[3, 4], addresses=list(range(100, 200)))
def return_address(slave_id, address):
""" Return address. """
print('Called with slave_id {0} and address {1}.'.format(slave_id, address))
return address
try:
server.serve_forever()
finally:
server.shutdown()

.. External References:
.. _GitHub: https://github.com/AdvancedClimateSystems/uModbus/
Expand Down
9 changes: 6 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../'))

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -50,7 +50,7 @@
master_doc = 'index'

# General information about the project.
project = 'Modbus'
project = 'uModbus'
copyright = '2015, Auke Willem Oosterhoff <oosterhoff@baopt.nl>'
author = 'Auke Willem Oosterhoff <oosterhoff@baopt.nl>'

Expand Down Expand Up @@ -157,7 +157,10 @@
#html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
html_sidebars = {
'index': ['globaltoc.html', 'searchbox.html'],
'**': ['globaltoc.html', 'relations.html', 'searchbox.html']
}

# Additional templates that should be rendered to pages, maps page names to
# template names.
Expand Down
44 changes: 44 additions & 0 deletions docs/source/functions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Functions
---------

The Modbus functions have been implemented.

01: Read Coils
==============

.. autoclass:: umodbus.functions.ReadCoils

02: Read Discrete Inputs
========================

.. autoclass:: umodbus.functions.ReadDiscreteInputs

03: Read Holding Registers
==========================

.. autoclass:: umodbus.functions.ReadHoldingRegisters

04: Read Input Registers
========================

.. autoclass:: umodbus.functions.ReadInputRegisters

05: Write Single Coil
=====================

.. autoclass:: umodbus.functions.WriteSingleCoil

06: Write Single Register
=========================

.. autoclass:: umodbus.functions.WriteSingleRegister

15: Write Multiple Coils
========================

.. autoclass:: umodbus.functions.WriteMultipleCoils

16: Write Multiple Register
===========================

.. autoclass:: umodbus.functions.WriteMultipleRegisters
8 changes: 0 additions & 8 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ Contents:
usage
decompose_requests
functions


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 6 additions & 29 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,16 @@ Modbus' data models (discrete inputs, coils, input registers and holding
registers) and their read/write properties.

Routing
-------
=======

The route system was inspired by Flask_. Like Flask, uModbus requires a global
app or server. This server contains a route map. Routes can be added to this
route map. The following example demostrates how to route all Modbus requests
for slave 1, function code 1 en 2 addressed to address 0 to the endpoint
`read_gpio_status`.
route map.

.. code:: python
The following code example demonstrates how to implement a very simple data
store for 10 addresses.

from umodbus import get_server
from collections import defaultdict
.. include:: ../../scripts/examples/simple_data_store.py
:code: python

# A very simple data store which maps addresss against their values.
data_store = dict(int)
server = get_server('localhost', 502)
@server.route(slave_ids=[1], functions_codes=[3, 4], addresses=list(range(0, 10)))
def read_data_store(slave_id, address):
"""" Return value of address. """
return data_store[address]
@server.route(slave_ids=[1], functions_codes=[3, 4], addresses=list(range(0, 10)))
def write_data_store(slave_id, address, value):
"""" Set value for address. """
data_store[address] = value
try:
server.serve_forever()
finally:
server.stop()
.. External references
.. _Flask: http://flask.pocoo.org/
27 changes: 27 additions & 0 deletions scripts/examples/simple_data_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# scripts/examples/simple_data_store.py
from umodbus import get_server
from collections import defaultdict

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

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.stop()
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python
from setuptools import setup

setup(name='Python-Modbus',
setup(name='uModbus',
version='0.1.0',
author='Auke Willem Oosterhoff',
author_email='oosterhoff@baopt.nl',
description='Implementation of the Modbus protocol in pure Python.',
url='https://github.com/AdvancedClimateSystems/python-modbus/',
url='https://github.com/AdvancedClimateSystems/umodbus/',
packages=[
'modbus',
'umodbus',
],
classifiers=[
'Development Status :: 2 - Pre-Alpha',
Expand Down
2 changes: 2 additions & 0 deletions umodbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ def emit(self, record):

log = getLogger('tolk')
log.addHandler(NullHandler())

from .server import get_server # NOQA
Loading

0 comments on commit 51753df

Please sign in to comment.