Skip to content

Commit 53c5894

Browse files
author
Karl Herbig
committed
Create a copy of RTU Layer as a starting poiont for building the ASCII Layer
1 parent 5462684 commit 53c5894

File tree

8 files changed

+573
-0
lines changed

8 files changed

+573
-0
lines changed

include/modbuspp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <modbuspp/rtulayer.h>
20+
#include <modbuspp/asciilayer.h>
2021
#include <modbuspp/tcplayer.h>
2122
#include <modbuspp/master.h>
2223
#include <modbuspp/server.h>

include/modbuspp/asciilayer.h

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/* Copyright © 2018-2019 Pascal JEAN, All rights reserved.
2+
* This file is part of the libmodbuspp Library.
3+
*
4+
* The libmodbuspp Library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 3 of the License, or (at your option) any later version.
8+
*
9+
* The libmodbuspp Library 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 GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with the libmodbuspp Library; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
#pragma once
18+
19+
#include <modbuspp/netlayer.h>
20+
21+
namespace Modbus {
22+
23+
/**
24+
* @class AsciiLayer
25+
* @brief RTU serial link layer
26+
*
27+
* This class can not and should not be instantiated by the user.
28+
* It provides access to properties and methods specific to the RTU layer.
29+
*
30+
* An instance of this class is created by the constructor @b Device::Device()
31+
* of the @b Device class (or its derived classes) if the RTU layer is selected.
32+
*
33+
* Access to this instance is done using the Device::rtu() method.
34+
*
35+
* @sa Device::Device()
36+
* @sa Device::rtu()
37+
*
38+
* @author Pascal JEAN, aka epsilonrt
39+
* @copyright GNU Lesser General Public License
40+
*/
41+
class AsciiLayer : public NetLayer {
42+
public:
43+
44+
/**
45+
* @brief Constructor
46+
*/
47+
AsciiLayer (const std::string & port, const std::string & settings);
48+
49+
/**
50+
* @brief Name of the serial port
51+
*
52+
* This property specifies the name of the serial port handled by the
53+
* OS, eg. "/dev/ttyS0" or "/dev/ttyUSB0".
54+
*/
55+
const std::string & port() const;
56+
57+
/**
58+
* @brief Return the baudrate
59+
*/
60+
int baud() const;
61+
62+
/**
63+
* @brief Return the parity
64+
*/
65+
char parity() const;
66+
67+
/**
68+
* @brief Return the bits of stop
69+
*/
70+
int stop() const;
71+
72+
/**
73+
* @brief Get the current serial mode
74+
*
75+
* This function shall return the serial mode currently used.
76+
*
77+
* - @b Rs232: the serial line is set for RS232 communication. RS-232
78+
* (Recommended Standard 232) is the traditional name for a series of
79+
* standards for serial binary single-ended data and control signals
80+
* connecting between a DTE (Data Terminal Equipment) and a DCE
81+
* (Data Circuit-terminating Equipment).
82+
* It is commonly used in computer serial ports
83+
* - @b Rs485: the serial line is set for RS485 communication. EIA-485,
84+
* also known as TIA/EIA-485 or RS-485, is a standard defining the electrical
85+
* characteristics of drivers and receivers for use in balanced digital
86+
* multipoint systems. This standard is widely used for communications in
87+
* industrial automation because it can be used effectively over long
88+
* distances and in electrically noisy environments.
89+
* .
90+
* This function is only available on Linux kernels 2.6.28 onwards.
91+
*
92+
* @return return the current mode if successful.
93+
* Otherwise it shall return @b UnknownMode (-1) and set errno.
94+
* @sa setSerialMode()
95+
*/
96+
SerialMode serialMode();
97+
98+
/**
99+
* @brief Set the serial mode
100+
*
101+
* This function shall set the selected serial mode @b mode.
102+
*
103+
* @return true if successful.
104+
* Otherwise it shall return false and set errno.
105+
* @sa serialMode()
106+
*/
107+
bool setSerialMode (SerialMode mode);
108+
109+
/**
110+
* @brief Get the current RTS mode
111+
*
112+
* This function shall get the current Request To Send mode
113+
*
114+
* @return the current RTS mode if successful.
115+
* Otherwise it shall return @b UnknownRts (-1) and set errno.
116+
* @sa setRts()
117+
*/
118+
SerialRts rts();
119+
120+
/**
121+
* @brief Set the RTS mode
122+
*
123+
* This function shall set the Request To Send mode to communicate on a
124+
* RS485 serial bus.
125+
*
126+
* @return true if successful.
127+
* Otherwise it shall return false and set errno.
128+
* @sa rts()
129+
*/
130+
bool setRts (SerialRts rts);
131+
132+
/**
133+
* @brief Get the current RTS delay
134+
*
135+
* This function shall get the current Request To Send delay period.
136+
* @return the current RTS delay in microseconds if successful.
137+
* Otherwise it shall return -1 and set errno.
138+
* @sa setRtsDelay()
139+
*/
140+
int rtsDelay();
141+
142+
/**
143+
* @brief Set the RTS delay
144+
*
145+
* This function shall set the Request To Send delay period in microseconds.
146+
*
147+
* @return true if successful.
148+
* Otherwise it shall return false and set errno.
149+
* @sa rtsDelay()
150+
*/
151+
bool setRtsDelay (int us);
152+
153+
/**
154+
* @overload
155+
*
156+
* @warning This function is not supported by Windows !
157+
*/
158+
virtual int sendRawMessage (const Message * msg);
159+
160+
/**
161+
* @overload
162+
*/
163+
virtual bool prepareToSend (Message & msg);
164+
165+
/**
166+
* @overload
167+
*/
168+
static bool checkMessage (const Message & msg);
169+
170+
/**
171+
* @brief Extracts the baudrate from a settings string.
172+
* @return the baudrate found. if no value is found, returns the default
173+
* value, ie 19200.
174+
*/
175+
static int baud (const std::string & settings);
176+
177+
/**
178+
* @brief Extracts the parity from a settings string.
179+
* @return the parity found. if no value is found, returns the default
180+
* value, ie E for Even parity.
181+
*/
182+
static char parity (const std::string & settings);
183+
184+
/**
185+
* @brief Return the stop bits from a settings string.
186+
*
187+
* @return the number returned is determined based on the parity found.
188+
* If the parity is None, this function returns 2, otherwise returns 1.
189+
*/
190+
static int stop (const std::string & settings);
191+
192+
/**
193+
* @brief Performing Modbus CRC16 generation of the buffer @b buf
194+
*/
195+
static uint16_t crc16 (const uint8_t * buf, uint16_t count);
196+
197+
protected:
198+
class Private;
199+
AsciiLayer (Private &dd);
200+
201+
private:
202+
PIMP_DECLARE_PRIVATE (AsciiLayer)
203+
};
204+
}
205+
206+
/* ========================================================================== */

include/modbuspp/global.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ namespace Modbus {
4848
* protocol communication.
4949
*/
5050
Rtu,
51+
/**
52+
* @brief ASCII backend
53+
*
54+
* The ASCII backend is used in serial communication.
55+
* The hex value of the binary data is transmitted
56+
* in ASCII character representation.
57+
*/
58+
Ascii,
5159
/**
5260
* @brief TCP backend
5361
*

0 commit comments

Comments
 (0)