We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
I ran into a problem when using the Serial library. I have an Arduino program that sends data through the serial transmitter. The arduino is connected to a Raspberry Pi where a processing program collects the data and prints them to a txt-file. The txt-file is overwritten every time there is new data from arduino. With the help of the serial library and Printwriter, this has worked well. Until now...
Now suddenly with each transmission, the writing to the file goes slower and slower. There are no error messages in the processing editor.
Any ideas?
Thanks in advance
Answers
How about writing to the file only when the program closes, storing the data until then. Or maybe use multithreading, though that would be difficult.
I assume you mean just writing to the file one time? The purpose of the txt-file is for it to work as a database that is updated continuously. Here's my code:
Do you have any other suggestions? Thanks for your time : )
put some timing debug printlns around the actual writing.
and give us some idea of the data that's being written. it's not just a case that the data is growing with time, is it?
(and why are you overwriting the same file again and again?)
As I mentioned I use the txt-file as a database. The values that I get in from arduino comes in the form of a json string {"in":x, "out":y}. Then I have a JavaScript that reads the values of the json-objects. I overwrite the file since the program will be running for a long time, and I don't want the file to be too large.
JavaScript? Where?
The JavaScript is irrelevant to the problem. I figured out the slowdown was due to a memory leakage. The conditions for creating the file was always true, since I mistakenly used != comparison when I really should have used !string1.equals(string2). When I changed that, it solved the problem.
@hejhej -- thank you for sharing how you found the problem and your resolution.