qDebug()<<"...........info_strat.............";
qint64 length = m_serial->bytesAvailable();
qDebug()<<"info有效数据长度: "<<length;
QByteArray info = m_serial->readAll();
QByteArray hex = info.toHex();
qDebug()<<hex;
int int_from_hex;
bool ok;
for(uint8_t i=0,j=0;j<length;i+=2,j++){
int_from_hex = hex.mid(i,2).toInt(&ok,16);
qDebug()<<ok;
qDebug()<<int_from_hex;
}
qDebug()<<".........info_end...............";
结果PS:
info有效数据长度: 32
"98808182838485868788898a8b8c8d8e8f909192939495969798808182838485"
true
152
true
128
true
129
true
130
true
131
true
132
true
133
true
134
true
135
true
136
true
137
true
138
true
139
true
140
true
141
WIN10下 QT 串口读取下位机发送的十六进制数据
最新推荐文章于 2023-09-03 17:04:57 发布
这篇博客详细介绍了如何使用QSerialPort在串口通信中获取信息,包括数据长度检测、hex转换和十六进制数据解析的过程。通过(debug)输出展示了每个步骤的结果,重点在于有效数据长度和十六进制字符串到十进制的转换。
2734

被折叠的 条评论
为什么被折叠?



