Skip to content

Commit aeca250

Browse files
Merge pull request #12 from NikolasK-source/main
Release 0.2.3
2 parents 74dc622 + 149678c commit aeca250

File tree

7 files changed

+105
-88
lines changed

7 files changed

+105
-88
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
44
# ======================================================================================================================
55

66
# project
7-
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.2.2)
7+
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.2.3)
88

99
# settings
1010
set(Target "modbus-rtu-client-shm") # Executable name (without file extension!)

README.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,43 @@ As an alternative to the ```git submodule``` commands, the ```--recursive``` opt
1616

1717
## Use
1818
```
19-
Modbus_RTU_client_shm [OPTION...]
20-
21-
-d, --device arg mandatory: serial device
22-
-i, --id arg mandatory: modbus RTU slave id
23-
-p, --parity arg serial parity bit (N(one), E(ven), O(dd)) (default: N)
24-
--data-bits arg serial data bits (5-8) (default: 8)
25-
--stop-bits arg serial stop bits (1-2) (default: 1)
26-
-b, --baud arg serial baud (default: 9600)
27-
--rs485 force to use rs485 mode
28-
--rs232 force to use rs232 mode
29-
-n, --name-prefix arg shared memory name prefix (default: modbus_)
30-
--do-registers arg number of digital output registers (default: 65536)
31-
--di-registers arg number of digital input registers (default: 65536)
32-
--ao-registers arg number of analog output registers (default: 65536)
33-
--ai-registers arg number of analog input registers (default: 65536)
34-
-m, --monitor output all incoming and outgoing packets to stdout
35-
-h, --help print usage
19+
modbus-rtu-client-shm [OPTION...]
20+
21+
-d, --device arg mandatory: serial device
22+
-i, --id arg mandatory: modbus RTU client id
23+
-p, --parity arg serial parity bit (N(one), E(ven), O(dd)) (default: N)
24+
--data-bits arg serial data bits (5-8) (default: 8)
25+
--stop-bits arg serial stop bits (1-2) (default: 1)
26+
-b, --baud arg serial baud (default: 9600)
27+
--rs485 force to use rs485 mode
28+
--rs232 force to use rs232 mode
29+
-n, --name-prefix arg shared memory name prefix (default: modbus_)
30+
--do-registers arg number of digital output registers (default: 65536)
31+
--di-registers arg number of digital input registers (default: 65536)
32+
--ao-registers arg number of analog output registers (default: 65536)
33+
--ai-registers arg number of analog input registers (default: 65536)
34+
-m, --monitor output all incoming and outgoing packets to stdout
35+
--byte-timeout arg timeout interval in seconds between two consecutive bytes of the same message. In most
36+
cases it is sufficient to set the response timeout. Fractional values are possible.
37+
--response-timeout arg set the timeout interval in seconds used to wait for a response. When a byte timeout is
38+
set, if the elapsed time for the first byte of response is longer than the given timeout,
39+
a timeout is detected. When byte timeout is disabled, the full confirmation response must
40+
be received before expiration of the response timeout. Fractional values are possible.
41+
--force Force the use of the shared memory even if it already exists. Do not use this option per
42+
default! It should only be used if the shared memory of an improperly terminated instance
43+
continues to exist as an orphan and is no longer used.
44+
-h, --help print usage
45+
--version print version information
46+
--license show licences
3647
3748
3849
The modbus registers are mapped to shared memory objects:
39-
type | name | master-access | shm name
40-
-----|---------------------------|-----------------|----------------
41-
DO | Discrete Output Coils | read-write | <name-prefix>DO
42-
DI | Discrete Input Coils | read-only | <name-prefix>DI
43-
AO | Discrete Output Registers | read-write | <name-prefix>AO
44-
AI | Discrete Input Registers | read-only | <name-prefix>AI
50+
type | name | mb-server-access | shm name
51+
-----|---------------------------|------------------|----------------
52+
DO | Discrete Output Coils | read-write | <name-prefix>DO
53+
DI | Discrete Input Coils | read-only | <name-prefix>DI
54+
AO | Discrete Output Registers | read-write | <name-prefix>AO
55+
AI | Discrete Input Registers | read-only | <name-prefix>AI
4556
```
4657

4758
## Libraries

docs/index.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ One for each register type:
1313
- Discrete Input Registers (AI)
1414

1515
All registers are initialized with 0 at the beginning.
16-
The Modbus master reads and writes directly the values from these shared memories.
16+
The Modbus server reads and writes directly the values from these shared memories.
1717

