-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialcom.cpp
81 lines (72 loc) · 1.72 KB
/
serialcom.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "serialcom.h"
serialCom::serialCom()
{
comport = new QSerialPort;
command[0]=0x54;
command[1]=0x58;
command[2]=0x4c;
command[3]=0x45;
command[4]=0x44;
command[5]=0x43;
command[6]=0x4f;
command[7]=0x4e;
command[8]=0x54;
command[9]=0x52;
command[10]=0x4f;
command[11]=0x4c;
command[12]=0x4c;
command[13]=0x45;
command[14]=0x52;
command[15]=0xbb;
command[16]=0x07;
command[17]=0x00;
command[18]=0x40;
}
serialCom::~serialCom()
{
delete comport;
comport->clear();
comport->close();
}
bool serialCom::openCom() {
if (comport->isOpen()) {
return true;
}
int flag = 0;
comport->setDataBits(QSerialPort::Data8);
comport->setParity(QSerialPort::NoParity);
comport->setStopBits(QSerialPort::OneStop);
comport->setBaudRate(QSerialPort::Baud115200);
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){
comport->setPortName(info.portName());
comport->open(QIODevice::ReadWrite);
comport->write(command, 19);
rcvData.clear();
while (comport->waitForReadyRead(100))
rcvData.append(comport->readAll());
if(!strncmp("run.log", rcvData.data(), 7)){
flag = 1;
break;
}
else
comport->close();
}
if(flag == 0)
return false;
else
return true;
}
bool serialCom::writeToCom(short block)
{
rcvData.clear();
command[18] = 0x40+block;
comport->write(command, 19);
return true;
}
bool serialCom::readFromCom()
{
qDebug() << "Brush:" <<"send data success";
while (comport->waitForReadyRead(100))
rcvData.append(comport->readAll());
return true;
}