-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuartreceiver.cpp
More file actions
42 lines (33 loc) · 1009 Bytes
/
uartreceiver.cpp
File metadata and controls
42 lines (33 loc) · 1009 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
#include "uartreceiver.h"
UARTReceiver::UARTReceiver(QObject *parent) : QObject(parent)
{
}
UARTReceiver::~UARTReceiver()
{
if (serialPort->isOpen())
serialPort->close();
}
void UARTReceiver::initializeUART(const QString& name)
{
serialPort = new QSerialPort();
serialPort->setPortName(name);
serialPort->setBaudRate(QSerialPort::Baud115200);
serialPort->setDataBits(QSerialPort::Data8);
serialPort->setParity(QSerialPort::NoParity);
serialPort->setStopBits(QSerialPort::OneStop);
serialPort->setFlowControl(QSerialPort::NoFlowControl);
qDebug() << "Port open: " << serialPort->open(QIODevice::ReadOnly);
qDebug() << "Port error: " << serialPort->errorString();
while (true)
{
if (serialPort->waitForReadyRead(100))
{
QByteArray data = serialPort->readAll();
emit dataReceived(data);
}
}
}
void UARTReceiver::deinitializeUART(const QString& name)
{
serialPort->close();
}