我写了一个QT串口通信程序,收不到数据。 red hat9系统,QT3。代码如下:各位大侠帮我看看咋回事。附上工程。(我没有设置定时器,使用的“显示数据”按钮,手动触发串口读取。各位莫喷~~)
#include "posix_qextserialport.h"
#include <QMessageBox>
#include <QIODevice>
Posix_QextSerialPort *myCom;
void Form7::openCom()
{
myCom = new Posix_QextSerialPort("/dev/ttyS0");
myCom->open();
}
void Form7::senddata()
{
myCom->setBaudRate(BAUD115200);
myCom->setFlowControl(FLOW_OFF);
myCom->setParity(PAR_NONE);
myCom->setDataBits(DATA_8);
myCom->setStopBits(STOP_1);
myCom->setTimeout(5,0);
int a=myCom->writeBlock("1",1);
QString str;
str.setNum(a);
QMessageBox::warning(this,"a",str);
}
void Form7::readCom()
{
char buf[256]={0};
int a= myCom->readBlock(buf,256);
QString str;
str.setNum(a);
QMessageBox::warning(this,"a",str);
this->lineEdit6->setText(buf);
}
void Form7::Nclose()
{
myCom->close();
}