1818
The actual functionality of the client is realized by applications that read data from or write data to the shared memory.
1919

@@ -24,7 +24,7 @@ The registers (AI, AO) use 10 bit per value. The user is responsible for handlin
2424
The application requires a serial device (```--device```) and a client id (```--id```) as arguments. All other arguments are optional.
2525

2626
By using the command line argument ```--monitor``` all incoming and outgoing packets are printed on stdout.
27-
This option should be used carefully, as it generates large amounts of output depending on the masters polling cycle and the number of used registers.
27+
This option should be used carefully, as it generates large amounts of output depending on the Modbus servers polling cycle and the number of used registers.
2828

2929
The client creates four shared memories and names them ```modbus_DO```, ```modbus_DI```, ```modbus_AO``` and ```modbus_AI``` by default.
3030
The prefix modbus_ can be changed via the argument ```--name-prefix```.
@@ -50,8 +50,14 @@ Connect as device with id ```1``` using serial device ```/dev/ttyS0``` and enfor
5050
```
5151
modbus-rtu-client-shm -d /dev/ttyS0 -i 1 --rs232
5252
```
53+
## Install
5354

54-
## Using the Flatpak package
55+
### Using the Modbus Collection Flapak Package: Shared Memory Modbus (recommended)
56+
[SHM-Modbus](https://nikolask-source.github.io/SHM_Modbus/) is a collection of the shared memory modbus tools.
57+
It is available as flatpak and published on flathub as ```network.koesling.shm-modbs```.
58+
59+
60+
### Using the Standalone Flatpak Package
5561
The flatpak package can be installed via the .flatpak file.
5662
This can be downloaded from the GitHub [projects release page](https://github.com/NikolasK-source/modbus_rtu_client_shm/releases):
5763

@@ -68,7 +74,7 @@ To enable calling with ```modbus-rtu-client-shm``` [this script](https://gist.gi
6874
In order to be executable everywhere, the path in which the script is placed must be in the ```PATH``` environment variable.
6975

7076

71-
## Build from Source
77+
### Build from Source
7278

7379
The following packages are required for building the application:
7480
- cmake

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
target_sources(${Target} PRIVATE main.cpp)
55
target_sources(${Target} PRIVATE modbus_shm.cpp)
6-
target_sources(${Target} PRIVATE Modbus_RTU_Slave.cpp)
6+
target_sources(${Target} PRIVATE Modbus_RTU_Client.cpp)
77
target_sources(${Target} PRIVATE license.cpp)
88

99

1010
# ---------------------------------------- header files (*.jpp, *.h, ...) ----------------------------------------------
1111
# ======================================================================================================================
1212
target_sources(${Target} PRIVATE modbus_shm.hpp)
13-
target_sources(${Target} PRIVATE Modbus_RTU_Slave.hpp)
13+
target_sources(${Target} PRIVATE Modbus_RTU_Client.hpp)
1414
target_sources(${Target} PRIVATE license.hpp)
1515

1616

src/Modbus_RTU_Slave.cpp renamed to src/Modbus_RTU_Client.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
44
*/
55

6-
#include "Modbus_RTU_Slave.hpp"
6+
#include "Modbus_RTU_Client.hpp"
77

88
#include <stdexcept>
99

@@ -12,15 +12,15 @@ namespace RTU {
1212

1313
static constexpr int MAX_REGS = 0x10000;
1414

15-
Slave::Slave(const std::string &device,
16-
int id,
17-
char parity,
18-
int data_bits,
19-
int stop_bits,
20-
int baud,
21-
bool rs232,
22-
bool rs485,
23-
modbus_mapping_t *mapping) {
15+
Client::Client(const std::string &device,
16+
int id,
17+
char parity,
18+
int data_bits,
19+
int stop_bits,
20+
int baud,
21+
bool rs232,
22+
bool rs485,
23+
modbus_mapping_t *mapping) {
2424
// create modbus object
2525
modbus = modbus_new_rtu(device.c_str(), baud, parity, data_bits, stop_bits);
2626
if (modbus == nullptr) {
@@ -71,22 +71,22 @@ Slave::Slave(const std::string &device,
7171
}
7272
}
7373

74-
Slave::~Slave() {
74+
Client::~Client() {
7575
if (modbus != nullptr) {
7676
modbus_close(modbus);
7777
modbus_free(modbus);
7878
}
7979
if (mapping != nullptr && delete_mapping) modbus_mapping_free(mapping);
8080
}
8181

82-
void Slave::set_debug(bool debug) {
82+
void Client::set_debug(bool debug) {
8383
if (modbus_set_debug(modbus, debug)) {
8484
const std::string error_msg = modbus_strerror(errno);
8585
throw std::runtime_error("failed to enable modbus debugging mode: " + error_msg);
8686
}
8787
}
8888

89-
bool Slave::handle_request() {
89+
bool Client::handle_request() {
9090
// receive modbus request
9191
uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH];
9292
int rc = modbus_receive(modbus, query);
@@ -120,7 +120,7 @@ static inline timeout_t double_to_timeout_t(double timeout) {
120120
return ret;
121121
}
122122

123-
void Slave::set_byte_timeout(double timeout) {
123+
void Client::set_byte_timeout(double timeout) {
124124
const auto T = double_to_timeout_t(timeout);
125125
auto ret = modbus_set_byte_timeout(modbus, T.sec, T.usec);
126126

@@ -130,7 +130,7 @@ void Slave::set_byte_timeout(double timeout) {
130130
}
131131
}
132132

133-
void Slave::set_response_timeout(double timeout) {
133+
void Client::set_response_timeout(double timeout) {
134134
const auto T = double_to_timeout_t(timeout);
135135
auto ret = modbus_set_response_timeout(modbus, T.sec, T.usec);
136136

@@ -140,7 +140,7 @@ void Slave::set_response_timeout(double timeout) {
140140
}
141141
}
142142

143-
double Slave::get_byte_timeout() {
143+
double Client::get_byte_timeout() {
144144
timeout_t timeout {};
145145

146146
auto ret = modbus_get_byte_timeout(modbus, &timeout.sec, &timeout.usec);
@@ -153,7 +153,7 @@ double Slave::get_byte_timeout() {
153153
return static_cast<double>(timeout.sec) + (static_cast<double>(timeout.usec) / (1000.0 * 1000.0));
154154
}
155155

156-
double Slave::get_response_timeout() {
156+
double Client::get_response_timeout() {
157157
timeout_t timeout {};
158158

159159
auto ret = modbus_get_response_timeout(modbus, &timeout.sec, &timeout.usec);

src/Modbus_RTU_Slave.hpp renamed to src/Modbus_RTU_Client.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
namespace Modbus {
1212
namespace RTU {
1313

14-
//! Modbus RTU slave
15-
class Slave {
14+
//! Modbus RTU client
15+
class Client {
1616
private:
1717
modbus_t *modbus; //!< modbus object (see libmodbus library)
1818
modbus_mapping_t *mapping; //!< modbus data object (see libmodbus library)
1919
bool delete_mapping; //!< indicates whether the mapping object was created by this instance
2020
int socket = -1; //!< internal modbus communication socket
2121

2222
public:
23-
/*! \brief create modbus slave (TCP server)
23+
/*! \brief create modbus client (TCP server)
2424
*
2525
* @param device serial device
26-
* @param id modbus rtu slave id
26+
* @param id modbus rtu client id
2727
* @param parity serial parity bit (N(one), E(ven), O(dd))
2828
* @param data_bits number of serial data bits
2929
* @param stop_bits number of serial stop bits
@@ -32,28 +32,28 @@ class Slave {
3232
* @param rs485 connect using rs485 mode
3333
* @param mapping modbus mapping object (nullptr: an mapping object with maximum size is generated)
3434
*/
35-
explicit Slave(const std::string &device,
36-
int id,
37-
char parity,
38-
int data_bits,
39-
int stop_bits,
40-
int baud,
41-
bool rs232,
42-
bool rs485,
43-
modbus_mapping_t *mapping = nullptr);
35+
explicit Client(const std::string &device,
36+
int id,
37+
char parity,
38+
int data_bits,
39+
int stop_bits,
40+
int baud,
41+
bool rs232,
42+
bool rs485,
43+
modbus_mapping_t *mapping = nullptr);
4444

45-
/*! \brief destroy the modbus slave
45+
/*! \brief destroy the modbus client
4646
*
4747
*/
48-
~Slave();
48+
~Client();
4949

5050
/*! \brief enable/disable debugging output
5151
*
5252
* @param debug true: enable debug output
5353
*/
5454
void set_debug(bool debug);
5555

56-
/*! \brief wait for request from Master and generate reply
56+
/*! \brief wait for request from Modbus Server and generate reply
5757
*
5858
* @return true: connection closed
5959
*/

0 commit comments

Comments
 (0)