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

4

7

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.

Northman answered 3/10, 2008 at 22:47 Comment(0)
N
3

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

Northman answered 4/10, 2008 at 20:45 Comment(0)
T
6

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().

http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html

Thanks answered 3/10, 2008 at 23:11 Comment(0)
N
3

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

Northman answered 4/10, 2008 at 20:45 Comment(0)
H
1

The Communications part of the Interface section in the Arduino Playground has several examples of interfacing, including one with the Arduino as Linux TTY.

Try the Syntax and Programs forum and the Software Development forum on the Arduino site. There have been discussions about interfacing to many different languages and computers in the past.

And finally check out the Processing and Wiring sites. The Arduino IDE is based on the Processing language, and the Wiring environment and dev board is related to Arduino. Both sites have lots more examples and links to even more resources.

Edit: I just realized that I didn't answer your actual question. These are all general communications resources, but some may have hints towards how to alert the computer of a new RFID input.

Hidebound answered 3/10, 2008 at 23:10 Comment(1)
I have searched for this beforehand, and stumbled upon those pages. However, most assumes input, then output as a response. My program does not know when it should read info, and I wonder how to do this. Preferably, I'd like to learn how to do this asynchronously, if that's at all possible.Northman
U
0

Hi I created a Simple library for this: cArduino https://github.com/ranma1988/cArduino C++ can find auto find connect Arduino port, read, write

Uranography answered 15/7, 2014 at 10:34 Comment(1)
Self promotion is considered spam, here on SO.Incomer

© 2022 - 2024 — McMap. All rights reserved.