I'm a beginner in programming, and I must write a plug-in in C++ in a preexisting program (for a project). I'll spare you the details, but I must communicate with an Arduino (USB connected, serial communication), send and read data. I already know how to write to the Arduino device, but I don't know how to read the data from the Arduino ?
To send data to the arduino, I simply use that :
string device ("/dev/ttyACM0 ");
string cmd ("Threshold reached");
system ( (device + cmd).c_str () );
I would like it very much if the reading was as simple as the writing :D
Thank you for your answers
edit : The program runs on lUbuntu and (2 different computers) Ubuntu 14.10 Reedit :
I found a program in c that works juste fine, I compile it and call the binary thanks to "system", it works too. Here is a link to the explanations :https://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/
I know now how to read and write, there's only one issue left : recognizing the data that I'm interested in. So far i've got : string readings = system (./arduino-serial -b 9600 -p /dev/ttyACM0 - r); (is this accurate ? can i put that in a variable ?)
if (readings == "dR:") { int requestedDensity = /that's my issue/;} In my computer's buffer, I'll receive all sort of datas, like, "Asked Temperature 9 : 25 / Humidity : 74 / dR: 80/door 1 opened" and I want to start reading after "dR:" and stop before " / ". Will my condition work ? Will the program start reading just after dR: ?
Then, if that's true, if I convert it like that int requestedDensity = std::stoi (readings); , will it stop reading as soon as it reads something not convertible ? Will it stop at "/" without any errors ? (unfortunately i'm running out of time for my project so I can't really afford to try every answer i find...)
<
– starksystem
, they say it "executes the command specified". What command did you specify?) – David Schwartz