diff --git a/Servo/include/ModbusMaster.h b/Servo/include/ModbusMaster.h index edde8fe..ebb6349 100644 --- a/Servo/include/ModbusMaster.h +++ b/Servo/include/ModbusMaster.h @@ -41,6 +41,7 @@ public slots: QBitArray getCoil(int startAddress, quint16 readSize); QBitArray getInputCoil(int startAddress, quint16 readSize); QVector getHoldingRegister(int startAddress, quint16 readSize); + QVector getInputRegister(int startAddress, quint16 readSize); }; #endif //MODBUSMASTER_H diff --git a/Servo/include/ModbusWrapper.h b/Servo/include/ModbusWrapper.h index 553297a..791bf33 100644 --- a/Servo/include/ModbusWrapper.h +++ b/Servo/include/ModbusWrapper.h @@ -24,6 +24,7 @@ public: QBitArray getCoil(int startAddress, quint16 readSize); QBitArray getInputCoil(int startAddress, quint16 readSize); QVector getHoldingRegister(int startAddress, quint16 readSize); + QVector getInputRegister(int startAddress, quint16 readSize); signals: void connectOrder(ModbusConfig modbusConfig); @@ -32,6 +33,7 @@ signals: QBitArray getInputCoilOrder(int startAddress, quint16 readSize); QVector getHoldingRegisterOrder(int startAddress, quint16 readSize); + QVector getInputRegisterOrder(int startAddress, quint16 readSize); //uncrustify off public slots: diff --git a/Servo/src/ModbusMaster.cpp b/Servo/src/ModbusMaster.cpp index 9bdc6ce..3781d10 100644 --- a/Servo/src/ModbusMaster.cpp +++ b/Servo/src/ModbusMaster.cpp @@ -149,6 +149,31 @@ QVector ModbusMaster::getHoldingRegister(int startAddress, quint16 read } } +/*************************************************************************************************/ +QVector ModbusMaster::getInputRegister(int startAddress, quint16 readSize) +{ + try + { + readRequest(QModbusDataUnit::RegisterType::InputRegisters, startAddress, readSize); + auto unit = _modbusReplyUnit; + + QVector registerValues; + auto num = unit.valueCount(); + registerValues.resize(static_cast(num)); + + for(uint i = 0; i < unit.valueCount(); i++) + { + registerValues[static_cast(i)] = unit.value(static_cast(i)); + } + + return registerValues; + } + catch(const ServoException& ex) + { + qDebug() << ex.what(); + } +} + /*************************************************************************************************/ void ModbusMaster::readRequest(QModbusDataUnit::RegisterType registerType, int startAddress, diff --git a/Servo/src/ModbusWrapper.cpp b/Servo/src/ModbusWrapper.cpp index 1f802cc..72e0930 100644 --- a/Servo/src/ModbusWrapper.cpp +++ b/Servo/src/ModbusWrapper.cpp @@ -48,6 +48,11 @@ void ModbusWrapper::init() &_modbusMaster, &ModbusMaster::getHoldingRegister, Qt::BlockingQueuedConnection); + connect(this, + &ModbusWrapper::getInputRegisterOrder, + &_modbusMaster, + &ModbusMaster::getInputRegister, + Qt::BlockingQueuedConnection); emit initOrder(); @@ -81,6 +86,15 @@ QVector ModbusWrapper::getHoldingRegister(int startAddress, quint16 rea return result; } +/*************************************************************************************************/ +QVector ModbusWrapper::getInputRegister(int startAddress, quint16 readSize) +{ + auto result = emit getInputRegisterOrder(startAddress, readSize); + qDebug() << "getInputRegister done"; + + return result; +} + /*************************************************************************************************/ void ModbusWrapper::connectToDevice(ModbusConfig modbusConfig) { diff --git a/Test/MainWindow.cpp b/Test/MainWindow.cpp index 5b852bb..98d6972 100644 --- a/Test/MainWindow.cpp +++ b/Test/MainWindow.cpp @@ -57,8 +57,12 @@ void MainWindow::on_readButton_clicked() static_cast(numberOfEntries))); break; - //case 2: printCoilsDataFromClient(modbusWrapper.(startAddress,static_cast(numberOfEntries))); - //break; + case 2: + printRegisterDataFromClient(modbusWrapper.getInputRegister(startAddress, + static_cast( + numberOfEntries))); + break; + case 3: printRegisterDataFromClient(modbusWrapper.getHoldingRegister(startAddress, static_cast(