PDA

View Full Version : qextserialport error



hezbon
13th July 2012, 09:36
I am trying to read a serial port using the above class library, and am trying to use the if(port.isOpen()) to check if the port is already opened but the function returns error.

Again I want read data from that serial port now without checking the port is open can somebody show me how to convert the bytedata into string so that i can display it on the text label?

kuzulis
13th July 2012, 10:01
Why did you choose QextSerialPort? Try a different library QtSerialPort (http://qt-project.org/wiki/QtSerialPort).


i can display it on the text label?
Of course it is possible, provided that you pass the text


...
QByteArray data = port->readAll();
...
QString s(data);
...
label->setText(s);
...

hezbon
13th July 2012, 11:04
thanx, but i have realized if i use Qstring directly it reads the data and automatically converts. but there is only one problem that am encountering, i have a device that continually send a value 200 to my com port and my programme waits for readyread so it will pick that value and display it but the values appear as 200200,200,00,0,2,02 so how can i wait for a three digit number that is being sent continually and display the correct value?

ChrisW67
14th July 2012, 01:14
Append each received chunk of characters onto a persistent QByteArray buffer. When the buffer has 3 or more characters in it remove the front three to display, repeat until less than three characters in buffer.

hezbon
15th July 2012, 10:24
Append each received chunk of characters onto a persistent QByteArray buffer. When the buffer has 3 or more characters in it remove the front three to display, repeat until less than three characters in buffer.

good quote. But the problem is solved. i used a logic to check the data and hold not to display any starting with 0 and should not exceed three.