|
@ -186,17 +186,24 @@ QModbusDataUnit modBusMaster::readRequest(QModbusDataUnit::RegisterType registe |
|
|
if (auto *reply =modbusDevice->sendReadRequest(QModbusDataUnit(table, startAddress, readSize), _slaveAddress)) |
|
|
if (auto *reply =modbusDevice->sendReadRequest(QModbusDataUnit(table, startAddress, readSize), _slaveAddress)) |
|
|
{ |
|
|
{ |
|
|
QFuture<void> future = QtConcurrent::run([this, reply]() { |
|
|
QFuture<void> future = QtConcurrent::run([this, reply]() { |
|
|
|
|
|
// while(!reply->isFinished())
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// qDebug() << "reply->isFinished() " << reply->isFinished();
|
|
|
// qDebug() << "reply->isFinished() " << reply->isFinished();
|
|
|
while(!reply->isFinished()) |
|
|
// qDebug() << "Hello from thread " << QThread::currentThread();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (!freeThread) |
|
|
{ |
|
|
{ |
|
|
qDebug() << "reply->isFinished() " << reply->isFinished(); |
|
|
if (!reply->isFinished()) |
|
|
qDebug() << "Hello from thread " << QThread::currentThread(); |
|
|
{ |
|
|
|
|
|
qDebug() << "1reply->isFinished() " << reply->isFinished(); |
|
|
|
|
|
connect(reply, &QModbusReply::finished, this, &modBusMaster::modbusReplyRecieved, Qt::ConnectionType::BlockingQueuedConnection); |
|
|
|
|
|
qDebug() << "2reply->isFinished() " << reply->isFinished(); |
|
|
} |
|
|
} |
|
|
freeThread=true; |
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// freeThread=true;
|
|
|
mutex.lock(); |
|
|
mutex.lock(); |
|
|
if (freeThread) |
|
|
if (freeThread) |
|
|
modBusAnswerNotReady.wakeAll(); |
|
|
modBusAnswerNotReady.wakeAll(); |
|
@ -209,8 +216,6 @@ QModbusDataUnit modBusMaster::readRequest(QModbusDataUnit::RegisterType registe |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
@ -218,7 +223,7 @@ QModbusDataUnit modBusMaster::readRequest(QModbusDataUnit::RegisterType registe |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//reply->deleteLater();
|
|
|
reply->deleteLater(); |
|
|
} |
|
|
} |
|
|
bool modBusMaster::checkForError(QModbusReply *_reply) |
|
|
bool modBusMaster::checkForError(QModbusReply *_reply) |
|
|
{ |
|
|
{ |
|
@ -239,6 +244,20 @@ bool modBusMaster::checkForError(QModbusReply *_reply) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void modBusMaster::modbusReplyRecieved() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
// auto reply = qobject_cast<QModbusReply *>(sender());
|
|
|
|
|
|
// if (!reply)
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
// modbusReplyFromClient = reply;
|
|
|
|
|
|
freeThread=true; |
|
|
|
|
|
|
|
|
|
|
|
// reply->deleteLater();
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void modBusMaster::writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 writeSize) |
|
|
void modBusMaster::writeRequest(QModbusDataUnit::RegisterType registerType, int startAddress, quint16 writeSize) |
|
|
{ |
|
|
{ |
|
|
qDebug() << " ---- setSingleCoil coilFlag writeRequest "; |
|
|
qDebug() << " ---- setSingleCoil coilFlag writeRequest "; |
|
|