Posts: 17
Joined: Wed May 01, 2013 11:57 pm

Log data to file.

Mon Oct 28, 2013 3:21 am


I wish to log data from a Arduino at 50sps (binary), then copy the last n bytes every 5 minutes, following time (ex: 13:05, 13:10).

What i thought:
-Continuously save data to file A, every 5 minutes remove last n bytes from file A and copy content to file B.

But i´m a bit concerned if i will loose data when copying the content, example: if the script takes 1 second (ex) to copy the content to another file, will i loose 1 second of data? I can always check the size of the file and insert some "0" or remove some bytes just to have the correct size, but i really wish not to loose data.

Any other suggestion to accomplish what i want, is welcome! :)

Best regards.

User avatar
Posts: 2422
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Log data to file.

Tue Oct 29, 2013 2:06 pm

@nadabro, will the serial reading mechanism not buffer data while you're doing something else? I would have thought it would be ok, however might be nicer to collect the data in a buffer in python and write it to file A then occasionally write n bytes to file B

Posts: 189
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Log data to file.

Tue Oct 29, 2013 2:46 pm

I don't know python, I'd do it in bash.

cat /dev/ttyAMA0 > fileA &

This continuosly writes all data to fileA in a background process. Then, every five minutes, do

tail -c $n fileA >fileB

This will copy the last $n bytes of fileA to fileB. The bytes will however not be removed from fileA. It is quite safe, the copying will not cause any data to be lost.

Return to “Python”