OBJECTIVE :- To achieve serial communication between arduino
and the C++ program. I am using processing as an intermediate program which performs some operation over data and then passes those values to the arduino serially!
I have a C++ program which writes a data to a file at regular intervals,say UFR,90,87
to a file at every 30 milliseconds. The file being written is done in truncating mode,i.e., the file is overwritten every 30 ms.
Next, there is a processing code which has to fetch that value from file as soon it get's written. The C++ code is executed first and then the processing code. The processing code is using BufferedReader
to read the contents of the file.
How should I enable synchronisation between the two programs so that the value just written by C++ program is read simultaneously(minor lag,less than 5-10 ms is acceptable) by Processing code and there is perfect synchronisation? There shouldn't be any mis-communication. Should I establish some kind of mutex lock/semaphore/something over the file between successive reading/writing?
Also, I am running C++ program from the terminal and the processing code from the processing IDE(GUI). The Operating system being used is Ubuntu 14.04/CentOS 7 Linux.
ALSO, SUGGESTION REQUIRED :- Would anyone please suggest me a better approach for establishing direct communication between arduino and C++ program. I was able to successfully transmit data with direct tranfer,but,not receive acknowledgement properly from arduino. We have to receive acknowledgement from arduino too which fails to acknowledge that the data has been received successfully. I tried sending data using the GNU screen emulator but it didn't acknowledge back the data received. Hence, I had to use this intermediate approach using Processing!