-
Notifications
You must be signed in to change notification settings - Fork 1
/
portthread.cpp
60 lines (52 loc) · 1.72 KB
/
portthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "portthread.h"
#include "QMessageBox"
#include <QDebug>
PortThread::PortThread(QObject *parent) :
QThread(parent)
{
//Contains all the ports available
serialPortInfoList=QSerialPortInfo::availablePorts();
ListPort=new QStringList();
length=serialPortInfoList.length();
setParent(0);
moveToThread(this);
}
void PortThread::run()
{
//b=true if connected
bool b;
QString name;
int i=0;
//Infinite loop
while (true)
{
b=false;
//We don't need to update the information every ms
QThread::msleep(1000);
//Update the serialPortInfoList
serialPortInfoList=QSerialPortInfo::availablePorts();
//If there is more or less port, we update
if (length!=serialPortInfoList.length() || i==0)
{
foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList)
{
qDebug() << serialPortInfo.manufacturer();
//Check the manufacturer to match one the following
if (serialPortInfo.manufacturer()=="www.airboxlab.com" || serialPortInfo.manufacturer()=="getalima.com" || serialPortInfo.manufacturer()=="http://getalima.com/" || serialPortInfo.manufacturer()=="http://www.airboxlab.com/" || serialPortInfo.manufacturer()=="Dean Camera")
{
b=true;
name=*(new QString(serialPortInfo.portName()));
}
}
//Inform MainWindow that the airboxlab is connected
emit isPlugged(b);
//Transmit it port name
emit updateName(name);
}
length=serialPortInfoList.length();
ListPort->clear();
//}
i=1;
}
exec();
}