Browse Source

Add GetInputRegister

test
nasicurious 3 years ago
parent
commit
b25a8b3240
  1. 1
      Servo/include/ModbusMaster.h
  2. 2
      Servo/include/ModbusWrapper.h
  3. 25
      Servo/src/ModbusMaster.cpp
  4. 14
      Servo/src/ModbusWrapper.cpp
  5. 8
      Test/MainWindow.cpp

1
Servo/include/ModbusMaster.h

@ -41,6 +41,7 @@ public slots:
QBitArray getCoil(int startAddress, quint16 readSize);
QBitArray getInputCoil(int startAddress, quint16 readSize);
QVector<quint16> getHoldingRegister(int startAddress, quint16 readSize);
QVector<quint16> getInputRegister(int startAddress, quint16 readSize);
};
#endif //MODBUSMASTER_H

2
Servo/include/ModbusWrapper.h

@ -24,6 +24,7 @@ public:
QBitArray getCoil(int startAddress, quint16 readSize);
QBitArray getInputCoil(int startAddress, quint16 readSize);
QVector<quint16> getHoldingRegister(int startAddress, quint16 readSize);
QVector<quint16> getInputRegister(int startAddress, quint16 readSize);
signals:
void connectOrder(ModbusConfig modbusConfig);
@ -32,6 +33,7 @@ signals:
QBitArray getInputCoilOrder(int startAddress, quint16 readSize);
QVector<quint16> getHoldingRegisterOrder(int startAddress,
quint16 readSize);
QVector<quint16> getInputRegisterOrder(int startAddress, quint16 readSize);
//uncrustify off
public slots:

25
Servo/src/ModbusMaster.cpp

@ -149,6 +149,31 @@ QVector<quint16> ModbusMaster::getHoldingRegister(int startAddress, quint16 read
}
}
/*************************************************************************************************/
QVector<quint16> ModbusMaster::getInputRegister(int startAddress, quint16 readSize)
{
try
{
readRequest(QModbusDataUnit::RegisterType::InputRegisters, startAddress, readSize);
auto unit = _modbusReplyUnit;
QVector<quint16> registerValues;
auto num = unit.valueCount();
registerValues.resize(static_cast<int>(num));
for(uint i = 0; i < unit.valueCount(); i++)
{
registerValues[static_cast<int>(i)] = unit.value(static_cast<int>(i));
}
return registerValues;
}
catch(const ServoException& ex)
{
qDebug() << ex.what();
}
}
/*************************************************************************************************/
void ModbusMaster::readRequest(QModbusDataUnit::RegisterType registerType,
int startAddress,

14
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<quint16> ModbusWrapper::getHoldingRegister(int startAddress, quint16 rea
return result;
}
/*************************************************************************************************/
QVector<quint16> ModbusWrapper::getInputRegister(int startAddress, quint16 readSize)
{
auto result = emit getInputRegisterOrder(startAddress, readSize);
qDebug() << "getInputRegister done";
return result;
}
/*************************************************************************************************/
void ModbusWrapper::connectToDevice(ModbusConfig modbusConfig)
{

8
Test/MainWindow.cpp

@ -57,8 +57,12 @@ void MainWindow::on_readButton_clicked()
static_cast<quint16>(numberOfEntries)));
break;
//case 2: printCoilsDataFromClient(modbusWrapper.(startAddress,static_cast<quint16>(numberOfEntries)));
//break;
case 2:
printRegisterDataFromClient(modbusWrapper.getInputRegister(startAddress,
static_cast<quint16>(
numberOfEntries)));
break;
case 3:
printRegisterDataFromClient(modbusWrapper.getHoldingRegister(startAddress,
static_cast<quint16>(

Loading…
Cancel
Save