Unicode character to readable format
-
Hi
Check the sample code for receiving data in the serial port.
connect(port,&QSerialPort::readyRead,this,&WeighingMachine::readData);
buffer is QByteArray datatype.
void WeighingMachine::readData()
{
QString Time = QTime::currentTime().toString("hh:mm:ss.zzz");while(!(port->atEnd())) { buffer.append(port->readAll()); int i =0; QByteArray temp; int len = buffer.length();
#ifdef QT_DEBUG
qDebug()<<"Buffer: "<< QString::fromUtf8(buffer);;
#endifwhile(i<len) { if ((buffer.at(i)== '\r') && (temp.length() > 0)) { QString str(temp); QString Find = "\n"; QString replace = ""; str.replace(str.indexOf(Find),Find.size(),replace); weighingMachineData = Time +"," +str;
#ifdef QT_DEBUG
// qDebug()<<"Weighing Data: "<<weighingMachineData;
#endiftemp.clear(); } else { temp.append(buffer.at(i)); } i++; } buffer.clear(); buffer.append(temp); temp.clear(); }
}
For your information, I also receive the same data in cutecom terminal also.
-
@eswar said in Unicode character to readable format:
#ifdef QT_DEBUG
qDebug()<<"Buffer: "<< QString::fromUtf8(buffer);;
#endifPlease change that to:
qDebug() << "Buffer:" << buffer << "hex:" << buffer.toHex();
and post the output here.Thanks.
-
@eswar That is really strange - all these characters are outside the visible ASCII range.
- Do you have a documentation for the command set of the device you are talking with?
- Can you repeat the last qDebug() tests in Windows?
- Are you sure the serial parameters (baudrate, start, stop bits, parity) are correct in Linux?
-
@eswar Something is terribly wrong in Linux - I'd blame the serial parameters.
You need to find the culprit before you can continue.
Best start with a terminal program in Linux and see if you can receive the data correctly there.
-
-
@aha_1980
The linux system is regular laptop and windows is another laptop.
The device is connected via USB( converter is used to covert the serial RS-232 to USB)
The external device is properly powered using separate power supply.Same device is used to development on both platforms. The previous attached screenshot are taken same value in device for both linux and windows platform.
-
Might be a silly question but did you try to connect it to another Linux station to see if it gives you the same results ?
-
The issue was solved. Its related to linux OS problem. Its will work well with linux mint 19 OS. Before the earlier version of linux, the data received as encoded format only. In Linux mint 19, it will work fine in both cutecom as well as Qt application. Thanks for the support to solve the issue.