-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathserial.cpp
More file actions
28 lines (25 loc) · 872 Bytes
/
Copy pathserial.cpp
File metadata and controls
28 lines (25 loc) · 872 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
#include "serial.h"
#include <iostream>
Serial::Serial(){
myCom = new Posix_QextSerialPort("/dev/ttyUSB0",QextSerialBase::Polling);
myCom ->open(QIODevice::ReadWrite);
//以读写方式打开串口
myCom->setBaudRate(BAUD115200);
//波特率设置,我们设置为9600
myCom->setDataBits(DATA_8);
//数据位设置,我们设置为8位数据位
myCom->setParity(PAR_NONE);
//奇偶校验设置,我们设置为无校验
myCom->setStopBits(STOP_1);
//停止位设置,我们设置为1位停止位
myCom->setFlowControl(FLOW_OFF);
myCom->setTimeout(1000);
}
void Serial::readMyCom(){
QByteArray temp = myCom->readAll();
QString str = temp;
std::cout << "rec : " << str.toStdString() << std::endl;
}
void Serial::send(QByteArray array){
myCom->write(array); //以ASCII码形式将数据写入串口
}