Skip to content

Commit e733515

Browse files
committed
Fix documentation
1 parent db153e7 commit e733515

19 files changed

+445
-159
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ Version 1.5.1
3131
* Added REPR statements for all syncchronous clients
3232
* Added `isError` method to exceptions, Any response received can be tested for success before proceeding.
3333

34-
```
34+
.. code-block:: python
35+
3536
res = client.read_holding_registers(...)
3637
if not res.isError():
3738
# proceed
3839
else:
3940
# handle error or raise
40-
```
41+
4142
* Add examples for MEI read device information request
4243

4344
Version 1.5.0

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ tox: install
4747

4848
docs: install
4949
@pip install --quiet --requirement=requirements-docs.txt
50-
@cd doc && make html
50+
@cd doc && make clean && make html
5151

5252
publish: install
5353
git push origin && git push --tags origin

README.rst

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
================================
2+
PyModbus - A Python Modbus Stack
3+
================================
4+
15
.. image:: https://travis-ci.org/riptideio/pymodbus.svg?branch=master
26
:target: https://travis-ci.org/riptideio/pymodbus
37
.. image:: https://badges.gitter.im/Join%20Chat.svg
@@ -12,9 +16,9 @@
1216
.. important::
1317
**Note This is a Major release and might affect your existing Async client implementation. Refer examples on how to use the latest async clients.**
1418

15-
============================================================
19+
------------------------------------------------------------
1620
Summary
17-
============================================================
21+
------------------------------------------------------------
1822

1923
Pymodbus is a full Modbus protocol implementation using twisted for its
2024
asynchronous communications core. It can also be used without any third
@@ -23,13 +27,13 @@ needed. Furthermore, it should work fine under any python version > 2.7
2327
(including python 3+)
2428

2529

26-
============================================================
30+
------------------------------------------------------------
2731
Features
28-
============================================================
29-
3032
------------------------------------------------------------
33+
34+
~~~~~~~~~~~~~~~~~~~~
3135
Client Features
32-
------------------------------------------------------------
36+
~~~~~~~~~~~~~~~~~~~~
3337

3438
* Full read/write protocol on discrete and register
3539
* Most of the extended protocol (diagnostic/file/pipe/setting/information)
@@ -38,19 +42,19 @@ Client Features
3842
* Payload builder/decoder utilities
3943
* Pymodbus REPL for quick tests
4044

41-
------------------------------------------------------------
45+
~~~~~~~~~~~~~~~~~~~~
4246
Server Features
43-
------------------------------------------------------------
47+
~~~~~~~~~~~~~~~~~~~~
4448

4549
* Can function as a fully implemented modbus server
4650
* TCP, UDP, Serial ASCII, Serial RTU, and Serial Binary
4751
* asynchronous(powered by twisted) and synchronous versions
4852
* Full server control context (device information, counters, etc)
4953
* A number of backing contexts (database, redis, sqlite, a slave device)
5054

51-
============================================================
55+
------------------------------------------------------------
5256
Use Cases
53-
============================================================
57+
------------------------------------------------------------
5458

5559
Although most system administrators will find little need for a Modbus
5660
server on any modern hardware, they may find the need to query devices on
@@ -94,21 +98,24 @@ trace them. I get a lot of email and sometimes these requests
9498
get lost in the noise: http://groups.google.com/group/pymodbus or
9599
at gitter: https://gitter.im/pymodbus_dev/Lobby
96100

97-
============================================================
101+
------------------------------------------------------------
98102
Pymodbus REPL (Read Evaluate Procee Loop)
99-
============================================================
103+
------------------------------------------------------------
100104
Starting with Pymodbus 2.x, pymodbus library comes with handy
101105
Pymodbus REPL to quickly run the modbus clients in tcp/rtu modes.
102106

103107
Pymodbus REPL comes with many handy features such as payload decoder
104108
to directly retrieve the values in desired format and supports all
105109
the diagnostic function codes directly .
106110

107-
For more info on REPL refer `Pymodbus REPL <pymodbus/repl/README.md>`_
111+
For more info on REPL refer `Pymodbus REPL <https://github.com/riptideio/pymodbus/tree/master/pymodbus/repl>`_
112+
113+
.. image:: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o.png
114+
:target: https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o
108115

109-
============================================================
116+
------------------------------------------------------------
110117
Installing
111-
============================================================
118+
------------------------------------------------------------
112119

