开发环境:fedora12+QT4.7.2+Qt Creator2.5.2
用的是第三方的
串口库:qextserialport-1.2win-alpha
问题描述:
单片机采集到的
数据通过TTL转串口模块接在
嵌入式Linux开发板的com口,打开串口时超级终端提示:
                       Trying to open File
                       Opened File succesfully
但是接受不到串口传上来的数据。 

程序截图:
void MainWindow::on_pushButton_clicked()  //串口初始化并打开串口
{
    QString portName=ui->comboBox->currentText();
    myCom=new Posix_QextSerialPort(portName,QextSerialBase::Polling);
    myCom->close();
    myCom->open(QIODevice::ReadWrite);
    if(!myCom->isOpen())
    {
        QMessageBox::critical(this,QString("FAULT"),QString("cannot open:")+myCom->portName());
    }
    else
    {
        myCom->setBaudRate(BAUD9600);
        myCom->setDataBits(DATA_8);
        myCom->setParity(PAR_NONE);
        myCom->setStopBits(STOP_1);
        myCom->setFlowControl(FLOW_OFF);
        myCom->setTimeout(100);
        QMessageBox::information(this,QString("RIGHT"),QString("Open  ")+myCom->portName());
       ui->pushButton->setEnabled(false);
       ui->pushButton_2->setEnabled(true);
       ui->pushButton_3->setEnabled(true);
       ui->pushButton_4->setEnabled(true);
    }
}
void MainWindow::on_pushButton_2_clicked()  //关闭串口
{
    myCom->close();
    ui->pushButton->setEnabled(true);
    ui->pushButton_2->setEnabled(false);
    ui->pushButton_3->setEnabled(false);
    ui->pushButton_4->setEnabled(false);
}
void MainWindow::on_pushButton_3_clicked()  //发送数据
{
    myCom->write(ui->lineEdit->text().toAscii());
    QMessageBox::information(this,QString("SEND"),QString("Send  Data!!!!!"));
}
void MainWindow::on_pushButton_4_clicked()  //接收数据
{
    qint64 len=myCom->bytesAvailable();
    if(len<=0)
    {
      QMessageBox::information(this,QString("RECEIVE"),QString("Have  No  Data!!!!!"));
    }
    else
    {
        QByteArray temp=myCom->read(10);
        ui->textBrowser->insertPlainText(temp);
        QMessageBox::information(this,QString("Receive"),QString("Received  Data!!!!!"));
    }
}