@@ -4,17 +4,44 @@ _A C++ wrapper for the [libmodbus](https://libmodbus.org/) library_
44
55## Abstract
66
7- libmodbus is a free software library to send/receive data according to the
8- Modbus protocol. This library is written in C and supports RTU (serial) and
9- TCP (Ethernet) communications.
10-
11- The libmodbuspp library provides a C++ overlay to [ libmodbus] ( https://libmodbus.org/ ) , a wrapper,
12- having no other dependency than libmodbus and libstdc++
7+ [ libmodbus] ( https://libmodbus.org/ ) is a free software library to send/receive
8+ data according to the MODBUS protocol. This library is written in C and supports
9+ RTU (serial) and TCP (Ethernet) communications.
10+
11+ MODBUS is considered an application layer messaging protocol, providing
12+ Master/Slave communication between devices connected together through buses or
13+ networks.
14+ On the OSI model, MODBUS is positioned at level 7. MODBUS is intended to be a
15+ request/reply protocol and delivers services specified by function codes.
16+ The function codes of MODBUS are elements of MODBUS’ request/reply PDUs
17+ (Protocol Data Unit).
18+
19+ In order to build the MODBUS application data unit, the client must initiate a
20+ MODBUS transaction. It is the function which informs the server as to which type
21+ of action to perform. The format of a request initiated by a Master is
22+ established by the MODBUS application protocol. The function code field is then
23+ coded into one byte. Only codes within the range of 1 through 255 are
24+ considered valid, with 128-255 being reserved for exception responses.
25+ When the Master sends a message to the Slave, it is the function code field
26+ which informs the server of what type of action to perform.
27+
28+ To define multiple actions, some functions will have sub-function codes added to
29+ them. For instance, the Master is able to read the ON/OFF states of a group of
30+ discreet outputs or inputs.
31+ It could also read/write the data contents of a group of MODBUS registers.
32+ When the Master receives the Slave response, the function code field is used by
33+ the Slave to indicate either an error-free response or an exception response.
34+ The Slave echoes to the request of the initial function code in the case of a
35+ normal response.
36+
37+ The libmodbuspp library provides a C++ overlay to
38+ [ libmodbus] ( https://libmodbus.org/ ) , a wrapper, having no other dependency than
39+ libmodbus and libstdc++
1340
1441A good example always better than a long explanation, this is an extremely
1542simple example:
1643
17- ``` c++
44+ ``` cpp
1845uint16_t values[2 ]; // array to store the values of the input registers
1946Master mb (Rtu, port, "19200E1"); // new master on RTU
2047mb.open(); // open a connection
@@ -62,7 +89,7 @@ If you want to build from sources, you can follow the
6289
6390Here is a complete example that can be compiled without error:
6491
65- ```c++
92+ ```cpp
6693#include <iostream>
6794#include <string>
6895#include <modbuspp.h>
@@ -105,11 +132,11 @@ in `main.cpp`
105132
106133To build, you must type the command:
107134
108- $ g++ -o read-input-registers main.cpp $(pkg-config --cflags --libs libmodbuspp)
135+ g++ -o read-input-registers main.cpp $(pkg-config --cflags --libs libmodbuspp)
109136
110137You can then run it :
111138
112- $ ./read-input-registers
139+ ./read-input-registers
113140 R0=9964
114141 R1=10029
115142
0 commit comments