113120
You can install using pip or easy install by issuing the following
114121
commands in a terminal window (make sure you have correct
@@ -144,9 +151,9 @@ out all mentions of twisted. It should be noted that without twisted,
144151
one will only be able to run the synchronized version as the
145152
asynchronous versions uses twisted for its event loop.
146153

147-
============================================================
154+
------------------------------------------------------------
148155
Current Work In Progress
149-
============================================================
156+
------------------------------------------------------------
150157

151158
Since I don't have access to any live modbus devices anymore
152159
it is a bit hard to test on live hardware. However, if you would
@@ -182,14 +189,14 @@ Use make to perform a range of activities
182189
make tox run the tests on all Python versions
183190
make clean cleanup all temporary files
184191

185-
============================================================
192+
------------------------------------------------------------
186193
Contributing
187-
============================================================
194+
------------------------------------------------------------
188195
Just fork the repo and raise your PR against `dev` branch.
189196

190-
============================================================
197+
------------------------------------------------------------
191198
License Information
192-
============================================================
199+
------------------------------------------------------------
193200

194201
Pymodbus is built on top of code developed from/by:
195202
* Copyright (c) 2001-2005 S.W.A.C. GmbH, Germany.

doc/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
============
2+
CHANGELOGS
3+
============
4+
15
.. include:: ../CHANGELOG.rst

doc/conf.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#
1919
import os
2020
import sys
21+
import recommonmark
22+
from recommonmark.parser import CommonMarkParser
23+
from recommonmark.transform import AutoStructify
2124
parent_dir = os.path.abspath(os.pardir)
2225
# examples = os.path.join(parent_dir, "examples")
2326
example_contrib = os.path.join(parent_dir, "examples/contrib")
@@ -31,7 +34,7 @@
3134
# sys.path.extend([examples, example_common, example_contrib, example_gui])
3235
# sys.path.insert(0, os.path.abspath('../'))
3336

34-
37+
github_doc_root = 'https://github.com/riptideio/pymodbus/tree/master/doc/'
3538
# -- General configuration ------------------------------------------------
3639

3740
# If your documentation needs a minimal Sphinx version, state it here.
@@ -41,16 +44,20 @@
4144
# Add any Sphinx extension module names here, as strings. They can be
4245
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4346
# ones.
44-
extensions = ['sphinx.ext.autodoc']
47+
extensions = ['sphinx.ext.autodoc', 'recommonmark']
4548

4649
# Add any paths that contain templates here, relative to this directory.
4750
templates_path = ['_templates']
4851

4952
# The suffix(es) of source filenames.
5053
# You can specify multiple suffix as a list of string:
5154
#
52-
# source_suffix = ['.rst', '.md']
53-
source_suffix = '.rst'
55+
source_parsers = {
56+
'.md': CommonMarkParser,
57+
}
58+
59+
source_suffix = ['.rst', '.md']
60+
# source_suffix = '.rst'
5461

5562
# The master toctree document.
5663
master_doc = 'index'
@@ -176,4 +183,10 @@
176183
]
177184

178185

186+
def setup(app):
187+
app.add_config_value('recommonmark_config', {
188+
'url_resolver': lambda url: github_doc_root + url,
189+
'auto_toc_tree_section': 'Contents',
190+
}, True)
191+
app.add_transform(AutoStructify)
179192

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Welcome to PyModbus's documentation!
1212

1313
readme.rst
1414
changelog.rst
15-
repl.rst
15+
source/library/REPL
1616
source/example/modules.rst
1717
source/library/modules.rst
1818

doc/repl.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

