问题描述
我正在调试使用 QtCreator 在 Qt/C++ 中开发的应用程序.我的应用程序使用 QextSerialPort 从串口读取数据,其中串口连接到 Rhino Mark IV 控制器.
I am debugging an application developed in Qt/C++ using QtCreator. My application reads from the serial port using QextSerialPort, where the serial port is connected to a Rhino Mark IV controller.
int bytesRead;
char buffer[BUFFER_SIZE];
if (_serialPort->bytesAvailable() > 0
&& (bytesRead = _serialPort->read(buffer, BUFFER_SIZE)) > 0)
{
_comBuffer.append(buffer, bytesRead);
buffer[bytesRead+1] = 0; // for debugging purposes
qDebug(buffer); // for debugging purposes
}
我遇到了这个问题,因为我尝试读取一些 ASCII 数据,但是我进入缓冲区的是一些奇怪的字符.例如,数字零 ('0') 的 ASCII 代码被另一个代码替换,该代码由调试器显示并由 qDebug
打印为°".
I am having trouble with this, because I try to read some ASCII data, but what I get into the buffer are some strange characters. For example, the ASCII code for number zero ('0') is replaced by another code that is shown by the debugger and printed by qDebug
as '°'.
此外,我在应用程序输出"选项卡中收到以下消息:解析目标库列表时:格式不正确(令牌无效)
.
In addition, I get following message in the Application Output tab: while parsing target library list: not well-formed (invalid token)
.
我想知道为什么我没有通过 QextSerialPort 获得适当的 ASCII 代码.是 QextSerialPort 还是 Rhino Mark IV 控制器的问题? 我正在两台显示器上通过串行端口查看流量,并且显示器上正确显示了 ASCII 字符.因此,我得出结论,这不是控制器或通信通道的问题.
I wonder why I do not get the appropriate ASCII code with QextSerialPort. Is it a problem of QextSerialPort or of the Rhino Mark IV controller? I am viewing the traffic through the serial port on two monitors, and the ASCII characters are displayed correctly on the monitors. Thus, I have concluded that it is not a problema of the controller or the communication channel.
解析目标库列表时出现的消息: not well-formed (invalid token)
是什么意思,为什么会这样?
What does the message while parsing target library list: not well-formed (invalid token)
mean and why is it caused?
推荐答案
您是否在应用程序中正确配置了串行端口(即波特率、停止位等)?
Did you configure the serial port correctly in your application (i.e. baudrate, stop bits, etc.)?
此外,当零终止缓冲区时,您不应向 bytesRead
添加 1,因为这会允许在字符串末尾出现一个不需要的字节.
Also, you should not add 1 to bytesRead
when zero terminating the buffer as that allows a single unwanted byte at the end of the string.
该错误消息由 gdb,而不是 Qt.这可能与使用具有非 latin1 编码名称的文件/文件夹有关.
That error message is generated by gdb, not Qt. It may be related to using files/folders with non-latin1 encoded names.
这篇关于Qt调试错误:“解析目标库列表时:格式不正确(令牌无效)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!