-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialComm.cpp
More file actions
44 lines (35 loc) · 864 Bytes
/
serialComm.cpp
File metadata and controls
44 lines (35 loc) · 864 Bytes
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
#include "serialComm.h"
SerialComm::SerialComm(QObject *parent) : QObject(parent)
{
comm =new QSerialPort();
initComm();
connect(comm,SIGNAL(readyRead()),this,SLOT(handleSerialRaw()));
}
void SerialComm::initComm()
{
comm->setPortName("ttymxc4");
comm->setBaudRate(QSerialPort::Baud115200);
comm->setDataBits(QSerialPort::Data8);
comm->setParity(QSerialPort::NoParity);
comm->setStopBits(QSerialPort::OneStop);
comm->setFlowControl(QSerialPort::NoFlowControl);
if(!comm->open(QIODevice::ReadWrite))
{
qDebug()<<"init field";
return;
}
}
void SerialComm::handleSerialRaw()
{
QByteArray ba = comm->readAll();
emit this->sendSerialData(ba);
}
void SerialComm::writeToSerial(QByteArray ba)
{
comm->write(ba,ba.size());
}
SerialComm::~SerialComm()
{
comm->close();
exit(0);
}