Create file name from incoming serial string
at_jay
Posts: 16
I want to creat a new file using fopen function but instead of declaring the file name as
fopen () argument e.g. fopen("abc.txt") I want to use serial received string of 9 characters
E.g name.txt including 0 as end of string. Please guide me how to do this in spin.
Thanks
Jay
fopen () argument e.g. fopen("abc.txt") I want to use serial received string of 9 characters
E.g name.txt including 0 as end of string. Please guide me how to do this in spin.
Thanks
Jay
Comments
Now my next question,which is quite basic, is how I can I write a file with stream of serial in coming data?
Do I need to define a local buffer (of type BYTE) that receives the in coming stream first and then write on SD card ? if yes then whats the maximum size of buffer I need to set? or?
Also the in coming stream is variable then how to effectively exit from the write operation after certain interval of time when no data is coming?
Cheers
Jay
Get a piece of paper and sketch a basic flow design.
I started using Byte buffer of size 512 for storing in coming serial stream that needs to be written into SD card.
Is it worth to use multiple buffers for handling stream of size greater than 512 bytes?
Also your opinion of using dedicated cog for write operations?
Thanks
Jay
If you can buffer all the data in memory then just read all the bytes into a big buffer and then write it to a file with a single write call. If you can't buffer all the data I would suggest that you use a seperate cog to read the data into two ping-ping buffers. Each buffer should be able to hold about 1 second's worth of data. Your main cog would then write each buffer to the file when it fills up. You would need a flag or two to indicate when a buffer is ready to be written, and when it has been emptied.
Here I struggled with serial receive-and-sd-write-problem.
My implementation loses bytes from time to time. SD driver can't write as fast as serial receiver gets bytes from PC.
Now I got a problem and is that :
at first time I use "w" to creat and write a new file (abcdefgh.txt", but later on I used the same file with "a" append option. But what I want is that when I go for second fresh download to SD card with the same file name (abcdefgh.txt) it appends in stead of creating the same file once more. What I saw in the file the same text is repeated twice like as the new file was not created and written to same file.
How do I creat a new file each time I go for fresh download?
I think a
sdfat.seek(0) will do that for you.hm. FileSeek? sorry I use kye's sd-driver, but fsrw has something like this for sure.
or delete the file if it is there and then recreate a new one ...
enjoy!
Mike
If you want to keep the file name and not the new data, then use the 'w' parameter not the 'a'.
I want to creat the file name (as received serially in 8.3 format), which is same each time. I want to append the created file only during ping-ping buffer writing loop. Once after the file is closed and before the new download to SD card I want to delete the previous file first and then start to open and write the new file.
sdfat.seek(0) does't work, what should I do to delete the exisiting files? or to overwrite the file with same name?
Comments from readme.spin