You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
#include "Modbuswrapper.h"
|
|
#include "qdebug.h"
|
|
ModbusWrapper::ModbusWrapper(QObject *parent) : QObject(parent)
|
|
{
|
|
qDebug() << " QThread::currentThreadId() ModbusWrapper before " <<QThread::currentThreadId() ;
|
|
// modBusObj = new modBusMaster();
|
|
|
|
}
|
|
|
|
ModbusWrapper::~ModbusWrapper()
|
|
{
|
|
workerThread.quit();
|
|
workerThread.wait();
|
|
}
|
|
|
|
void ModbusWrapper::init(QString serialPort, int slaveAddress)
|
|
{
|
|
modBusObj.moveToThread(&workerThread);
|
|
workerThread.setObjectName("workerThread");
|
|
workerThread.start();
|
|
|
|
qDebug() << " QThread::currentThreadId() ModbusWrapper then " <<QThread::currentThreadId() ;
|
|
connect(this, &ModbusWrapper::openConnectionOrder, &modBusObj, &ModBusMaster::open, Qt::BlockingQueuedConnection);
|
|
connect(this, &ModbusWrapper::stopConnectionOrder, &modBusObj, &ModBusMaster::stop, Qt::BlockingQueuedConnection);
|
|
connect(&workerThread, &QThread::started, &modBusObj, &ModBusMaster::init);
|
|
connect(&modBusObj, &ModBusMaster::finished, &workerThread, &QThread::terminate);
|
|
connect(this, &ModbusWrapper::getCoilOrder, &modBusObj, &ModBusMaster::getCoil, Qt::BlockingQueuedConnection);
|
|
qDebug() << "initWrapper " << QThread::currentThreadId() ;
|
|
emit openConnectionOrder(serialPort, slaveAddress);
|
|
}
|
|
|
|
void ModbusWrapper::stop()
|
|
{
|
|
emit stopConnectionOrder();
|
|
}
|
|
|
|
QBitArray ModbusWrapper::getCoil(int startAddress, quint16 numberOfEntries)
|
|
{
|
|
QBitArray coilDataFromClient = emit getCoilOrder(startAddress, numberOfEntries);
|
|
return coilDataFromClient;
|
|
}
|
|
|
|
|