为什么我收到一些从SerialPort收到的空数据?
我使用以下命令行从传感器中提取数据:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其在计时器上进行轮询,不如将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.