【问题标题】:Qt c++ Issue receiving data weighing scale Ohaus aviator 7000Qt c++ 问题接收数据称重秤 Ohaus aviator 7000
【发布时间】:2022-01-18 00:08:54
【问题描述】:

我正在尝试使用 Qt c++ 建立与我的 Aviator 7000 体重秤的串行端口连接。预期结果将是通过使用字节命令的成功通信。 可悲的是,我没有收到秤返回的任何字节。您可以在下面找到我迄今为止尝试过的内容:

    const int Max_attempts = 5;
    const int Max_sleep = 125;

    int attemps;
    attemps = 0;
    while (true)
    {

        int enq {5};
        QByteArray bytes;
        bytes.setNum(enq);
        m_serial->write(bytes);

        m_serial->waitForReadyRead(Max_sleep);

        if (m_serial->bytesAvailable() !=0)
        {
            qDebug() << m_serial->bytesAvailable() ;
            qDebug() << "connected" << m_serial->readAll();
            break;
        }

        attemps += 1;

        if (attemps == Max_attempts)
        {
            qDebug() << "no connection established";
            break;
        }
    }

亲切的问候, 提波

【问题讨论】:

  • 您是否尝试过使用像 TeraTerm 这样的串行客户端并检查串行端口是否确实有效?

标签: c++ qt


【解决方案1】:

根据this manual,您应该发送一个字节0x05,但您发送的是0x35(字符“5”)。

使用

bytes.append('\X05');

【讨论】:

  • 是的,已修复,谢谢
猜你喜欢
  • 2012-07-15
  • 2023-02-25
  • 1970-01-01
  • 2020-09-13
  • 1970-01-01
  • 2011-05-30
  • 2017-01-24
  • 2018-09-21
  • 2015-05-19
相关资源
最近更新 更多