Reputation: 431
Is it possible to check from user space application, whether data is available for reading in the UART port. The code is written in C over Embedded Linux Platform.
For Example :
while(isDataAvalable(fileDescriptor)) {
read(fileDescriptor, buffer, 10)
}
I am looking for some function provided by linux, which returns true if there is data to be read from port and false if there is no data. But the function itself should not remove the data from hardware buffer, until the data is read using "read" method.
If there is no such inbuilt function in linux, is there a way to create a wrapper function using the linux system calls to achieve the above functionality, which can be used by the user space application..?
Upvotes: 0
Views: 1097
Reputation: 7842
This can be achieved by using poll() in linux.
poll() shall be able to tell whether there is data to read and is very useful in such scenarios. It monitors a set of file descriptors and waits for one of the file descriptor to become ready to perform I/O.
poll() checks whether any desired event(like arrival of data) has occurred. If the requested event has occurred, it shall alert via POLLIN that the event has happened(there is data to read) in the particular file descriptor.
Upvotes: 1
Reputation: 718
If you could use Qt framework, than the QSerialPort is emitting signal QIODevice::readyRead() when data is available. (you could deploy Qt without gui for your platform to minimize the footprint)
Upvotes: 0