CuteHMI - Modbus (CuteHMI.Modbus.2)
RTUClient.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_RTUCLIENT_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_RTUCLIENT_HPP
3 
4 #include "AbstractClient.hpp"
5 #include "internal/QtRTUClientBackend.hpp"
6 
7 #include <QThread>
8 
9 namespace cutehmi {
10 namespace modbus {
11 
15 class CUTEHMI_MODBUS_API RTUClient:
16  public AbstractClient
17 {
18  Q_OBJECT
19 
20  public:
21  static constexpr int MIN_SLAVE_ADDRESS = internal::RTUClientConfig::MIN_SLAVE_ADDRESS;
22  static constexpr int MAX_SLAVE_ADDRESS = internal::RTUClientConfig::MAX_SLAVE_ADDRESS;
23  static const char * INITIAL_PORT;
24  static constexpr QSerialPort::Parity INITIAL_PARITY = internal::RTUClientConfig::INITIAL_PARITY;
25  static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE = internal::RTUClientConfig::INITIAL_BAUD_RATE;
26  static constexpr QSerialPort::DataBits INITIAL_DATA_BITS = internal::RTUClientConfig::INITIAL_DATA_BITS;
27  static constexpr QSerialPort::StopBits INITIAL_STOP_BITS = internal::RTUClientConfig::INITIAL_STOP_BITS;
28  static constexpr int INITIAL_SLAVE_ADDRESS = internal::RTUClientConfig::INITIAL_SLAVE_ADDRESS;
29 
30  Q_PROPERTY(QString port READ port WRITE setPort NOTIFY portChanged)
31  Q_PROPERTY(QSerialPort::Parity parity READ parity WRITE setParity NOTIFY parityChanged)
32  Q_PROPERTY(QSerialPort::BaudRate baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
33  Q_PROPERTY(QSerialPort::DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
34  Q_PROPERTY(QSerialPort::StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)
35  Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
36 
37  RTUClient(QObject * parent = nullptr);
38 
39  ~RTUClient() override;
40 
41  QString port() const;
42 
43  void setPort(const QString & port);
44 
45  QSerialPort::Parity parity() const;
46 
47  void setParity(QSerialPort::Parity);
48 
49  QSerialPort::BaudRate baudRate() const;
50 
51  void setBaudRate(QSerialPort::BaudRate baudRate);
52 
53  QSerialPort::DataBits dataBits() const;
54 
55  void setDataBits(QSerialPort::DataBits dataBits);
56 
57  QSerialPort::StopBits stopBits() const;
58 
59  void setStopBits(QSerialPort::StopBits stopBits);
60 
61  int slaveAddress() const;
62 
63  void setSlaveAddress(int slaveAddress);
64 
65  public slots:
66  void open() override;
67 
68  void close() override;
69 
70  signals:
71  void portChanged();
72 
73  void parityChanged();
74 
75  void baudRateChanged();
76 
77  void dataBitsChanged();
78 
79  void stopBitsChanged();
80 
81  void slaveAddressChanged();
82 
83  private:
84  struct Members {
87  QThread thread;
88 
89  Members():
90  backend(& config)
91  {
92  }
93  };
94 
95  MPtr<Members> m;
96 };
97 
98 }
99 }
100 
101 #endif
102 
103 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
104 //(c)C: This file is a part of CuteHMI.
105 //(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.
106 //(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.
107 //(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::RTUClientConfig::INITIAL_SLAVE_ADDRESS
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: RTUClientConfig.hpp:29
cutehmi::modbus::internal::RTUClientConfig::INITIAL_STOP_BITS
static constexpr QSerialPort::StopBits INITIAL_STOP_BITS
Definition: RTUClientConfig.hpp:28
QThread
cutehmi::modbus::internal::RTUClientConfig::MAX_SLAVE_ADDRESS
static constexpr int MAX_SLAVE_ADDRESS
Definition: RTUClientConfig.hpp:23
cutehmi::modbus::internal::RTUClientConfig::INITIAL_BAUD_RATE
static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE
Definition: RTUClientConfig.hpp:26
cutehmi::modbus::RTUClient::INITIAL_PORT
static const char * INITIAL_PORT
Definition: RTUClient.hpp:23
cutehmi::modbus::internal::RTUClientConfig::INITIAL_PARITY
static constexpr QSerialPort::Parity INITIAL_PARITY
Definition: RTUClientConfig.hpp:25
cutehmi::MPtr< Members >
cutehmi::modbus::RTUClient
Modbus TCP client.
Definition: RTUClient.hpp:15
cutehmi::modbus::internal::RTUClientConfig
Definition: RTUClientConfig.hpp:16
QObject
cutehmi::modbus::internal::RTUClientConfig::MIN_SLAVE_ADDRESS
static constexpr int MIN_SLAVE_ADDRESS
Definition: RTUClientConfig.hpp:22
cutehmi
QString
cutehmi::modbus::AbstractClient
Abstract client.
Definition: AbstractClient.hpp:18
cutehmi::modbus::internal::RTUClientConfig::INITIAL_DATA_BITS
static constexpr QSerialPort::DataBits INITIAL_DATA_BITS
Definition: RTUClientConfig.hpp:27
cutehmi::modbus::internal::QtRTUClientBackend
Modbus RTU client backend based on Qt Serial Bus.
Definition: QtRTUClientBackend.hpp:14