CuteHMI - Modbus (CuteHMI.Modbus.4)
TCPClient.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_TCPCLIENT_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_TCPCLIENT_HPP
3
4#include "AbstractClient.hpp"
5#include "internal/QtTCPClientBackend.hpp"
6
7#include <QThread>
8#include <QQmlEngine>
9
10namespace cutehmi {
11namespace modbus {
12
16class CUTEHMI_MODBUS_API TCPClient:
18{
19 Q_OBJECT
20 QML_NAMED_ELEMENT(TCPClient)
21
22 public:
23 static constexpr int MIN_SLAVE_ADDRESS = internal::TCPClientConfig::MIN_SLAVE_ADDRESS;
24 static constexpr int MAX_SLAVE_ADDRESS = internal::TCPClientConfig::MAX_SLAVE_ADDRESS;
25 static const char * INITIAL_HOST;
26 static constexpr int INITIAL_PORT = internal::TCPClientConfig::INITIAL_PORT;
27 static constexpr int INITIAL_SLAVE_ADDRESS = internal::TCPClientConfig::INITIAL_SLAVE_ADDRESS;
28 static constexpr int INITIAL_TIMEOUT = internal::TCPClientConfig::INITIAL_TIMEOUT;
29
30 Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
31 Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
32 Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
33
34 TCPClient(QObject * parent = nullptr);
35
36 ~TCPClient() override;
37
38 QString host() const;
39
40 void setHost(const QString & host);
41
42 int port() const;
43
44 void setPort(int port);
45
46 int slaveAddress() const;
47
48 void setSlaveAddress(int slaveAddress);
49
50 int timeout() const override;
51
52 void setTimeout(int timeout) override;
53
54 public slots:
55 void open() override;
56
57 void close() override;
58
59 signals:
61
63
65
66 private:
67 struct Members {
70 QThread thread;
71
72 Members():
73 backend(& config)
74 {
75 }
76 };
77
79};
80
81}
82}
83
84#endif
85
86//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
87//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
88//(c)C: This file is a part of CuteHMI.
89//(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.
90//(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.
91//(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/>.
92//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
93//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
94//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
95//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Abstract client.
Definition: AbstractClient.hpp:32
Modbus TCP client.
Definition: TCPClient.hpp:18
static const char * INITIAL_HOST
Definition: TCPClient.hpp:25
Modbus TCP client backend based on Qt Serial Bus.
Definition: QtTCPClientBackend.hpp:18
Definition: TCPClientConfig.hpp:16
static constexpr int MIN_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:20
static constexpr int MAX_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:21
static constexpr int INITIAL_TIMEOUT
Definition: TCPClientConfig.hpp:25
static constexpr int INITIAL_PORT
Definition: TCPClientConfig.hpp:23
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: TCPClientConfig.hpp:24