Skip to content

Commit 7b239ac

Browse files
Merge pull request #38 from NikolasK-source/main
update to 1.6.0
2 parents a27b516 + db00e1f commit 7b239ac

File tree

9 files changed

+60
-63
lines changed

9 files changed

+60
-63
lines changed

.gitmodules

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
[submodule "libs/cxxopts"]
2-
path = libs/cxxopts
3-
url = https://github.com/NikolasK-source/cxxopts.git
4-
[submodule "libs/libmodbus"]
5-
path = libs/libmodbus
6-
url = https://github.com/stephane/libmodbus
7-
[submodule "libs/cxxshm"]
8-
path = libs/cxxshm
9-
url = https://github.com/NikolasK-source/cxxshm.git
10-
[submodule "libs/cxxsemaphore"]
11-
path = libs/cxxsemaphore
12-
url = https://github.com/NikolasK-source/cxxsemaphore.git

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
99
# ======================================================================================================================
1010

1111
# project
12-
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.5.3)
12+
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.6.0)
1313

1414
# settings
1515
set(Target "modbus-tcp-client-shm") # Executable name (without file extension!)

README.md

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,67 @@
22

33
Modbus tcp client that stores its data (registers) in shared memory objects.
44

5+
## Dependencies
6+
- cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts) (only required for building the application)
7+
- libmodbus by Stéphane Raimbault (https://github.com/stephane/libmodbus)
8+
- cxxshm (https://github.com/NikolasK-source/cxxshm)
9+
- cxxsemaphore (https://github.com/NikolasK-source/cxxsemaphore)
10+
11+
On Arch linux they are available via the official repositories and the AUR:
12+
- https://archlinux.org/packages/extra/any/cxxopts/
13+
- https://aur.archlinux.org/packages/libmodbus
14+
- https://aur.archlinux.org/packages/cxxshm
15+
- https://aur.archlinux.org/packages/cxxsemaphore
16+
517
## Build
618
```
7-
git submodule init
8-
git submodule update
9-
mkdir build
10-
cd build
11-
cmake .. -DCMAKE_CXX_COMPILER=$(which clang++) -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
19+
cmake -B build -DCMAKE_CXX_COMPILER=$(which clang++) -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCLANG_TIDY=OFF -DCOMPILER_WARNINGS=OFF -DBUILD_DOC=OFF
1220
cmake --build .
1321
```
1422

15-
As an alternative to the ```git submodule``` commands, the ```--recursive``` option can be used with ```git clone```.
16-
1723
## Use
1824
```
1925
modbus-tcp-client-shm [OPTION...]
2026
21-
-i, --ip arg ip to listen for incoming connections (default: 0.0.0.0)
22-
-p, --port arg port to listen for incoming connections (default: 502)
23-
-n, --name-prefix arg shared memory name prefix (default: modbus_)
27+
network options:
28+
-i, --host arg host to listen for incoming connections (default: any)
29+
-p, --service arg service or port to listen for incoming connections (default: 502)
30+
-c, --connections arg number of allowed simultaneous Modbus Server connections. (default: 1)
31+
-r, --reconnect do not terminate if no Modbus Server is connected anymore.
32+
-t, --tcp-timeout arg tcp timeout in seconds. Set to 0 to use the system defaults (not recommended). (default: 5)
33+
34+
shared memory options:
35+
-n, --name-prefix arg shared memory name prefix (default: modbus_)
36+
--force Force the use of the shared memory even if it already exists. Do not use this option per default! It should only be used if the shared memory of an improperly terminated instance continues to exist as an orphan
37+
and is no longer used.
38+
-s, --separate arg Use a separate shared memory for requests with the specified client id. The client id (as hex value) is appended to the shared memory prefix (e.g. modbus_fc_DO). You can specify multiple client ids by
39+
separating them with ','. Use --separate-all to generate separate shared memories for all possible client ids.
40+
--separate-all like --separate, but for all client ids (creates 1028 shared memory files! check/set 'ulimit -n' before using this option.)
41+
--semaphore arg protect the shared memory with a named semaphore against simultaneous access
42+
--semaphore-force Force the use of the semaphore even if it already exists. Do not use this option per default! It should only be used if the semaphore of an improperly terminated instance continues to exist as an orphan and is
43+
no longer used.
44+
-b, --permissions arg permission bits that are applied when creating a shared memory. (default: 0640)
45+
46+
modbus options:
2447
--do-registers arg number of digital output registers (default: 65536)
2548
--di-registers arg number of digital input registers (default: 65536)
2649
--ao-registers arg number of analog output registers (default: 65536)
2750
--ai-registers arg number of analog input registers (default: 65536)
2851
-m, --monitor output all incoming and outgoing packets to stdout
29-
-r, --reconnect do not terminate if the Modbus Server disconnects.
30-
--byte-timeout arg timeout interval in seconds between two consecutive bytes of the same message. In most
31-
cases it is sufficient to set the response timeout. Fractional values are possible.
32-
--response-timeout arg set the timeout interval in seconds used to wait for a response. When a byte timeout is
33-
set, if the elapsed time for the first byte of response is longer than the given timeout,
34-
a timeout is detected. When byte timeout is disabled, the full confirmation response must
35-
be received before expiration of the response timeout. Fractional values are possible.
36-
-t, --tcp-timeout arg tcp timeout in seconds. Set to 0 to use the system defaults (not recommended). (default:
37-
5)
38-
--force Force the use of the shared memory even if it already exists. Do not use this option per
39-
default! It should only be used if the shared memory of an improperly terminated instance
40-
continues to exist as an orphan and is no longer used.
41-
-s, --separate arg Use a separate shared memory for requests with the specified client id. The client id
42-
(as hex value) is appended to the shared memory prefix (e.g. modbus_fc_DO). You can
43-
specify multiple client ids by separating them with ','. Use --separate-all to generate
44-
separate shared memories for all possible client ids.
45-
--separate-all like --separate, but for all client ids (creates 1028 shared memory files! check/set
46-
'ulimit -n' before using this option.)
47-
-h, --help print usage
48-
--version print version information
49-
--license show licences
52+
--byte-timeout arg timeout interval in seconds between two consecutive bytes of the same message. In most cases it is sufficient to set the response timeout. Fractional values are possible.
53+
--response-timeout arg set the timeout interval in seconds used to wait for a response. When a byte timeout is set, if the elapsed time for the first byte of response is longer than the given timeout, a timeout is detected. When
54+
byte timeout is disabled, the full confirmation response must be received before expiration of the response timeout. Fractional values are possible.
55+
56+
other options:
57+
-h, --help print usage
58+
--license show licences (short)
59+
--license-full show licences (full license text)
60+
61+
version information options:
62+
--version print version and exit
63+
--longversion print version (including compiler and system info) and exit
64+
--shortversion print version (only version string) and exit
65+
--git-hash print git hash
5066
5167
5268
The modbus registers are mapped to shared memory objects:
@@ -66,8 +82,3 @@ The following example redirects packets from port 502 (standard modbus port) to
6682
iptables -A PREROUTING -t nat -p tcp --dport 502 -j REDIRECT --to-port 5020
6783
```
6884
The modbus client must be called with the option ```-p 5020```
69-
70-
## Libraries
71-
This application uses the following libraries:
72-
- cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts)
73-
- libmodbus by Stéphane Raimbault (https://github.com/stephane/libmodbus)

libs/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
# ---------------------------------------- packages --------------------------------------------------------------------
2+
# ======================================================================================================================
3+
find_package(cxxshm REQUIRED)
4+
find_package(cxxsemaphore REQUIRED)
5+
find_package(cxxopts REQUIRED)
6+
7+
# ---------------------------------------- external libs ---------------------------------------------------------------
8+
# ======================================================================================================================
9+
find_library(modbus_library modbus)
110

211
# ---------------------------------------- subdirectories --------------------------------------------------------------
312
# ======================================================================================================================
4-
include(../modbus.cmake)
5-
target_link_libraries(${Target} PRIVATE modbus)
613

714
# ---------------------------------------- link libraries --------------------------------------------------------------
815
# ======================================================================================================================
16+
target_link_libraries(${Target} PRIVATE ${modbus_library})
917
target_link_libraries(${Target} PRIVATE rt)
10-
11-
add_subdirectory(cxxopts EXCLUDE_FROM_ALL)
12-
target_link_libraries(${Target} PRIVATE cxxopts)
13-
14-
add_subdirectory(cxxshm EXCLUDE_FROM_ALL)
18+
target_link_libraries(${Target} PRIVATE INTERFACE cxxopts)
1519
target_link_libraries(${Target} PRIVATE cxxshm)
16-
17-
add_subdirectory(cxxsemaphore EXCLUDE_FROM_ALL)
1820
target_link_libraries(${Target} PRIVATE cxxsemaphore)

libs/cxxopts

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/cxxsemaphore

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/cxxshm

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/libmodbus

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ int main(int argc, char **argv) {
193193
cxxopts::ParseResult args;
194194
try {
195195
args = options.parse(argc, argv);
196-
} catch (cxxopts::OptionParseException &e) {
196+
} catch (cxxopts::exceptions::parsing::exception &e) {
197197
std::cerr << Print_Time::iso << " ERROR: Failed to parse arguments: " << e.what() << ".'\n";
198198
return exit_usage();
199199
}

0 commit comments

Comments
 (0)