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.

43 lines
1.5 KiB

4 years ago
#include "Modbuswrapper.h"
3 years ago
#include "qdebug.h"
4 years ago
ModbusWrapper::ModbusWrapper(QObject *parent) : QObject(parent)
{
3 years ago
qDebug() << " QThread::currentThreadId() ModbusWrapper before " <<QThread::currentThreadId() ;
3 years ago
// modBusObj = new modBusMaster();
4 years ago
}
ModbusWrapper::~ModbusWrapper()
{
workerThread.quit();
workerThread.wait();
}
3 years ago
void ModbusWrapper::init(QString serialPort, int slaveAddress)
4 years ago
{
3 years ago
modBusObj.moveToThread(&workerThread);
workerThread.setObjectName("workerThread");
workerThread.start();
qDebug() << " QThread::currentThreadId() ModbusWrapper then " <<QThread::currentThreadId() ;
3 years ago
connect(this, &ModbusWrapper::openConnectionOrder, &modBusObj, &ModBusMaster::open, Qt::BlockingQueuedConnection);
3 years ago
connect(this, &ModbusWrapper::stopConnectionOrder, &modBusObj, &ModBusMaster::stop, Qt::BlockingQueuedConnection);
connect(&workerThread, &QThread::started, &modBusObj, &ModBusMaster::init);
connect(&modBusObj, &ModBusMaster::finished, &workerThread, &QThread::terminate);
3 years ago
connect(this, &ModbusWrapper::getCoilOrder, &modBusObj, &ModBusMaster::getCoil, Qt::BlockingQueuedConnection);
3 years ago
qDebug() << "initWrapper " << QThread::currentThreadId() ;
4 years ago
emit openConnectionOrder(serialPort, slaveAddress);
}
3 years ago
void ModbusWrapper::stop()
4 years ago
{
emit stopConnectionOrder();
}
3 years ago
QBitArray ModbusWrapper::getCoil(int startAddress, quint16 numberOfEntries)
4 years ago
{
3 years ago
QBitArray coilDataFromClient = emit getCoilOrder(startAddress, numberOfEntries);
return coilDataFromClient;
4 years ago
}