|
|
@ -7,8 +7,7 @@ |
|
|
|
enum { NumColumn = 0, CoilsColumn = 1, HoldingColumn = 2, ColumnCount = 3, RowCount = 10 }; |
|
|
|
modBusMaster::modBusMaster(QObject *parent) : QObject(parent) |
|
|
|
{ |
|
|
|
m_coils.resize(2); |
|
|
|
m_holdingRegisters.resize(2); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -75,7 +74,7 @@ void modBusMaster::setSingleCoil(int startAddress,bool coilFlag) |
|
|
|
{ |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_coils.setBit(0,coilFlag); |
|
|
|
_coilFlags.setBit(0,coilFlag); |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::Coils, startAddress, 1); |
|
|
|
|
|
|
|
} |
|
|
@ -84,7 +83,7 @@ void modBusMaster::setMultipleCoil(int startAddress, quint16 writeSize, QBitArra |
|
|
|
{ |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_coils = coilFlags; |
|
|
|
_coilFlags = coilFlags; |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::Coils, startAddress, writeSize); |
|
|
|
} |
|
|
|
|
|
|
@ -92,7 +91,7 @@ void modBusMaster::setSingleRegister(int startAddress, quint16 registerValue) |
|
|
|
{ |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_holdingRegisters[0]=registerValue; |
|
|
|
_registerValues[0]=registerValue; |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::HoldingRegisters, startAddress, 1); |
|
|
|
} |
|
|
|
|
|
|
@ -100,7 +99,7 @@ void modBusMaster::setMultipleRegister(int startAddress, quint16 writeSize , QVe |
|
|
|
{ |
|
|
|
if (!modbusDevice) |
|
|
|
return; |
|
|
|
m_holdingRegisters = registerValues; |
|
|
|
_registerValues = registerValues; |
|
|
|
writeRequest(QModbusDataUnit::RegisterType::HoldingRegisters, startAddress, writeSize); |
|
|
|
} |
|
|
|
|
|
|
@ -187,7 +186,7 @@ QModbusDataUnit modBusMaster::readRequest(QModbusDataUnit::RegisterType registe |
|
|
|
return unit; |
|
|
|
} |
|
|
|
}); |
|
|
|
future.waitForFinished(); |
|
|
|
// future.waitForFinished();
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
@ -226,9 +225,9 @@ void modBusMaster::writeRequest(QModbusDataUnit::RegisterType registerType, int |
|
|
|
qDebug() << " ---- writeUnit.valueCount()" << writeUnit.valueCount(); |
|
|
|
for (int i = 0; i < writeUnit.valueCount(); i++) { |
|
|
|
if (table == QModbusDataUnit::Coils) |
|
|
|
writeUnit.setValue(i, m_coils[i + writeUnit.startAddress()]); |
|
|
|
writeUnit.setValue(i, _coilFlags[i + writeUnit.startAddress()]); |
|
|
|
else |
|
|
|
writeUnit.setValue(i, m_holdingRegisters[i + writeUnit.startAddress()]); |
|
|
|
writeUnit.setValue(i, _registerValues[i + writeUnit.startAddress()]); |
|
|
|
} |
|
|
|
|
|
|
|
if (auto *reply = modbusDevice->sendWriteRequest(writeUnit, _slaveAddress)) { |
|
|
@ -238,13 +237,14 @@ void modBusMaster::writeRequest(QModbusDataUnit::RegisterType registerType, int |
|
|
|
{ |
|
|
|
qDebug() << "reply->isFinished() " << reply->isFinished(); |
|
|
|
} |
|
|
|
qDebug() << "reply->isFinished() after " << reply->isFinished(); |
|
|
|
if(!checkForError(reply)) |
|
|
|
{ |
|
|
|
const QModbusDataUnit unit = reply->result(); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
future.waitForFinished(); |
|
|
|
// future.waitForFinished();
|
|
|
|
|
|
|
|
// if (!reply->isFinished()) {
|
|
|
|
// connect(reply, &QModbusReply::finished, this, [reply]() {
|
|
|
|