UART is an asynchronous interface, so, you never know when the data is coming in. Thus, your driver should start a thread / process / part of mainloop to periodically poll the line for data.
Thanks. I understand that...maybe I didn't ask the right question. How should I check for data? Doing a ready or there is another (correct) way?
Sorry, I'm not familiar with libmraa at all, possible someone else can explain how you can achieve it there.
If you're programming in C you may have at least those two possibilities for knowing if there is any data in RX buffer of UART :
- Using the function provided by libmraa mraa_uart_data_available() : mraa: /var/lib/jenkins/workspace/mraa-doc/api/mraa/uart.h File Reference
- Using the Linux ioctl library directly : ioctl(2) - Linux manual page
Were you able to follow Bylos’ suggestion? Do you still need help with this thread?
Hi Bylos, Sergio,
I will try to use the mraa_uart_data_available tomorrow. So far i'm just reading and checking bytes read, which works, but i'm wondering if that's the most efficient. Is there any suggestion on how long to wait in between each read? I'm setting the baud rate to 115200.
thank you for suggestions. I'll report back afterwards.
I used this mraa_uart_data_available and it works great. Thanks.
don't know how i missed it before.