Using Serial port output data for C programming

Im new with arduinos, so even if there is a topic about that, I dont know what to search for :~. Im taking data from a sonar, and want to use the output for a C program on my PC, but for that I would have to keep something like a .txt file with the data I need (last 10 sonar sacans) that my computer could acces. How can I do that? I have puttin, but not shure how I can use that to save constantly a number of scans.

Tnx in advanced.

Im taking data from a sonar, and want to use the output for a C program on my PC, but for that I would have to keep something like a .txt file with the data I need (last 10 sonar sacans)

You could open the Com:n port (n= port number) using C.... Specific to your flavor of C. Same idea for Visual Basic, Java, Excel, etc.

You could use a Leonardo and use HID over USB to make C "think" you were typing in the data in realtime.

You could use a console redirect (command window) to redirect the serial port to a file. Since the file handle is open to the redirect, you'll need to research how to open an "already open" file. Or, build a more intelligent batch file to count off 10 lines and open another redirect with something like a 001, 002, file suffix.

Ray

Bicho:
want to use the output for a C program on my PC, but for that I would have to keep something like a .txt file with the data I need (last 10 sonar sacans)

If I were you I'd design it so that there was a long-running process on the PC which read readings from the Arduino serial port and made them available to your 'C program'.

If you C program is long-running - or you don't mind having to wait for it to receive ten samples at startup - then the C program itself could do the whole thing. Otherwise, your long-running program will need to make the most recent ten rows available to the C program in some way. A shared text file isn't a brilliant way to pass the data because you have to deal with file locking issues but if you're comfortable with that level of technology then it could be made to work. Given a free choice I'd suggest dumping the data into a relational database and then chucking away the old data as it becomes obsolete - it's overkill in this case but gives you reliable shared storage independently of the two applications accessing it, and being able to keep them completely isolated eliminates a whole load of potential headaches.

General help for writing programs to interface with an Arduino -- if you want to run the data "live":
http://playground.arduino.cc/Main/InterfacingWithSoftware

You can also save the data to a file on an SD card and then mess with it later:

Shows various boards that allow use of an SD card: