1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_ABSTRACTDEVICE_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_ABSTRACTDEVICE_HPP
4#include "internal/common.hpp"
5#include "internal/RegisterTraits.hpp"
6#include "InputRegister.hpp"
7#include "internal/HoldingRegister.hpp"
8#include "internal/InputRegister.hpp"
9#include "DiscreteInput.hpp"
12#include <cutehmi/InplaceError.hpp>
13#include <cutehmi/services/Serviceable.hpp>
19#include <QQmlListProperty>
41 QML_UNCREATABLE(
"AbstractDevice is an abstract class")
43 friend class test_AbstractDevice;
44 friend class test_AbstractServer;
45 friend class internal::IterableTasks;
87 DIAGNOSTICS_RETURN_QUERY_DATA = 0x00,
88 DIAGNOSTICS_RESTART_COMM_OPTION = 0x01,
89 DIAGNOSTICS_RETURN_DIAGNOSTICS_REGISTER = 0x02,
90 DIAGNOSTICS_CHANGE_ASCII_INPUT_DELIMITER = 0x03,
91 DIAGNOSTICS_FORCE_LISTEN_ONLY_MODE = 0x04,
92 DIAGNOSTICS_CLEAR_COUNTERS_AND_DIAGNOSTICS_REGISTER = 0x0A,
93 DIAGNOSTICS_RETURN_BUS_MESSAGE_COUNT = 0x0B,
94 DIAGNOSTICS_RETURN_BUS_COMM_ERROR_COUNT = 0x0C,
95 DIAGNOSTICS_RETURN_BUS_EXCEPTION_ERROR_COUNT = 0x0D,
96 DIAGNOSTICS_RETURN_SLAVE_MESSAGE_COUNT = 0x0E,
97 DIAGNOSTICS_RETURN_SLAVE_NO_RESPONSE_COUNT = 0x0F,
98 DIAGNOSTICS_RETURN_SLAVE_NAK_COUNT = 0x10,
99 DIAGNOSTICS_RETURN_SLAVE_BUSY_COUNT = 0x11,
100 DIAGNOSTICS_RETURN_BUS_CHARACTER_OVERRUN_COUNT = 0x12,
101 DIAGNOSTICS_RETURN_IOP_OVERRUN_COUNT = 0x13,
102 DIAGNOSTICS_CLEAR_OVERRUN_COUNTER_AND_FLAG = 0x14,
103 DIAGNOSTICS_GET_CLEAR_MODBUS_PLUS_STATISTICS = 0x15
105 Q_ENUM(DiagnosticsSubfunction)
126 static constexpr
int MAX_READ_TCP_COILS = 1976;
131 static constexpr
int MAX_READ_RTU_COILS = 2008;
136 static constexpr
int MAX_WRITE_TCP_COILS = 1944;
141 static constexpr
int MAX_WRITE_RTU_COILS = 1976;
146 static constexpr
int MAX_READ_TCP_DISCRETE_INPUTS = 1976;
151 static constexpr
int MAX_READ_RTU_DISCRETE_INPUTS = 2008;
156 static constexpr
int MAX_READ_TCP_HOLDING_REGISTERS = 123;
161 static constexpr
int MAX_READ_RTU_HOLDING_REGISTERS = 125;
166 static constexpr
int MAX_WRITE_TCP_HOLDING_REGISTERS = 123;
171 static constexpr
int MAX_WRITE_RTU_HOLDING_REGISTERS = 125;
176 static constexpr
int MAX_READ_TCP_INPUT_REGISTERS = 123;
181 static constexpr
int MAX_READ_RTU_INPUT_REGISTERS = 125;
184 static constexpr quint16 MIN_ADDRESS = 0;
185 static constexpr quint16 MAX_ADDRESS = 65535;
187 static constexpr
int INITIAL_MAX_READ_COILS = 16;
188 static constexpr
int INITIAL_MAX_WRITE_COILS = 16;
189 static constexpr
int INITIAL_MAX_READ_DISCRETE_INPUTS = 16;
190 static constexpr
int INITIAL_MAX_WRITE_DISCRETE_INPUTS = 16;
191 static constexpr
int INITIAL_MAX_READ_HOLDING_REGISTERS = 16;
192 static constexpr
int INITIAL_MAX_WRITE_HOLDING_REGISTERS = 16;
193 static constexpr
int INITIAL_MAX_READ_INPUT_REGISTERS = 16;
194 static constexpr
int INITIAL_MAX_WRITE_INPUT_REGISTERS = 16;
195 static constexpr
int INITIAL_MAX_REQUESTS = 1000;
196 static constexpr
State INITIAL_STATE = CLOSED;
197 static constexpr
bool INITIAL_READY = false;
199 Q_PROPERTY(
State state READ state NOTIFY stateChanged)
201 Q_PROPERTY(
bool ready READ ready NOTIFY readyChanged)
203 Q_PROPERTY(
int maxReadCoils READ maxReadCoils WRITE setMaxReadCoils NOTIFY maxReadCoilsChanged)
205 Q_PROPERTY(
int maxWriteCoils READ maxWriteCoils WRITE setMaxWriteCoils NOTIFY maxWriteCoilsChanged)
207 Q_PROPERTY(
int maxReadDiscreteInputs READ maxReadDiscreteInputs WRITE setMaxReadDiscreteInputs NOTIFY maxReadDiscreteInputsChanged)
209 Q_PROPERTY(
int maxWriteDiscreteInputs READ maxWriteDiscreteInputs WRITE setMaxWriteDiscreteInputs NOTIFY maxWriteDiscreteInputsChanged)
211 Q_PROPERTY(
int maxReadHoldingRegisters READ maxReadHoldingRegisters WRITE setMaxReadHoldingRegisters NOTIFY maxReadHoldingRegistersChanged)
213 Q_PROPERTY(
int maxWriteHoldingRegisters READ maxWriteHoldingRegisters WRITE setMaxWriteHoldingRegisters NOTIFY maxWriteHoldingRegistersChanged)
215 Q_PROPERTY(
int maxReadInputRegisters READ maxReadInputRegisters WRITE setMaxReadInputRegisters NOTIFY maxReadInputRegistersChanged)
217 Q_PROPERTY(
int maxWriteInputRegisters READ maxWriteInputRegisters WRITE setMaxWriteInputRegisters NOTIFY maxWriteInputRegistersChanged)
219 Q_PROPERTY(
int maxRequests READ maxRequests WRITE setMaxRequests NOTIFY maxRequestsChanged)
229 int maxReadCoils() const;
231 void setMaxReadCoils(
int maxReadCoils);
233 int maxWriteCoils() const;
235 void setMaxWriteCoils(
int maxWriteCoils);
237 int maxReadDiscreteInputs() const;
239 void setMaxReadDiscreteInputs(
int maxReadDiscreteInputs);
241 int maxWriteDiscreteInputs() const;
243 void setMaxWriteDiscreteInputs(
int maxWriteDiscreteInputs);
245 int maxReadHoldingRegisters() const;
247 void setMaxReadHoldingRegisters(
int maxReadHoldingRegisters);
249 int maxWriteHoldingRegisters() const;
251 void setMaxWriteHoldingRegisters(
int maxWriteHoldingRegisters);
253 int maxReadInputRegisters() const;
255 void setMaxReadInputRegisters(
int maxReadInputRegisters);
257 int maxWriteInputRegisters() const;
259 void setMaxWriteInputRegisters(
int maxWriteInputRegisters);
261 int maxRequests() const;
263 void setMaxRequests(
int maxRequests);
265 Coil * coilAt(quint16 address);
283 Q_INVOKABLE
void requestReadCoils(quint16 address, quint16 amount = 1,
QUuid * requestId =
nullptr);
292 Q_INVOKABLE
void requestWriteCoil(quint16 address,
bool value,
QUuid * requestId =
nullptr);
302 Q_INVOKABLE
void requestWriteMultipleCoils(quint16 address,
QJsonArray values,
QUuid * requestId =
nullptr);
314 Q_INVOKABLE
void requestReadDiscreteInputs(quint16 address, quint16 amount = 1,
QUuid * requestId =
nullptr);
324 Q_INVOKABLE
void requestWriteDiscreteInput(quint16 address,
bool value,
QUuid * requestId =
nullptr);
334 Q_INVOKABLE
void requestWriteMultipleDiscreteInputs(quint16 address,
QJsonArray values,
QUuid * requestId =
nullptr);
347 Q_INVOKABLE
void requestReadHoldingRegisters(quint16 address, quint16 amount = 1,
QUuid * requestId =
nullptr);
357 Q_INVOKABLE
void requestWriteHoldingRegister(quint16 address, quint16 value,
QUuid * requestId =
nullptr);
367 Q_INVOKABLE
void requestWriteMultipleHoldingRegisters(quint16 address,
QJsonArray values,
QUuid * requestId =
nullptr);
380 Q_INVOKABLE
void requestReadInputRegisters(quint16 address, quint16 amount = 1,
QUuid * requestId =
nullptr);
390 Q_INVOKABLE
void requestWriteInputRegister(quint16 address, quint16 value,
QUuid * requestId =
nullptr);
400 Q_INVOKABLE
void requestWriteMultipleInputRegisters(quint16 address,
QJsonArray values,
QUuid * requestId =
nullptr);
417 Q_INVOKABLE
void requestReadExceptionStatus(
QUuid * requestId =
nullptr);
424 Q_INVOKABLE
void requestFetchCommEventCounter(
QUuid * requestId =
nullptr);
431 Q_INVOKABLE
void requestFetchCommEventLog(
QUuid * requestId =
nullptr);
438 Q_INVOKABLE
void requestReportSlaveId(
QUuid * requestId =
nullptr);
450 Q_INVOKABLE
void requestMaskWriteHoldingRegister(quint16 address, quint16 andMask, quint16 orMask,
QUuid * requestId =
nullptr);
462 Q_INVOKABLE
void requestReadWriteMultipleHoldingRegisters(quint16 readAddress, quint16 amount, quint16 writeAddress,
QJsonArray values,
QUuid * requestId =
nullptr);
471 Q_INVOKABLE
void requestReadFIFOQueue(quint16 address,
QUuid * requestId =
nullptr);
482 Q_INVOKABLE
QJsonObject readFileRecordSubrequest(quint16 file, quint16 address, quint16 amount);
494 Q_INVOKABLE
void requestReadFileRecord(
QJsonArray subrequests,
QUuid * requestId =
nullptr);
517 Q_INVOKABLE
void requestWriteFileRecord(
QJsonArray subrequests,
QUuid * requestId =
nullptr);
536 virtual
void open() = 0;
538 virtual
void close() = 0;
547 void maxReadCoilsChanged();
549 void maxWriteCoilsChanged();
551 void maxReadDiscreteInputsChanged();
553 void maxWriteDiscreteInputsChanged();
555 void maxReadHoldingRegistersChanged();
557 void maxWriteHoldingRegistersChanged();
559 void maxReadInputRegistersChanged();
561 void maxWriteInputRegistersChanged();
563 void maxRequestsChanged();
625 void setReady(
bool ready);
630 Q_SIGNAL
void broke();
632 Q_SIGNAL
void stopped();
634 Q_SIGNAL
void started();
639 static
void ValidatePayloadAddressKey(const
QJsonObject & json, const
QString & key = "address");
641 static
void ValidatePayloadAmountKey(const
QJsonObject & json,
int max);
643 static
void ValidatePayloadValueKeyInt(const
QJsonObject & json);
645 static
void ValidatetPayloadValueKeyBool(const
QJsonObject & json);
647 static
void ValidatePayloadReadFileRecordSubrequestsKey(const
QJsonObject & json);
649 static
void ValidatePayloadWriteFileRecordSubrequestsKey(const
QJsonObject & json);
663 static
void ValidateReadFileRecordSubresponsesKey(const
QJsonObject & json, const
QString & path = "");
665 static
void ValidateWriteFileRecordSubresponsesKey(const
QJsonObject & json, const
QString & path = "");
677 int maxReadDiscreteInputs;
678 int maxWriteDiscreteInputs;
679 int maxReadHoldingRegisters;
680 int maxWriteHoldingRegisters;
681 int maxReadInputRegisters;
682 int maxWriteInputRegisters;
691 state(INITIAL_STATE),
692 ready(INITIAL_READY),
693 maxReadCoils(INITIAL_MAX_READ_COILS),
694 maxWriteCoils(INITIAL_MAX_WRITE_COILS),
695 maxReadDiscreteInputs(INITIAL_MAX_READ_DISCRETE_INPUTS),
696 maxWriteDiscreteInputs(INITIAL_MAX_WRITE_DISCRETE_INPUTS),
697 maxReadHoldingRegisters(INITIAL_MAX_READ_HOLDING_REGISTERS),
698 maxWriteHoldingRegisters(INITIAL_MAX_WRITE_HOLDING_REGISTERS),
699 maxReadInputRegisters(INITIAL_MAX_READ_INPUT_REGISTERS),
700 maxWriteInputRegisters(INITIAL_MAX_WRITE_INPUT_REGISTERS),
701 maxRequests(INITIAL_MAX_REQUESTS)
Abstract Modbus device.
Definition: AbstractDevice.hpp:38
internal::RegisterTraits< internal::InputRegister >::Container InputRegisterDataContainer
Definition: AbstractDevice.hpp:571
internal::RegisterTraits< internal::HoldingRegister >::Container HoldingRegisterDataContainer
Definition: AbstractDevice.hpp:570
DiagnosticsSubfunction
Definition: AbstractDevice.hpp:86
internal::RegisterTraits< internal::Coil >::Container CoilDataContainer
Definition: AbstractDevice.hpp:568
internal::RegisterTraits< internal::DiscreteInput >::Container DiscreteInputDataContainer
Definition: AbstractDevice.hpp:569
Function
Definition: AbstractDevice.hpp:56
@ FUNCTION_WRITE_INPUT_REGISTER
Definition: AbstractDevice.hpp:80
@ FUNCTION_WRITE_MULTIPLE_DISCRETE_INPUTS
Definition: AbstractDevice.hpp:79
@ FUNCTION_WRITE_MULTIPLE_INPUT_REGISTERS
Definition: AbstractDevice.hpp:81
@ FUNCTION_WRITE_DISCRETE_INPUT
Definition: AbstractDevice.hpp:78
State
Definition: AbstractDevice.hpp:48
@ OPENED
Definition: AbstractDevice.hpp:50
@ CLOSING
Definition: AbstractDevice.hpp:51
@ OPENING
Definition: AbstractDevice.hpp:49
Cached properties of 16 bit register.
Definition: Register16.hpp:15
Cached properties of 1 bit register.
Definition: Register1.hpp:15
Definition: IterableTasks.hpp:18