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.
55 lines
1.6 KiB
55 lines
1.6 KiB
#include "SimulaterModbus.h"
|
|
#include "QDebug"
|
|
#include <QTimer>
|
|
#include <QThread>
|
|
#include <qeventloop.h>
|
|
Simulatermodbus::Simulatermodbus(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
}
|
|
|
|
void Simulatermodbus::init()
|
|
{
|
|
QEventLoop qloop;
|
|
qDebug() << "Simulatermodbus::init" << QThread::currentThreadId() ;
|
|
timer = new QTimer();
|
|
timer->setInterval(2000);
|
|
timer->start();
|
|
connect(timer, &QTimer::timeout, &qloop, &QEventLoop::quit);
|
|
qloop.exec();
|
|
timer->stop();
|
|
}
|
|
|
|
void Simulatermodbus::open(QString serialPort, int slaveAddress)
|
|
{
|
|
QEventLoop qloop;
|
|
qDebug() << "Simulatermodbus::open " << QThread::currentThreadId() ;
|
|
timer = new QTimer();
|
|
timer->setInterval(2000);
|
|
timer->start();
|
|
connect(timer, &QTimer::timeout, &qloop, &QEventLoop::quit);
|
|
qloop.exec();
|
|
qDebug() << " Simulatermodbus open Done serial is " << serialPort;
|
|
qDebug() << " Simulatermodbus open Done slaveAddress is " << slaveAddress;
|
|
timer->stop();
|
|
|
|
}
|
|
|
|
void Simulatermodbus::readCoil(int startAddress, quint16 readSize)
|
|
{
|
|
QEventLoop qloop;
|
|
qDebug() << "Simulatermodbus::open " << QThread::currentThreadId() ;
|
|
timer = new QTimer();
|
|
timer->setInterval(10000);
|
|
timer->start();
|
|
connect(timer, &QTimer::timeout, &qloop, &QEventLoop::quit);
|
|
qloop.exec();
|
|
qDebug() << " Simulatermodbus open Done serial is " << startAddress;
|
|
qDebug() << " Simulatermodbus open Done slaveAddress is " << readSize;
|
|
timer->stop();
|
|
QBitArray bitArrayTemp;
|
|
bitArrayTemp.resize(1);
|
|
bitArrayTemp[0] = true;
|
|
emit coilIsReady(bitArrayTemp);
|
|
}
|
|
|
|
|