54 lines
955 B
C++
54 lines
955 B
C++
#include "vhfmillthread.h"
|
|
|
|
VhfMillThread::VhfMillThread(bool tcpI, int portI, const QString& hostI, const QString& serialPortI, QObject *parent):
|
|
tcp(tcpI),
|
|
port(portI),
|
|
serialPort(serialPortI),
|
|
host(hostI),
|
|
QThread(parent)
|
|
{
|
|
}
|
|
|
|
void VhfMillThread::run()
|
|
{
|
|
if(tcp)
|
|
{
|
|
QTcpSocket* microSocket = new QTcpSocket;
|
|
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
|
if(!microSocket->waitForConnected(1000))
|
|
{
|
|
ret = -2;
|
|
ready();
|
|
return;
|
|
}
|
|
masterIODevice = microSocket;
|
|
}
|
|
else
|
|
{
|
|
QSerialPort* microPort = new QSerialPort;
|
|
microPort->setPortName(serialPort);
|
|
microPort->setBaudRate(115200);
|
|
|
|
if(!microPort->open(QIODevice::ReadWrite))
|
|
{
|
|
qDebug()<<"could not open serial port "<<serialPort;
|
|
ret = -3;
|
|
ready();
|
|
return;
|
|
}
|
|
masterIODevice = microPort;
|
|
}
|
|
|
|
mill = new VhfMill(masterIODevice);
|
|
ret = 0;
|
|
ready();
|
|
exec();
|
|
delete mill;
|
|
delete masterIODevice;
|
|
}
|
|
|
|
VhfMillThread::~VhfMillThread()
|
|
{
|
|
}
|
|
|