CuteHMI - Modbus (CuteHMI.Modbus.4)
RTUServer.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_RTUSERVER_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_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#include <QQmlEngine>
13
14namespace cutehmi {
15namespace modbus {
16
17class CUTEHMI_MODBUS_API RTUServer:
19{
20 Q_OBJECT
21 QML_NAMED_ELEMENT(RTUServer)
22
23 public:
24 static constexpr int MIN_SLAVE_ADDRESS = internal::RTUServerConfig::MIN_SLAVE_ADDRESS;
25 static constexpr int MAX_SLAVE_ADDRESS = internal::RTUServerConfig::MAX_SLAVE_ADDRESS;
26 static const char * INITIAL_PORT;
27 static constexpr QSerialPort::Parity INITIAL_PARITY = internal::RTUServerConfig::INITIAL_PARITY;
28 static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE = internal::RTUServerConfig::INITIAL_BAUD_RATE;
29 static constexpr QSerialPort::DataBits INITIAL_DATA_BITS = internal::RTUServerConfig::INITIAL_DATA_BITS;
30 static constexpr QSerialPort::StopBits INITIAL_STOP_BITS = internal::RTUServerConfig::INITIAL_STOP_BITS;
31 static constexpr int INITIAL_SLAVE_ADDRESS = internal::RTUServerConfig::INITIAL_SLAVE_ADDRESS;
32 static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MIN;
33 static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_COILS_ADDRESS_RANGE_MAX;
34 static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN;
35 static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX;
36 static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN;
37 static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX;
38 static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN;
39 static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = internal::RTUServerConfig::INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX;
40
41 Q_PROPERTY(QString port READ port WRITE setPort NOTIFY portChanged)
42 Q_PROPERTY(QSerialPort::Parity parity READ parity WRITE setParity NOTIFY parityChanged)
43 Q_PROPERTY(QSerialPort::BaudRate baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
44 Q_PROPERTY(QSerialPort::DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
45 Q_PROPERTY(QSerialPort::StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)
46 Q_PROPERTY(int slaveAddress READ slaveAddress WRITE setSlaveAddress NOTIFY slaveAddressChanged)
47
48 RTUServer(QObject * parent = nullptr);
49
50 ~RTUServer() override;
51
52 QString port() const;
53
54 void setPort(const QString & port);
55
56 QSerialPort::Parity parity() const;
57
58 void setParity(QSerialPort::Parity);
59
60 QSerialPort::BaudRate baudRate() const;
61
62 void setBaudRate(QSerialPort::BaudRate baudRate);
63
64 QSerialPort::DataBits dataBits() const;
65
66 void setDataBits(QSerialPort::DataBits dataBits);
67
68 QSerialPort::StopBits stopBits() const;
69
70 void setStopBits(QSerialPort::StopBits stopBits);
71
72 int slaveAddress() const;
73
74 void setSlaveAddress(int slaveAddress);
75
76 void setBusy(bool busy) override;
77
78 public slots:
79 void open() override;
80
81 void close() override;
82
83 signals:
85
87
89
91
93
95
96 private:
97 struct Members
98 {
101 QThread thread;
102
107 backend(& config, coilData, discreteInputData, holdingRegisterData, inputRegisterData)
108 {
109 }
110 };
111
113};
114
115}
116}
117
118#endif
119
120//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
121//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
122//(c)C: This file is a part of CuteHMI.
123//(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.
124//(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.
125//(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/>.
126//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
127//(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:
128//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
129//(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 server.
Definition: AbstractServer.hpp:19
Definition: RTUServer.hpp:19
static const char * INITIAL_PORT
Definition: RTUServer.hpp:26
TCP server backend.
Definition: QtRTUServerBackend.hpp:17
RegisterTraits< DiscreteInput >::Container DiscreteInputDataContainer
Definition: QtRTUServer.hpp:32
RegisterTraits< InputRegister >::Container InputRegisterDataContainer
Definition: QtRTUServer.hpp:34
RegisterTraits< HoldingRegister >::Container HoldingRegisterDataContainer
Definition: QtRTUServer.hpp:33
RegisterTraits< Coil >::Container CoilDataContainer
Definition: QtRTUServer.hpp:31
Definition: RTUServerConfig.hpp:17
static constexpr int MAX_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:24
static constexpr QSerialPort::Parity INITIAL_PARITY
Definition: RTUServerConfig.hpp:26
static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:38
static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:31
static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:33
static constexpr int INITIAL_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:30
static constexpr QSerialPort::DataBits INITIAL_DATA_BITS
Definition: RTUServerConfig.hpp:28
static constexpr QSerialPort::StopBits INITIAL_STOP_BITS
Definition: RTUServerConfig.hpp:29
static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE
Definition: RTUServerConfig.hpp:27
static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:35
static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:36
static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:34
static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX
Definition: RTUServerConfig.hpp:32
static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN
Definition: RTUServerConfig.hpp:37
static constexpr int MIN_SLAVE_ADDRESS
Definition: RTUServerConfig.hpp:23