Skip to content

Commit 7523c7a

Browse files
committed
Adds documentation package
1 parent e8382ce commit 7523c7a

33 files changed

+3491
-54
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2018 Pascal JEAN, All rights reserved.
1+
# Copyright © 2018-2019 Pascal JEAN, All rights reserved.
22
# This file is part of the libmodbuspp Project.
33
#
44
# The libmodbuspp Project is free software: you can redistribute it and/or modify
@@ -129,7 +129,7 @@ add_compile_options(-Wno-psabi)
129129
add_subdirectory (dev)
130130
add_subdirectory (lib)
131131
#add_subdirectory (utils)
132-
#add_subdirectory (doc)
132+
add_subdirectory (doc)
133133

134134
if (MODBUSPP_WITH_DOXYGEN_DOC)
135135
add_dependencies(modbuspp-shared doc)

README.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1441
A good example always better than a long explanation, this is an extremely
1542
simple example:
1643

17-
```c++
44+
```cpp
1845
uint16_t values[2]; // array to store the values of the input registers
1946
Master mb (Rtu, port, "19200E1"); // new master on RTU
2047
mb.open(); // open a connection
@@ -62,7 +89,7 @@ If you want to build from sources, you can follow the
6289
6390
Here 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

106133
To 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

110137
You can then run it :
111138

112-
$ ./read-input-registers
139+
./read-input-registers
113140
R0=9964
114141
R1=10029
115142

dev/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2018 Pascal JEAN, All rights reserved.
1+
# Copyright © 2018-2019 Pascal JEAN, All rights reserved.
22
# This file is part of the libmodbuspp Project.
33
#
44
# The libmodbuspp Project is free software: you can redistribute it and/or modify

dev/cmake/GitVersion.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2018 Pascal JEAN, All rights reserved.
1+
# Copyright © 2018-2019 Pascal JEAN, All rights reserved.
22
# This file is part of the libmodbuspp Project.
33
#
44
# The libmodbuspp Project is free software: you can redistribute it and/or modify

doc/CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright © 2018-2019 Pascal JEAN, All rights reserved.
2+
# This file is part of the libmodbuspp Project.
3+
#
4+
# The libmodbuspp Project is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# The libmodbuspp Project is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with the libmodbuspp Project. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# doc CMakeLists.txt
18+
19+
cmake_minimum_required(VERSION 2.8.11)
20+
21+
set (MODBUSPP_WITH_DOXYGEN_DOC 0 CACHE BOOL "Enable build of the documentation")
22+
23+
# set packaging dir
24+
if(NOT CPACK_PACKAGE_DIRECTORY)
25+
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages)
26+
endif()
27+
28+
if("${CMAKE_PROJECT_NAME}" STREQUAL "Project")
29+
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
30+
endif()
31+
32+
if (MODBUSPP_WITH_DOXYGEN_DOC)
33+
34+
find_package(Doxygen REQUIRED)
35+
set(DOXYGEN_README ${PROJECT_SOURCE_DIR}/README.md)
36+
set(DOXYGEN_FILE ${CMAKE_BINARY_DIR}/Doxyfile)
37+
set(DOXYGEN_MAINPAGE ${CMAKE_BINARY_DIR}/main_page.dox)
38+
39+
set(DOXYGEN_INPUT_LIST
40+
${PROJECT_SOURCE_DIR}/include/modbuspp.h
41+
${PROJECT_SOURCE_DIR}/include/modbuspp-data.h
42+
)
43+
44+
set(DOXYGEN_INPUT "${CMAKE_BINARY_DIR}/main_page.dox")
45+
foreach(item ${DOXYGEN_INPUT_LIST})
46+
# get_filename_component(item_dir ${item} DIRECTORY)
47+
string(APPEND DOXYGEN_INPUT " ${item} ")
48+
endforeach(item ${DOXYGEN_INPUT_LIST})
49+
50+
#message("DOXYGEN_INPUT=${DOXYGEN_INPUT}")
51+
52+
configure_file(Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
53+
configure_file(build_main_page.sh.in ${CMAKE_BINARY_DIR}/build_main_page.sh @ONLY)
54+
55+
add_custom_target(main_page.dox
56+
COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation Main Page..."
57+
COMMAND sh ${CMAKE_BINARY_DIR}/build_main_page.sh > /dev/null
58+
COMMAND ${CMAKE_COMMAND} -E echo "Done."
59+
DEPENDS main_page_header.dox main_page_footer.dox ${PROJECT_SOURCE_DIR}/README.md
60+
)
61+
62+
add_custom_target(html
63+
COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation..."
64+
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE} > /dev/null
65+
COMMAND ${CMAKE_COMMAND} -E echo "Done."
66+
DEPENDS main_page.dox DoxygenLayout.xml Doxyfile.in ${DOXYGEN_INPUT_LIST}
67+
)
68+
69+
add_custom_target(doc)
70+
add_dependencies(doc main_page.dox html)
71+
72+
# message("MODBUSPP_INSTALL_DOC_DIR=${MODBUSPP_INSTALL_DOC_DIR}")
73+
file(GLOB manpages ${CMAKE_BINARY_DIR}/man/man3/Modbus_*.3)
74+
75+
install(DIRECTORY ${CMAKE_BINARY_DIR}/html/
76+
DESTINATION ${MODBUSPP_INSTALL_DOC_DIR}/api-manual COMPONENT doc)
77+
install(FILES ${manpages}
78+
DESTINATION "${INSTALL_DATA_DIR}/man/man3" COMPONENT doc)
79+
80+
endif(MODBUSPP_WITH_DOXYGEN_DOC)

0 commit comments

Comments
 (0)