Hi to everyone.
I'm currently using the QextSerialPort v1.1 and I've got a problem when trying to use the waitForReadyRead (like in QTcpSocket and other IODevices...). My application currently uses three threads (GUI, socket and serial port) and in fact I want to use the waitForReadyRead method because my thread uses a loop approach (not being a GUI thread...)
I'm giving the method a 5s timeout (value 5000 as argument) and what actually happens when I call the method is that it won't wait until the timeout (if not data has been received yet) but it returns immediately returning me a -1 value which means that an error occurred...
If I use a counter decremented until 0 and call bytesAvailable() I'm able to read everything correctly but the counter, which is a polling approach, wastes me time...
Did someone of you had problems with this waitForReadyRead method in QextSerialPort?
By the way my code looks like the following:
...
quint32 count = 800000;
serial_port->write(&cdata, 1);
//qDebug() << "Wait: " << serial_port->waitForReadyRead(5000);
while(count--);
qDebug() << "bytes available: " << serial_port->bytesAvailable();
serial_port->read(&cdata, 1);
...
...
quint32 count = 800000;
serial_port->write(&cdata, 1);
//qDebug() << "Wait: " << serial_port->waitForReadyRead(5000);
while(count--);
qDebug() << "bytes available: " << serial_port->bytesAvailable();
serial_port->read(&cdata, 1);
...
To copy to clipboard, switch view to plain text mode
The following is the non-working version using waitForReadyRead()
...
serial_port->write(&cdata, 1);
if(!serial_port->waitForReadyRead(5000)){
qDebug() << "Error";
}else{
qDebug() << "bytes available: " << serial_port->bytesAvailable();
serial_port->read(&cdata, 1);
}
...
...
serial_port->write(&cdata, 1);
if(!serial_port->waitForReadyRead(5000)){
qDebug() << "Error";
}else{
qDebug() << "bytes available: " << serial_port->bytesAvailable();
serial_port->read(&cdata, 1);
}
...
To copy to clipboard, switch view to plain text mode
It would be great if someone could be able to help me.
Cheers.
Bookmarks