CuteHMI - Modbus (CuteHMI.Modbus.2)
RTUClientConfig.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_RTUCLIENTCONFIG_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_RTUCLIENTCONFIG_HPP
3 
4 #include "Config.hpp"
5 
6 #include <QObject>
7 #include <QString>
8 #include <QModbusDevice>
9 #include <QReadWriteLock>
10 #include <QSerialPort>
11 
12 namespace cutehmi {
13 namespace modbus {
14 namespace internal {
15 
16 class CUTEHMI_MODBUS_PRIVATE RTUClientConfig:
17  public Config
18 {
19  Q_OBJECT
20 
21  public:
22  static constexpr int MIN_SLAVE_ADDRESS = 1; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
23  static constexpr int MAX_SLAVE_ADDRESS = 247; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
24  static const char * INITIAL_PORT;
25  static constexpr QSerialPort::Parity INITIAL_PARITY = QSerialPort::NoParity;
26  static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE = QSerialPort::Baud19200;
27  static constexpr QSerialPort::DataBits INITIAL_DATA_BITS = QSerialPort::Data8;
28  static constexpr QSerialPort::StopBits INITIAL_STOP_BITS = QSerialPort::OneStop;
29  static constexpr int INITIAL_SLAVE_ADDRESS = MIN_SLAVE_ADDRESS;
30 
31  explicit RTUClientConfig(QObject * parent = nullptr);
32 
33  QString port() const;
34 
35  void setPort(const QString & port);
36 
37  QSerialPort::Parity parity() const;
38 
39  void setParity(QSerialPort::Parity parity);
40 
41  QSerialPort::BaudRate baudRate() const;
42 
43  void setBaudRate(QSerialPort::BaudRate baudRate);
44 
45  QSerialPort::DataBits dataBits() const;
46 
47  void setDataBits(QSerialPort::DataBits dataBits);
48 
49  QSerialPort::StopBits stopBits() const;
50 
51  void setStopBits(QSerialPort::StopBits stopBits);
52 
53  int slaveAddress() const;
54 
55  void setSlaveAddress(int slaveAddress);
56 
57  private:
58  struct Members
59  {
60  QString port = INITIAL_PORT;
61  QSerialPort::Parity parity = INITIAL_PARITY;
62  QSerialPort::BaudRate baudRate = INITIAL_BAUD_RATE;
63  QSerialPort::DataBits dataBits = INITIAL_DATA_BITS;
64  QSerialPort::StopBits stopBits = INITIAL_STOP_BITS;
65  int slaveAddress = INITIAL_SLAVE_ADDRESS;
66  mutable QReadWriteLock lock;
67  };
68 
69  MPtr<Members> m;
70 };
71 
72 }
73 }
74 }
75 
76 #endif
77 
78 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
79 //(c)C: This file is a part of CuteHMI.
80 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
81 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
82 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
cutehmi::MPtr< Members >
cutehmi::modbus::internal::RTUClientConfig
Definition: RTUClientConfig.hpp:16
QObject
cutehmi
QString
cutehmi::modbus::internal::RTUClientConfig::INITIAL_PORT
static const char * INITIAL_PORT
Definition: RTUClientConfig.hpp:24
std::internal
T internal(T... args)
cutehmi::modbus::internal::Config
Definition: Config.hpp:10
QReadWriteLock