| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qmodbusdataunit.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | \class QModbusDataUnit |
| 10 | \inmodule QtSerialBus |
| 11 | \since 5.8 |
| 12 | |
| 13 | \brief QModbusDataUnit is a container class representing single bit and |
| 14 | \c 16 bit word entries in the Modbus register. |
| 15 | |
| 16 | \l QModbusDataUnit can be used for read and write operations. The entries |
| 17 | are addressed via \l startAddress() and the \l valueCount() number of |
| 18 | contiguous entries. \l registerType() determines which register is used for |
| 19 | the operations. Note that some registers are read-only registers. |
| 20 | |
| 21 | The actual \l values() are either single bit or \c 16 bit based. |
| 22 | \l QModbusDataUnit::DiscreteInputs and \l QModbusDataUnit::Coils |
| 23 | only accept single bits. Therefore \c 0 is interpreted as \c 0 and anything |
| 24 | else \c 1. |
| 25 | */ |
| 26 | |
| 27 | /*! |
| 28 | \enum QModbusDataUnit::RegisterType |
| 29 | |
| 30 | This enum describes all supported register types. |
| 31 | |
| 32 | \value Invalid Set by the default constructor, do not use. |
| 33 | \value DiscreteInputs This type of data can be provided by an I/O |
| 34 | system. |
| 35 | \value Coils This type of data can be alterable by an |
| 36 | application program. |
| 37 | \value InputRegisters This type of data can be provided by an I/O |
| 38 | system. |
| 39 | \value HoldingRegisters This type of data can be alterable by an |
| 40 | application program. |
| 41 | */ |
| 42 | |
| 43 | /*! |
| 44 | \fn QModbusDataUnit::QModbusDataUnit() |
| 45 | |
| 46 | Constructs an empty, invalid QModbusDataUnit. Start address is set to \c -1 |
| 47 | and the \l registerType is set to \l QModbusDataUnit::Invalid. |
| 48 | */ |
| 49 | |
| 50 | /*! |
| 51 | \fn QModbusDataUnit::QModbusDataUnit(RegisterType type) |
| 52 | |
| 53 | Constructs a unit of data for register \a type. Start address is set to |
| 54 | \c 0, data range and data values are empty. |
| 55 | */ |
| 56 | |
| 57 | /*! |
| 58 | \fn QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, |
| 59 | quint16 size) |
| 60 | |
| 61 | Constructs a unit of data for register\a type. Start address of the data is |
| 62 | set to \a address and the size of the unit to \a size. |
| 63 | The entries of \l values() are initialized with \c 0. |
| 64 | */ |
| 65 | |
| 66 | /*! |
| 67 | \fn QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, |
| 68 | const QList<quint16> &data) |
| 69 | |
| 70 | Constructs a unit of data for register\a type. Start address of the data is |
| 71 | set to \a address and the unit's values to \a data. |
| 72 | The value count is implied by the \a data size. |
| 73 | */ |
| 74 | |
| 75 | /*! |
| 76 | \fn void QModbusDataUnit::setRegisterType(QModbusDataUnit::RegisterType type) |
| 77 | |
| 78 | Sets the register \a type. |
| 79 | |
| 80 | \sa registerType(), QModbusDataUnit::RegisterType |
| 81 | */ |
| 82 | |
| 83 | /*! |
| 84 | \fn QModbusDataUnit::RegisterType QModbusDataUnit::registerType() const |
| 85 | |
| 86 | Returns the type of the register. |
| 87 | |
| 88 | \sa setRegisterType(), QModbusDataUnit::RegisterType |
| 89 | */ |
| 90 | |
| 91 | /*! |
| 92 | \fn void QModbusDataUnit::setStartAddress(int address) |
| 93 | |
| 94 | Sets the start \a address of the data unit. |
| 95 | |
| 96 | \sa startAddress() |
| 97 | */ |
| 98 | |
| 99 | /*! |
| 100 | \fn int QModbusDataUnit::startAddress() const |
| 101 | |
| 102 | Returns the start address of data unit in the register. |
| 103 | |
| 104 | \sa setStartAddress() |
| 105 | */ |
| 106 | |
| 107 | /*! |
| 108 | \fn void QModbusDataUnit::setValues(const QList<quint16> &values) |
| 109 | |
| 110 | Sets the \a values of the data unit. \l QModbusDataUnit::DiscreteInputs |
| 111 | and \l QModbusDataUnit::Coils tables only accept single bit value, so \c 0 |
| 112 | is interpreted as \c 0 and anything else as \c 1. |
| 113 | |
| 114 | \sa values() |
| 115 | */ |
| 116 | |
| 117 | /*! |
| 118 | \fn QList<quint16> QModbusDataUnit::values() const |
| 119 | |
| 120 | Returns the data in the data unit. \l QModbusDataUnit::DiscreteInputs |
| 121 | and \l QModbusDataUnit::Coils tables only accept single bit value, so \c 0 |
| 122 | is interpreted as \c 0 and anything else as \c 1. |
| 123 | |
| 124 | \sa setValues() |
| 125 | */ |
| 126 | |
| 127 | /*! |
| 128 | \fn qsizetype QModbusDataUnit::valueCount() const |
| 129 | |
| 130 | Returns the size of the requested register's data block or the size of data |
| 131 | read from the device. |
| 132 | |
| 133 | This function may not always return a count that equals \l values() size. |
| 134 | Since this class is used to request data from the remote data register, the |
| 135 | \l valueCount() can be used to indicate the size of the requested register's |
| 136 | data block. Once the request has been processed, the \l valueCount() is |
| 137 | equal to the size of \l values(). |
| 138 | |
| 139 | \sa setValueCount() |
| 140 | */ |
| 141 | |
| 142 | /*! |
| 143 | \fn void QModbusDataUnit::setValueCount(qsizetype newCount) |
| 144 | |
| 145 | Sets the size of the requested register's data block to \a newCount. |
| 146 | |
| 147 | This may be different from \l values() size as this function is used |
| 148 | to indicated the size of a data request. Only once the data request |
| 149 | has been processed \l valueCount() is equal to the size of \l values(). |
| 150 | */ |
| 151 | |
| 152 | /*! |
| 153 | \fn void QModbusDataUnit::setValue(qsizetype index, quint16 value) |
| 154 | |
| 155 | Sets the register at position \a index to \a value. |
| 156 | */ |
| 157 | |
| 158 | /*! |
| 159 | \fn quint16 QModbusDataUnit::value(qsizetype index) const |
| 160 | |
| 161 | Return the value at position \a index. |
| 162 | */ |
| 163 | |
| 164 | /*! |
| 165 | \fn bool QModbusDataUnit::isValid() const |
| 166 | |
| 167 | Returns \c true if the \c QModbusDataUnit is valid; otherwise \c false. |
| 168 | A \c QModbusDataUnit is considered valid if the \l registerType() is not |
| 169 | \l QModbusDataUnit::Invalid and the \l startAddress() is greater than or |
| 170 | equal to \c 0. |
| 171 | */ |
| 172 | |
| 173 | /*! |
| 174 | \typedef QModbusDataUnitMap |
| 175 | \relates QModbusDataUnit |
| 176 | \since 5.8 |
| 177 | |
| 178 | Synonym for QMap<QModbusDataUnit::RegisterType, QModbusDataUnit>. |
| 179 | */ |
| 180 | |
| 181 | QT_END_NAMESPACE |
| 182 | |