0

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
}

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).

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.

What does the message while parsing target library list: not well-formed (invalid token) mean and why is it caused?

Genba
  • 854
  • 2
  • 10
  • 19

1 Answers1

1

Did you configure the serial port correctly in your application (i.e. baudrate, stop bits, etc.)?

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.

That error message is generated by gdb, not Qt. It may be related to using files/folders with non-latin1 encoded names.

Judge Maygarden
  • 26,961
  • 9
  • 82
  • 99
  • I added that 1 to `bytesRead` for debugging purposes, just for easily printing the string stored in the buffer, given that I know that I will never have an overflow during my tests (since I do the tests and I know that the buffer will never be filled during those tests). I did set up the proper baudrate, but I am not sure if the other parameters are correctly set. However, I can read and write from the port (actually, sending commands over the serial connection works perfectly), but the problem is that the bytes I read from the port do not seem to have the proper character coding. – Genba Mar 25 '11 at 21:44
  • Finally, I realized that the way I was configuring the serial port was not correct at all. Some of the settings were right, but not all of them. I did not find that information in the device's manual, but in a manual different from the one of the proper device, which was quite annoying. – Genba Apr 13 '11 at 12:12