CuteHMI - Modbus (CuteHMI.Modbus.2)
RTUServer.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_RTUSERVER_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_RTUSERVER_HPP
3 
4 #include "AbstractServer.hpp"
5 #include "internal/RegisterTraits.hpp"
6 #include "internal/QtRTUServerBackend.hpp"
7 
8 #include <cutehmi/macros.hpp>
9 
10 #include <QThread>
11 #include <QStateMachine>
12 
13 namespace cutehmi {
14 namespace modbus {
15 
16 class CUTEHMI_MODBUS_API RTUServer:
17  public AbstractServer
18 {
19  Q_OBJECT
20 
21  public:
22  static constexpr int MIN_SLAVE_ADDRESS = internal::RTUServerConfig::MIN_SLAVE_ADDRESS;
23  static constexpr int MAX_SLAVE_ADDRESS = internal::RTUServerConfig::MAX_SLAVE_ADDRESS;
24  static const char * INITIAL_PORT;
25  static constexpr QSerialPort::Parity INITIAL_PARITY = internal::RTUServerConfig::INITIAL_PARITY;
26  static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE = internal::RTUServerConfig::INITIAL_BAUD_RATE;
27  static constexpr QSerialPort::DataBits INITIAL_DATA_BITS = internal::RTUServerConfig::INITIAL_DATA_BITS;
28  static constexpr QSerialPort::StopBits INITIAL_STOP_BITS = internal::RTUServerConfig::INITIAL_STOP_BITS;
29  static constexpr int INITIAL_SLAVE_ADDRESS = internal::RTUServerConfig::INITIAL_SLAVE_ADDRESS;
30  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN;
31  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX;
32  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN;
33  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX;
34  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN;
35  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX;
36  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN;
37  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX;
38 
39  Q_PROPERTY(QString port READ port WRITE setPort NOTIFY portChanged)
40  Q_PROPERTY(QSerialPort::Parity parity READ parity WRITE setParity NOTIFY parityChanged)
41  Q_PROPERTY(QSerialPort::BaudRate baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
42  Q_PROPERTY(QSerialPort::DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
43  Q_PROPERTY(QSerialPort::StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)
44  Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
45 
46  RTUServer(QObject * parent = nullptr);
47 
48  ~RTUServer() override;
49 
50  QString port() const;
51 
52  void setPort(const QString & port);
53 
54  QSerialPort::Parity parity() const;
55 
56  void setParity(QSerialPort::Parity);
57 
58  QSerialPort::BaudRate baudRate() const;
59 
60  void setBaudRate(QSerialPort::BaudRate baudRate);
61 
62  QSerialPort::DataBits dataBits() const;
63 
64  void setDataBits(QSerialPort::DataBits dataBits);
65 
66  QSerialPort::StopBits stopBits() const;
67 
68  void setStopBits(QSerialPort::StopBits stopBits);
69 
70  int slaveAddress() const;
71 
72  void setSlaveAddress(int slaveAddress);
73 
74  void setBusy(bool busy) override;
75 
76  public slots:
77  void open() override;
78 
79  void close() override;
80 
81  signals:
82  void portChanged();
83 
84  void parityChanged();
85 
86  void baudRateChanged();
87 
88  void dataBitsChanged();
89 
90  void stopBitsChanged();
91 
92  void slaveAddressChanged();
93 
94  private:
95  struct Members
96  {
99  QThread thread;
100 
101  Members(internal::QtRTUServer::CoilDataContainer * coilData,
105  backend(& config, coilData, discreteInputData, holdingRegisterData, inputRegisterData)
106  {
107  }
108  };
109 
110  MPtr<Members> m;
111 };
112 
113 }
114 }
115 
116 #endif
117 
118 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
119 //(c)C: This file is a part of CuteHMI.
120 //(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.
121 //(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.
122 //(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::modbus::internal::QtRTUServer::DiscreteInputDataContainer
RegisterTraits< DiscreteInput >::Container DiscreteInputDataContainer
Definition: QtRTUServer.hpp:28
cutehmi::modbus::internal::QtRTUServer::CoilDataContainer
RegisterTraits< Coil >::Container CoilDataContainer
Definition: QtRTUServer.hpp:27
cutehmi::modbus::internal::QtRTUServerBackend
TCP server backend.
Definition: QtRTUServerBackend.hpp:15
cutehmi::modbus::internal::RTUServerConfig::INITIAL_BAUD_RATE
static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE
Definition: RTUServerConfig.hpp:27
cutehmi::modbus::internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:36
QThread
cutehmi::modbus::RTUServer::INITIAL_PORT
static const char * INITIAL_PORT
Definition: RTUServer.hpp:24
cutehmi::modbus::internal::RTUServerConfig::INITIAL_PARITY
static constexpr QSerialPort::Parity INITIAL_PARITY
Definition: RTUServerConfig.hpp:26
cutehmi::modbus::internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:33
cutehmi::modbus::internal::RTUServerConfig::INITIAL_DATA_BITS
static constexpr QSerialPort::DataBits INITIAL_DATA_BITS
Definition: RTUServerConfig.hpp:28
cutehmi::modbus::internal::QtRTUServer::HoldingRegisterDataContainer
RegisterTraits< HoldingRegister >::Container HoldingRegisterDataContainer
Definition: QtRTUServer.hpp:29
cutehmi::MPtr< Members >
cutehmi::modbus::RTUServer
Definition: RTUServer.hpp:16
cutehmi::modbus::internal::RTUServerConfig::MIN_SLAVE_ADDRESS
static constexpr int MIN_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:23
cutehmi::modbus::internal::RTUServerConfig::INITIAL_STOP_BITS
static constexpr QSerialPort::StopBits INITIAL_STOP_BITS
Definition: RTUServerConfig.hpp:29
cutehmi::modbus::internal::RTUServerConfig::MAX_SLAVE_ADDRESS
static constexpr int MAX_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:24
QObject
cutehmi
cutehmi::modbus::internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:34
QString
cutehmi::modbus::internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:38
cutehmi::modbus::internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:35
cutehmi::modbus::internal::RTUServerConfig
Definition: RTUServerConfig.hpp:15
cutehmi::modbus::internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN
static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:31
cutehmi::modbus::internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX
static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:32
cutehmi::modbus::AbstractServer
Abstract server.
Definition: AbstractServer.hpp:15
cutehmi::modbus::internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:37
cutehmi::modbus::internal::QtRTUServer::InputRegisterDataContainer
RegisterTraits< InputRegister >::Container InputRegisterDataContainer
Definition: QtRTUServer.hpp:30
cutehmi::modbus::internal::RTUServerConfig::INITIAL_SLAVE_ADDRESS
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:30