Read data RS232 without pooling
-
i read data from RS232 in a for loop.this has no good performance.i want don't have a for loop instead of that there was a thing like event that when data is receiving it fire. is this possible? for example when data is receiving from COM16 event firing.
-
You give absolutely no info what API you are currently using to read from COM port.
Anyway, if that API has a blocking call, that will not return before new data is available, you can simply use that one, in a loop, and put that loop into a background thread. Then send a signal as soon as new data is available.
Like:
@MyThread::run()
{
forever
{
readDataFromComPort_blocking();
emit newDataAvailable();
}
}@ -
thanks for your reply. how can i have blocking call for that? i can't implement
@
readDataFromComPort_blocking();
@
function. -
Tell us what API you are using to read from the COM port, if you expect an answer on this ;-)
-
I'm using QExtSerialPort very successfully in an application that doesn't poll, either.
http://code.google.com/p/qextserialport/It makes this possible by emitting a readyRead signal, as soon as data is available.
-
You can also use official "QtSerialPort":http://qt-project.org/wiki/QtSerialPort addon.
See documentation about API and examples "here":http://doc-snapshot.qt-project.org/qt5-stable/qtserialport/qtserialport-index.html.
Therefore there is no need of use of your custom code.