1

我可以看到我在写入缓冲区中写入的内容,但是,没有准备好读取的信号,即使我使用读取功能,读取缓冲区中也没有任何内容。这是我的代码:

    void Widget::ouvrir_port_com()
{
    struct PortSettings myComSetting = {BAUD57600,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,100};

    myCom = new Win_QextSerialPort(port_com,myComSetting,QextSerialBase::EventDriven);

    if(myCom ->open(QIODevice::ReadWrite))// si il est ouvert
    {
        //QMessageBox::information(this, tr("Ouvert reussi"), tr("Ce port est ouvert") + port_com, QMessageBox::Ok);
    }else// si il est pas ouvert
    {
        QMessageBox::critical(this, tr("Echec de l'ouverture"), tr("Ce port de com ne peut pas être ouvrire ") + port_com + tr("\n Ce port de com n'est pas dipnible"), QMessageBox::Ok);
         return;
    }

    connect(myCom,SIGNAL(readyRead()),this,SLOT(readCom()));

    send_command();
}

void Widget::readCom()

{
    QByteArray temp = myCom->readAll();

    ui->textBrowser->insertPlainText(temp);
}

void Widget::send_command()
{
    QString x="OK ou pas?";
    myCom->write(x.toLatin1());
    myCom->flush();

    myCom->readyRead();
}

请帮我!!!!

4

1 回答 1

0

您可以阅读 souce,posix_qextserialport.cpp 第 147 行:“POSIX 尚未实现事件驱动机制”,因此您可以新建一个计时器并在 100 毫秒时进行轮询。

于 2017-01-12T03:22:53.297 回答