|
|
@ -107,8 +107,14 @@ void modBusMaster::setMultipleRegister(int startAddress, quint16 writeSize , QVe |
|
|
|
|
|
|
|
QBitArray modBusMaster::getCoil(int startAddress, quint16 readSize) |
|
|
|
{ |
|
|
|
|
|
|
|
QModbusDataUnit unit = readRequest(QModbusDataUnit::RegisterType::Coils, startAddress, readSize); |
|
|
|
mutex.lock(); |
|
|
|
if (!unit.valueCount()) |
|
|
|
modBusAnswerNotReady.wait(&mutex); |
|
|
|
mutex.unlock(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QBitArray coils; |
|
|
|
coils.resize(2); |
|
|
|
auto num = unit.valueCount(); |
|
|
@ -117,7 +123,15 @@ QBitArray modBusMaster::getCoil(int startAddress, quint16 readSize) |
|
|
|
{ |
|
|
|
coils.setBit((unit.value(i))); |
|
|
|
} |
|
|
|
|
|
|
|
mutex.lock(); |
|
|
|
modBusAnswerConsumed.wait(&mutex); |
|
|
|
mutex.unlock(); |
|
|
|
|
|
|
|
return coils ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QBitArray modBusMaster::getInputCoil(int startAddress, quint16 readSize) |
|
|
@ -174,19 +188,29 @@ QModbusDataUnit modBusMaster::readRequest(QModbusDataUnit::RegisterType registe |
|
|
|
if (auto *reply =modbusDevice->sendReadRequest(QModbusDataUnit(table, startAddress, readSize), _slaveAddress)) |
|
|
|
{ |
|
|
|
QFuture<void> future = QtConcurrent::run([this, reply]() { |
|
|
|
qDebug() << "reply->isFinished() " << reply->isFinished(); |
|
|
|
while(!reply->isFinished()) |
|
|
|
{ |
|
|
|
qDebug() << "reply->isFinished() " << reply->isFinished(); |
|
|
|
qDebug() << "Hello from thread " << QThread::currentThread(); |
|
|
|
} |
|
|
|
|
|
|
|
mutex.lock(); |
|
|
|
if (!reply->isFinished()) |
|
|
|
modBusAnswerNotReady.wait(&mutex); |
|
|
|
mutex.unlock(); |
|
|
|
|
|
|
|
|
|
|
|
// qDebug() << "reply->isFinished() " << reply->isFinished();
|
|
|
|
// while(!reply->isFinished())
|
|
|
|
// {
|
|
|
|
// qDebug() << "reply->isFinished() " << reply->isFinished();
|
|
|
|
// qDebug() << "Hello from thread " << QThread::currentThread();
|
|
|
|
// }
|
|
|
|
if(!checkForError(reply)) |
|
|
|
{ |
|
|
|
const QModbusDataUnit unit = reply->result(); |
|
|
|
return unit; |
|
|
|
} |
|
|
|
|
|
|
|
mutex.lock(); |
|
|
|
modBusAnswerConsumed.wakeAll(); |
|
|
|
mutex.unlock(); |
|
|
|
}); |
|
|
|
// future.waitForFinished();
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|