| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtSerialBus module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #include "qmodbusdataunit.h" | 
| 38 |  | 
| 39 | QT_BEGIN_NAMESPACE | 
| 40 |  | 
| 41 | /*! | 
| 42 |     \class QModbusDataUnit | 
| 43 |     \inmodule QtSerialBus | 
| 44 |     \since 5.8 | 
| 45 |  | 
| 46 |     \brief QModbusDataUnit is a container class representing single bit and | 
| 47 |     \c 16 bit word entries in the Modbus register. | 
| 48 |  | 
| 49 |     \l QModbusDataUnit can be used for read and write operations. The entries | 
| 50 |     are addressed via \l startAddress() and the \l valueCount() number of | 
| 51 |     contiguous entries. \l registerType() determines which register is used for | 
| 52 |     the operations. Note that some registers are read-only registers. | 
| 53 |  | 
| 54 |     The actual \l values() are either single bit or \c 16 bit based. | 
| 55 |     \l QModbusDataUnit::DiscreteInputs and \l QModbusDataUnit::Coils | 
| 56 |     only accept single bits. Therefore \c 0 is interpreted as \c 0 and anything | 
| 57 |     else \c 1. | 
| 58 | */ | 
| 59 |  | 
| 60 | /*! | 
| 61 |     \enum QModbusDataUnit::RegisterType | 
| 62 |  | 
| 63 |     This enum describes all supported register types. | 
| 64 |  | 
| 65 |     \value Invalid              Set by the default constructor, do not use. | 
| 66 |     \value DiscreteInputs       This type of data can be provided by an I/O | 
| 67 |                                 system. | 
| 68 |     \value Coils                This type of data can be alterable by an | 
| 69 |                                 application program. | 
| 70 |     \value InputRegisters       This type of data can be provided by an I/O | 
| 71 |                                 system. | 
| 72 |     \value HoldingRegisters     This type of data can be alterable by an | 
| 73 |                                 application program. | 
| 74 | */ | 
| 75 |  | 
| 76 | /*! | 
| 77 |     \fn QModbusDataUnit::QModbusDataUnit() | 
| 78 |  | 
| 79 |     Constructs an empty, invalid QModbusDataUnit. Start address is set to \c -1 | 
| 80 |     and the \l registerType is set to \l QModbusDataUnit::Invalid. | 
| 81 | */ | 
| 82 |  | 
| 83 | /*! | 
| 84 |     \fn QModbusDataUnit::QModbusDataUnit(RegisterType type) | 
| 85 |  | 
| 86 |     Constructs a unit of data for register \a type. Start address is set to | 
| 87 |     \c 0, data range and data values are empty. | 
| 88 | */ | 
| 89 |  | 
| 90 | /*! | 
| 91 |     \fn QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, | 
| 92 |                                          quint16 size) | 
| 93 |  | 
| 94 |     Constructs a unit of data for register\a type. Start address of the data is | 
| 95 |     set to \a address and the size of the unit to \a size. | 
| 96 |     The entries of \l values() are initialized with \c 0. | 
| 97 | */ | 
| 98 |  | 
| 99 | /*! | 
| 100 |     \fn QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, | 
| 101 |                                          const QVector<quint16> &data) | 
| 102 |  | 
| 103 |     Constructs a unit of data for register\a type. Start address of the data is | 
| 104 |     set to \a address and the unit's values to \a data. | 
| 105 |     The value count is implied by the \a data size. | 
| 106 | */ | 
| 107 |  | 
| 108 | /*! | 
| 109 |     \fn void QModbusDataUnit::setRegisterType(QModbusDataUnit::RegisterType type) | 
| 110 |  | 
| 111 |     Sets the register \a type. | 
| 112 |  | 
| 113 |     \sa registerType(), QModbusDataUnit::RegisterType | 
| 114 | */ | 
| 115 |  | 
| 116 | /*! | 
| 117 |     \fn QModbusDataUnit::RegisterType QModbusDataUnit::registerType() const | 
| 118 |  | 
| 119 |     Returns the type of the register. | 
| 120 |  | 
| 121 |     \sa setRegisterType(), QModbusDataUnit::RegisterType | 
| 122 | */ | 
| 123 |  | 
| 124 | /*! | 
| 125 |     \fn void QModbusDataUnit::setStartAddress(int address) | 
| 126 |  | 
| 127 |     Sets the start \a address of the data unit. | 
| 128 |  | 
| 129 |     \sa startAddress() | 
| 130 | */ | 
| 131 |  | 
| 132 | /*! | 
| 133 |     \fn int QModbusDataUnit::startAddress() const | 
| 134 |  | 
| 135 |     Returns the start address of data unit in the register. | 
| 136 |  | 
| 137 |     \sa setStartAddress() | 
| 138 | */ | 
| 139 |  | 
| 140 | /*! | 
| 141 |     \fn void QModbusDataUnit::setValues(const QVector<quint16> &values) | 
| 142 |  | 
| 143 |     Sets the \a values of the data unit. \l QModbusDataUnit::DiscreteInputs | 
| 144 |     and \l QModbusDataUnit::Coils tables only accept single bit value, so \c 0 | 
| 145 |     is interpreted as \c 0 and anything else as \c 1. | 
| 146 |  | 
| 147 |     \sa values() | 
| 148 | */ | 
| 149 |  | 
| 150 | /*! | 
| 151 |     \fn QVector<quint16> QModbusDataUnit::values() const | 
| 152 |  | 
| 153 |     Returns the data in the data unit. \l QModbusDataUnit::DiscreteInputs | 
| 154 |     and \l QModbusDataUnit::Coils tables only accept single bit value, so \c 0 | 
| 155 |     is interpreted as \c 0 and anything else as \c 1. | 
| 156 |  | 
| 157 |     \sa setValues() | 
| 158 | */ | 
| 159 |  | 
| 160 | /*! | 
| 161 |     \fn uint QModbusDataUnit::valueCount() const | 
| 162 |  | 
| 163 |     Returns the size of the requested register's data block or the size of data | 
| 164 |     read from the device. | 
| 165 |  | 
| 166 |     This function may not always return a count that equals \l values() size. | 
| 167 |     Since this class is used to request data from the remote data register, the | 
| 168 |     \l valueCount() can be used to indicate the size of the requested register's | 
| 169 |     data block. Once the request has been processed, the \l valueCount() is | 
| 170 |     equal to the size of \l values(). | 
| 171 |  | 
| 172 |     \sa setValueCount() | 
| 173 | */ | 
| 174 |  | 
| 175 | /*! | 
| 176 |     \fn void QModbusDataUnit::setValueCount(uint newCount) | 
| 177 |  | 
| 178 |     Sets the size of the requested register's data block to \a newCount. | 
| 179 |  | 
| 180 |     This may be different from \l values() size as this function is used | 
| 181 |     to indicated the size of a data request. Only once the data request | 
| 182 |     has been processed \l valueCount() is equal to the size of \l values(). | 
| 183 | */ | 
| 184 |  | 
| 185 | /*! | 
| 186 |     \fn void QModbusDataUnit::setValue(int index, quint16 value) | 
| 187 |  | 
| 188 |     Sets the register at position \a index to \a value. | 
| 189 | */ | 
| 190 |  | 
| 191 | /*! | 
| 192 |     \fn quint16 QModbusDataUnit::value(int index) const | 
| 193 |  | 
| 194 |     Return the value at position \a index. | 
| 195 | */ | 
| 196 |  | 
| 197 | /*! | 
| 198 |     \fn bool QModbusDataUnit::isValid() const | 
| 199 |  | 
| 200 |     Returns \c true if the \c QModbusDataUnit is valid; otherwise \c false. | 
| 201 |     A \c QModbusDataUnit is considered valid if the \l registerType() is not | 
| 202 |     \l QModbusDataUnit::Invalid and the \l startAddress() is greater than or | 
| 203 |     equal to \c 0. | 
| 204 | */ | 
| 205 |  | 
| 206 | /*! | 
| 207 |     \typedef QModbusDataUnitMap | 
| 208 |     \relates QModbusDataUnit | 
| 209 |     \since 5.8 | 
| 210 |  | 
| 211 |     Synonym for QMap<QModbusDataUnit::RegisterType, QModbusDataUnit>. | 
| 212 | */ | 
| 213 |  | 
| 214 | QT_END_NAMESPACE | 
| 215 |  |