A suggest a smaller timeout (like 100ms) unless you rarely receive anything on the serial port. To be honest it is best to have an adaptive timeout, for instance start with 100ms. If you receive something reduce the timeout twice unless you are already on 100ms. If you don't receive anything, double the timeout.
void sth::tryReceive(){
if(bytesAvailable()>0){
timeout = qMax(100, timeout/2);
readData(...);
} else {
timeout = qMin(1000, timeout*2);
}
QTimer::singleShot(timeout,
this,
SLOT(tryReceive
()));
}
void sth::tryReceive(){
if(bytesAvailable()>0){
timeout = qMax(100, timeout/2);
readData(...);
} else {
timeout = qMin(1000, timeout*2);
}
QTimer::singleShot(timeout, this, SLOT(tryReceive()));
}
To copy to clipboard, switch view to plain text mode
This way you'll be receiving faster if there is anything to receive and will reduce the load on the application when there is not.
Bookmarks