How to communicate with an Arduino over its serial interface in C++ on Linux?


I have an RFID reader connected to an Arduino board. I'd like to connect to it over its serial interface, and whenever the RFID reader omits a signal ( when it has read an (RF)ID ), I'd like to retrieve it in my C++ program.

I already have the code for simply printing the RFID to serial from the Arduino.

What I don't know, is how to read it from C++ in Linux ?

I have looked at libserial, which looks straightforward. However, how can I have the C++ program react to a signal and then read the RFID, instead of listening continously? Is this necessary?

EDIT: In most examples I have read, the (c++) program sends input, and recieves output. I just want to listen and recieve output from the Arduino.

12/18/2008 9:39:13 PM

Accepted Answer

I found the Boost::Asio library, which reads from serial interfaces asynchronously. Boost::Asio Documentation

10/4/2008 8:45:12 PM

On unix you use the select() call to wait for an input. The select() call acts like a sleep - using no CPU until the kernel receives the hardware interrupt and triggers the select().

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow