CuteHMI - Modbus (CuteHMI.Modbus.2)
TCPClient.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_TCPCLIENT_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_TCPCLIENT_HPP
3 
4 #include "AbstractClient.hpp"
5 #include "internal/QtTCPClientBackend.hpp"
6 
7 #include <QThread>
8 
9 namespace cutehmi {
10 namespace modbus {
11 
15 class CUTEHMI_MODBUS_API TCPClient:
16  public AbstractClient
17 {
18  Q_OBJECT
19 
20  public:
21  static constexpr int MIN_SLAVE_ADDRESS = internal::TCPClientConfig::MIN_SLAVE_ADDRESS;
22  static constexpr int MAX_SLAVE_ADDRESS = internal::TCPClientConfig::MAX_SLAVE_ADDRESS;
23  static const char * INITIAL_HOST;
24  static constexpr int INITIAL_PORT = internal::TCPClientConfig::INITIAL_PORT;
25  static constexpr int INITIAL_SLAVE_ADDRESS = internal::TCPClientConfig::INITIAL_SLAVE_ADDRESS;
26 
27  Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
28  Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
29  Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
30 
31  TCPClient(QObject * parent = nullptr);
32 
33  ~TCPClient() override;
34 
35  QString host() const;
36 
37  void setHost(const QString & host);
38 
39  int port() const;
40 
41  void setPort(int port);
42 
43  int slaveAddress() const;
44 
45  void setSlaveAddress(int slaveAddress);
46 
47  public slots:
48  void open() override;
49 
50  void close() override;
51 
52  signals:
53  void hostChanged();
54 
55  void portChanged();
56 
57  void slaveAddressChanged();
58 
59  private:
60  struct Members {
63  QThread thread;
64 
65  Members():
66  backend(& config)
67  {
68  }
69  };
70 
71  MPtr<Members> m;
72 };
73 
74 }
75 }
76 
77 #endif
78 
79 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
80 //(c)C: This file is a part of CuteHMI.
81 //(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.
82 //(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.
83 //(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/>.
QThread
cutehmi::modbus::internal::TCPClientConfig::INITIAL_PORT
static constexpr int INITIAL_PORT
Definition: TCPClientConfig.hpp:23
cutehmi::modbus::internal::QtTCPClientBackend
Modbus TCP client backend based on Qt Serial Bus.
Definition: QtTCPClientBackend.hpp:16
cutehmi::modbus::TCPClient::INITIAL_HOST
static const char * INITIAL_HOST
Definition: TCPClient.hpp:23
cutehmi::MPtr< Members >
QObject
cutehmi
QString
cutehmi::modbus::AbstractClient
Abstract client.
Definition: AbstractClient.hpp:18
cutehmi::modbus::internal::TCPClientConfig::MIN_SLAVE_ADDRESS
static constexpr int MIN_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:20
cutehmi::modbus::TCPClient
Modbus TCP client.
Definition: TCPClient.hpp:15
cutehmi::modbus::internal::TCPClientConfig
Definition: TCPClientConfig.hpp:14
cutehmi::modbus::internal::TCPClientConfig::MAX_SLAVE_ADDRESS
static constexpr int MAX_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:21
cutehmi::modbus::internal::TCPClientConfig::INITIAL_SLAVE_ADDRESS
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:24