为什么我收到一些从SerialPort收到的空数据?

发布于 2025-02-13 00:21:17 字数 751 浏览 1 评论 0原文

我使用以下命令行从传感器中提取数据:

QObject::connect(this->serialPort,SIGNAL(readyRead()),this,SLOT(pollSerialPort()));
QObject::connect(serialPort, &::QSerialPort::errorOccurred,this,&Imu::handleError);

QByteArray hexData = d.append(serialPort->readAll().toHex());

qDebug() << "Serial received " << hexData;

时,我不会收到数据,

但是,每当我收到很多空的消息

例如接收到“ 55555541321E7FF33029F61DA000000000000FFFFFFFFFFFFFFFAFFAFFAFFA2FFA0CBE24B124B124B124B124B124B124B1007B1007B1007B13D000000000 FERTIES MESTILS

MSERTING THINEMES命令 但是它不起作用

qObject :: connect(this-&gt; serialport,&amp; qSerialport :: readyread,this,this {qtimer :: singleshot(5,this,&amp; imu :: pollserialport;}); 请有什么解决方案吗?

I extracted the data from my sensor using these command lines:

QObject::connect(this->serialPort,SIGNAL(readyRead()),this,SLOT(pollSerialPort()));
QObject::connect(serialPort, &::QSerialPort::errorOccurred,this,&Imu::handleError);

QByteArray hexData = d.append(serialPort->readAll().toHex());

qDebug() << "Serial received " << hexData;

however, I do not receive the data every time

I have a lot of empty messages like this

Serial received "555541321e7ff3029f61da00000000ffff00d2fffa0cbe24b124b124b1007b13d00000f4d8"

Serial received ""

I used this command to receive the data every ms but it doesn't work

QObject::connect(this->serialPort, &QSerialPort::readyRead, this, this {QTimer::singleShot(5,this,&Imu::pollSerialPort);});
Any solution please ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡寂寞咖啡 2025-02-20 00:21:17

与其在计时器上进行轮询,不如将QSerialPort :: ReadyRead连接到一个插槽,并且在插槽内使用QSerialPort :: ReadAll(),直到qSerialport :: bytesavailable()为0。

Instead of polling on a timer, connect QSerialPort::readyRead to a slot and inside the slot use QSerialPort::readAll() until QSerialPort::bytesAvailable() is 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文