【问题标题】:Qt serial port, when i write, i can not read what i writeQt串口,当我写的时候,我不能读我写的东西
【发布时间】:2013-11-07 08:51:50
【问题描述】:

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

    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();
}

请帮帮我!!!!

【问题讨论】:

  • 好吧,现在你写了它,它被发送到另一个设备。您不会为刚刚写的内容做好准备,而是为串行连接另一端的设备所写的内容做好准备。
  • 您编写的其他设备是否正在将收到的内容发回?
  • 你有没有考虑切换官方的QtSerialPort插件?

标签: c++ qt serial-port


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多