Read/write to pc files with prop
Mauvai
Posts: 45
I am trying to rapidly collect data (~200Hz) with the prop and export it to a pc for analysis. The code I am using is as follows:
This however doesn't do a whole lot. Any suggestions?
#include <stdio.h> #include <propeller.h> int main() { char name[20]; FILE *fp1; waitcnt(CLKFREQ+CNT); // pause for terminal to open sprintf(name,"Test"); // test file name printf("Opening file '%s'.\n", name); char sentence[] = {128, 13}; fp1=fopen("myfile.txt", "w"); if(fp1==0) { printf("File was opened.\n"); fputs (sentence,fp1); fputs("\nHI", fp1); fclose(fp1); } else { printf("Can't open file %s.\n",name);; } while(1); return 0; }
This however doesn't do a whole lot. Any suggestions?
Comments
If possible I want to export to pc over the USB, I don't have an SD card setup
To work with files on your PC, you'll need to send them via some sort of communication port. Generally, this means a serial port. You can use Simple Librarie's print and printi, PropGCC's printf (or tiny printf), or any number of UART/RS232 drivers. Take a look at PropWare's UART classes, libpropeller's Serial classes, Simple Librarie's FDSerial functions, and others.
On the PC side, you'll need to write your own application to read the serial console and copy the data to a file.
If you require more than 57 characters per data interval you could buffer the data into memory and dump it out later. This assumes you only need to buffer a few kilobytes of data, and there is enough space in hub RAM to buffer it. Another possibility is to run the serial port at a higher rate. The full duplex serial driver should be able to handle 230,400 baud, and maybe even higher than that.
Are you familiar with the structure of a circular buffer? If single-cog performance becomes a problem, I'd recommend a writing to a global, circular buffer from your data collector cog and reading from that buffer in your UART cog. Assuming you're doing write-only out the serial port (never taking input from the PC), PropWare's unbuffered UART classes would work great for this (and in LMM mode, they can reach an average of 673,230 bits/second at ~1.4MHz).
There are other implementations that are even faster, but I'll refer you to this thread for those.
Also, i probably wont implement this... I don't have any experience writing code to control the hyperterminal from the pc, and i dont need it all that badly - i can come up with a way of processing on chip if i need to. thanks though
http://technet.microsoft.com/en-us/library/cc738294(v=ws.10).aspx
If you want to do it via your own program, there are lots of ways. A couple years ago, my senior design team wrote a program that monitored various parameters from a car and communicated them via UART to a PC, where they were displayed in a Java GUI. The Java program communicated directly with the computer's COM port - no need for hyperterminal in the middle
I'm working on pulling up that code.... i'll post it when I find it.