Skip to content

Commit

Permalink
Merge branch '#24' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Auke Willem Oosterhoff committed May 8, 2016
2 parents 7741a4e + 188c821 commit 3c2c558
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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 (or master in Modbus language) and a Modbus
server (or slave). The "u" or "μ" in the name comes from the the SI prefix
implements both a Modbus client (both TCP and RTU) and a Modbus TCP server
(only TCP). ThereThe "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 server is easy:
Creating a Modbus TCP server is easy:

..
Because GitHub doesn't support the include directive the source of
Expand Down Expand Up @@ -124,14 +124,14 @@ 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
* Modbus RTU server
* 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
uModbus software is licensed under `Mozilla Public License`_. © 2016 `Advanced
Climate Systems`_.

.. External References:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/client/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Client
======
Modbus Client
=============

uModbus contains a client for Modbus TCP and Modbus RTU.

Expand Down
3 changes: 3 additions & 0 deletions docs/source/client/rtu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Example
* 15: Write Multiple Coils
* 16: Write Multiple Registers

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

API
===

Expand Down
1 change: 0 additions & 1 deletion docs/source/client/tcp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ this:
.. include:: ../../../scripts/examples/simple_tcp_client.py
:code: python


API
===

Expand Down
7 changes: 7 additions & 0 deletions docs/source/decompose_requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ ADU for TCP/IP requests and responses

.. _MODBUS Messaging on TCP/IP Implementation Guide V1.0b: http://modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf
.. _MODBUS Application Protocol Specification V1.1b3: http://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf

ADU for RTU requests and responses
==================================

.. automodule:: umodbus.client.serial.rtu

.. _MODBUS over Serial Line Specification and Implementation Guide V1.02: http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf
6 changes: 3 additions & 3 deletions docs/source/functions.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Functions
---------
Modbus Functions
----------------

The Modbus functions have been implemented.
These Modbus functions have been implemented.

01: Read Coils
==============
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modbus_server.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Modbus server
Modbus Server
-------------

Viewpoint
Expand Down
33 changes: 33 additions & 0 deletions scripts/examples/simple_rtu_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# scripts/example/simple_rtu_client.py
import fcntl
import struct
from serial import Serial, PARITY_NONE

from umodbus.client.serial impor rtu


def get_serial_port():
""" Return serial.Serial instance, ready to use for RS485."""
port = Serial(port='/dev/ttyS1', baudrate=9600, parity=PARITY_NONE,
stopbits=1, bytesize=8, timeout=1)

fh = port.fileno()

# A struct with configuration for serial port.
serial_rs485 = struct.pack('hhhhhhhh', 1, 0, 0, 0, 0, 0, 0, 0)
fcntl.ioctl(fh, 0x542F, serial_rs485)

return port

serial_port = get_serial_port()

# Returns a message or Application Data Unit (ADU) specific for doing
# Modbus RTU.
message = rtu.write_multiple_coils(slave_id=1, 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 = rtu.send_message(message, serial_port)

serial_port.close()
2 changes: 1 addition & 1 deletion scripts/examples/simple_tcp_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# scripts/examples/simple_client.py
# scripts/examples/simple_tcp_client.py
import socket

from umodbus import conf
Expand Down
22 changes: 22 additions & 0 deletions umodbus/client/serial/rtu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
"""
.. note:: This section is based on `MODBUS over Serial Line Specification and
Implementation Guide V1.02`_.
The ADU for Modbus RTU messages differs from Modbus TCP/IP messages. Messages
send over RTU don't have a MBAP header, instead they have an Address field.
This field contains the slave id. A CRC is appended to the message. Below all
parts of a Modbus RTU message are listed together with their byte size:
+---------------+-----------------+
| **Component** | **Size** (bytes)|
+---------------+-----------------+
| Address field | 1 |
+---------------+-----------------+
| PDU | N |
+---------------+-----------------+
| CRC | 2 |
+---------------+-----------------+
The CRC is calculated from the Address field and the PDU.
"""

import struct
from serial import SerialTimeoutException

Expand Down
2 changes: 1 addition & 1 deletion umodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.. note:: This section is based on `MODBUS Messaging on TCP/IP
Implementation Guide V1.0b`_.
The Application Data Unit (ADU) for Modbus responses carried over a TCP/IP are
The Application Data Unit (ADU) for Modbus messages carried over a TCP/IP are
build out of two components: a MBAP header and a PDU. The Modbus Application
Header (MBAP) is what makes Modbus TCP/IP requests and responsen different from
their counterparts send over a serial line. Below the components of the Modbus
Expand Down

0 comments on commit 3c2c558

Please sign in to comment.