doc/source/library/REPL.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Pymodbus REPL
2+
3+
## Dependencies
4+
5+
Depends on [prompt_toolkit](https://python-prompt-toolkit.readthedocs.io/en/stable/index.html) and [click](http://click.pocoo.org/6/quickstart/)
6+
7+
Install dependencies
8+
```
9+
$ pip install click prompt_toolkit --upgarde
10+
```
11+
12+
Or
13+
Install pymodbus with repl support
14+
```
15+
$ pip install pymodbus[repl] --upgrade
16+
```
17+
18+
## Usage Instructions
19+
RTU and TCP are supported as of now
20+
```
21+
bash-3.2$ pymodbus.console
22+
Usage: pymodbus.console [OPTIONS] COMMAND [ARGS]...
23+
24+
Options:
25+
--version Show the version and exit.
26+
--verbose Verbose logs
27+
--support-diag Support Diagnostic messages
28+
--help Show this message and exit.
29+
30+
Commands:
31+
rtu
32+
tcp
33+
34+
35+
```
36+
TCP Options
37+
```
38+
bash-3.2$ pymodbus.console tcp --help
39+
Usage: pymodbus.console tcp [OPTIONS]
40+
41+
Options:
42+
--host TEXT Modbus TCP IP
43+
--port INTEGER Modbus TCP port
44+
--help Show this message and exit.
45+
46+
47+
48+
49+
```
50+
51+
RTU Options
52+
```
53+
bash-3.2$ pymodbus.console rtu --help
54+
Usage: pymodbus.console rtu [OPTIONS]
55+
56+
Options:
57+
--method TEXT Modbus Serial Mode (rtu/ascii)
58+
--port TEXT Modbus RTU port
59+
--baudrate INTEGER Modbus RTU serial baudrate to use. Defaults to 9600
60+
--bytesize [5|6|7|8] Modbus RTU serial Number of data bits. Possible
61+
values: FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS.
62+
Defaults to 8
63+
--parity [N|E|O|M|S] Modbus RTU serial parity. Enable parity checking.
64+
Possible values: PARITY_NONE, PARITY_EVEN, PARITY_ODD
65+
PARITY_MARK, PARITY_SPACE. Default to 'N'
66+
--stopbits [1|1.5|2] Modbus RTU serial stop bits. Number of stop bits.
67+
Possible values: STOPBITS_ONE,
68+
STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO. Default to '1'
69+
--xonxoff INTEGER Modbus RTU serial xonxoff. Enable software flow
70+
control.Defaults to 0
71+
--rtscts INTEGER Modbus RTU serial rtscts. Enable hardware (RTS/CTS)
72+
flow control. Defaults to 0
73+
--dsrdtr INTEGER Modbus RTU serial dsrdtr. Enable hardware (DSR/DTR)
74+
flow control. Defaults to 0
75+
--timeout FLOAT Modbus RTU serial read timeout. Defaults to 0.025 sec
76+
--write-timeout FLOAT Modbus RTU serial write timeout. Defaults to 2 sec
77+
--help Show this message and exit.
78+
```
79+
80+
To view all available commands type `help`
81+
82+
```
83+
$ pymodbus.console tcp --host 192.168.128.126 --port 5020
84+
85+
> help
86+
Available commands:
87+
client.change_ascii_input_delimiter Diagnostic sub command, Change message delimiter for future requests
88+
client.clear_counters Diagnostic sub command, Clear all counters and diag registers
89+
client.clear_overrun_count Diagnostic sub command, Clear over run counter
90+
client.force_listen_only_mode Diagnostic sub command, Forces the addressed remote device to its Listen Only Mode
91+
client.get_clear_modbus_plus Diagnostic sub command, Get or clear stats of remote modbus plus device
92+
client.get_com_event_counter Read status word and an event count from the remote device's communication event counter
93+
client.get_com_event_log Read status word, event count, message count, and a field of event bytes from the remote device.
94+
client.mask_write_register Mask content of holding register at `address` with `and_mask` and `or_mask`
95+
client.read_coils Reads `count` coils from a given slave starting at `address`
96+
client.read_device_information Read the identification and additional information of remote slave
97+
client.read_discrete_inputs Reads `count` number of discrete inputs starting at offset `address`
98+
client.read_exception_status Read the contents of eight Exception Status outputs in a remote device.
99+
client.read_holding_registers Read `count` number of holding registers starting at `address`
100+
client.read_input_registers Read `count` number of input registers starting at `address`
101+
client.readwrite_registers Read `read_count` number of holding registers starting at `read_address` and write `write_registers` starting at `write_address`
102+
client.report_slave_id Report information about remote slave ID
103+
client.restart_comm_option Diagnostic sub command, initialize and restart remote devices serial interface and clear all of its communications event counters .
104+
client.return_bus_com_error_count Diagnostic sub command, Return count of CRC errors received by remote slave
105+
client.return_bus_exception_error_count Diagnostic sub command, Return count of Modbus exceptions returned by remote slave
106+
client.return_bus_message_count Diagnostic sub command, Return count of message detected on bus by remote slave
107+
client.return_diagnostic_register Diagnostic sub command, Read 16-bit diagnostic register
108+
client.return_iop_overrun_count Diagnostic sub command, Return count of iop overrun errors by remote slave
109+
client.return_query_data Diagnostic sub command , Loop back data sent in response
110+
client.return_slave_bus_char_overrun_count Diagnostic sub command, Return count of messages not handled by remote slave due to character overrun condition
111+
client.return_slave_busy_count Diagnostic sub command, Return count of server busy exceptions sent by remote slave
112+
client.return_slave_message_count Diagnostic sub command, Return count of messages addressed to remote slave
113+
client.return_slave_no_ack_count Diagnostic sub command, Return count of NO ACK exceptions sent by remote slave
114+
client.return_slave_no_response_count Diagnostic sub command, Return count of No responses by remote slave
115+
client.write_coil Write `value` to coil at `address`
116+
client.write_coils Write `value` to coil at `address`
117+
client.write_register Write `value` to register at `address`
118+
client.write_registers Write list of `values` to registers starting at `address`
119+
result.decode Decode the register response to known formatters
120+
result.raw Return raw result dict
121+
```
122+
123+
Every command has auto suggetion on the arguments supported , supply arg and value are to be supplied in `arg=val` format.
124+
```
125+
126+
> client.read_holding_registers count=4 address=9 unit=1
127+
{
128+
"registers": [
129+
60497,
130+
47134,
131+
34091,
132+
15424
133+
]
134+
}
135+
```
136+
137+
The last result could be accessed with `result.raw` command
138+
```
139+
> result.raw
140+
{
141+
"registers": [
142+
15626,
143+
55203,
144+
28733,
145+
18368
146+
]
147+
}
148+
```
149+
150+
For Holding and Input register reads, the decoded value could be viewed with `result.decode`
151+
```
152+
> result.decode word_order=little byte_order=little formatters=float64
153+
28.17
154+
155+
>
156+
```
157+
158+
## DEMO
159+
160+
[![asciicast](https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o.png)](https://asciinema.org/a/y1xOk7lm59U1bRBE2N1pDIj2o)
161+

0 commit comments

Comments
 (0)