|
|
@ -8,41 +8,46 @@ ModbusWrapper::ModbusWrapper(QObject* parent) : QObject(parent) |
|
|
|
/*************************************************************************************************/ |
|
|
|
ModbusWrapper::~ModbusWrapper() |
|
|
|
{ |
|
|
|
workerThread.quit(); |
|
|
|
workerThread.wait(); |
|
|
|
_workerThread.quit(); |
|
|
|
_workerThread.wait(); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ModbusWrapper::init() |
|
|
|
{ |
|
|
|
modbusMaster.moveToThread(&workerThread); |
|
|
|
workerThread.setObjectName("workerThread"); |
|
|
|
workerThread.start(); |
|
|
|
_modbusMaster.moveToThread(&_workerThread); |
|
|
|
_workerThread.setObjectName("workerThread"); |
|
|
|
_workerThread.start(); |
|
|
|
|
|
|
|
QEventLoop loop; |
|
|
|
connect(&workerThread, &QThread::started, &loop, &QEventLoop::quit); |
|
|
|
connect(&_workerThread, &QThread::started, &loop, &QEventLoop::quit); |
|
|
|
loop.exec(); |
|
|
|
|
|
|
|
connect(this, |
|
|
|
&ModbusWrapper::initOrder, |
|
|
|
&modbusMaster, |
|
|
|
&_modbusMaster, |
|
|
|
&ModbusMaster::init, |
|
|
|
Qt::BlockingQueuedConnection); |
|
|
|
connect(this, |
|
|
|
&ModbusWrapper::connectOrder, |
|
|
|
&modbusMaster, |
|
|
|
&_modbusMaster, |
|
|
|
&ModbusMaster::connectToDevice, |
|
|
|
Qt::BlockingQueuedConnection); |
|
|
|
connect(this, |
|
|
|
&ModbusWrapper::getCoilOrder, |
|
|
|
&modbusMaster, |
|
|
|
&_modbusMaster, |
|
|
|
&ModbusMaster::getCoil, |
|
|
|
Qt::BlockingQueuedConnection); |
|
|
|
connect(this, |
|
|
|
&ModbusWrapper::getInputCoilOrder, |
|
|
|
&modbusMaster, |
|
|
|
&_modbusMaster, |
|
|
|
&ModbusMaster::getInputCoil, |
|
|
|
Qt::BlockingQueuedConnection); |
|
|
|
connect(this, |
|
|
|
&ModbusWrapper::getHoldingRegisterOrder, |
|
|
|
&_modbusMaster, |
|
|
|
&ModbusMaster::getHoldingRegister, |
|
|
|
Qt::BlockingQueuedConnection); |
|
|
|
|
|
|
|
emit initOrder(); |
|
|
|
|
|
|
@ -67,6 +72,15 @@ QBitArray ModbusWrapper::getInputCoil(int startAddress, quint16 readSize) |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
QVector<quint16> ModbusWrapper::getHoldingRegister(int startAddress, quint16 readSize) |
|
|
|
{ |
|
|
|
auto result = emit getHoldingRegisterOrder(startAddress, readSize); |
|
|
|
qDebug() << "getHoldingRegister done"; |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ModbusWrapper::connectToDevice(ModbusConfig modbusConfig) |
|
|
|
{ |
|
|
|