Skip to content

Commit

Permalink
Add draft of Usage section.
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeTux committed Nov 7, 2015
1 parent fb30edb commit 67dffab
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ or "μ" in the name comes from the the SI prefix "micro-". uModbus is very small
and lightweight. uModbus is open source and licenced under `Mozilla Public
License`_. The source can be found on GitHub_.

Routing Modbus requests is easy::
Routing Modbus requests is easy:

.. code:: python
from umodbus import get_server
Expand Down
51 changes: 51 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Usage
-----

Viewpoint
=========

uModbus is build with routing in mind. Routing (groups of) requests to a
certain callback must be easy. This is in contrast with with other Modbus
implementation which often focus on reading and writing from a data store.

Because of this difference in view point uModbus doesn't know the concepts of
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`.

.. code:: python
from umodbus import get_server
from collections import defaultdict
# 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/

0 comments on commit 67dffab

Please sign in to comment.