How to change file names while writing to an SD card?
ElectricAye
Posts: 4,561
Hi all,
I've got a program that is writing data to an SD card.· In my wildest dreams, I·wish it could start a new file with one name, write data, close the file, then start up a second new file with a different name, write data, close that file, and so on and so forth for possibly thousands of files.· Ideally, of course, the file names would have some kind of sequential identifier, such as Name1, Name2, etc.· Currently, I am using the following to create a file:
Objects
sdfat: fsrw
sdfat.mount(0)·· {Start SPI communication at pin 0 of Propeller.}
{Open a file called 'Name1.csv' for writing comma separated data...}
status := sdfat.popen(string("Name1.csv"), "w")
So I think I would like to put some kind of string appending snippet thingy in here somehow with an index value that advances the name, but... I'm not sure where to even begin.·· Can anybody out there point me to the promised land?
many thanks,
Mark
I've got a program that is writing data to an SD card.· In my wildest dreams, I·wish it could start a new file with one name, write data, close the file, then start up a second new file with a different name, write data, close that file, and so on and so forth for possibly thousands of files.· Ideally, of course, the file names would have some kind of sequential identifier, such as Name1, Name2, etc.· Currently, I am using the following to create a file:
Objects
sdfat: fsrw
sdfat.mount(0)·· {Start SPI communication at pin 0 of Propeller.}
{Open a file called 'Name1.csv' for writing comma separated data...}
status := sdfat.popen(string("Name1.csv"), "w")
So I think I would like to put some kind of string appending snippet thingy in here somehow with an index value that advances the name, but... I'm not sure where to even begin.·· Can anybody out there point me to the promised land?
many thanks,
Mark
Comments
1. Stop where you are... don't go one step farther until you have ordered Andre's book. I made the same mistake... Andre's book should have been called "the Propeller Bible with Special Applications in the Areas of Game Development and Virtual Environments and if You Own a Propeller You Are an Idiot if You Don't Buy My Book." .... but I guess that would have been too easy for us to figure out[noparse]:)[/noparse]" By the way, for my money Andre's book has the best introduction to Propeller Assembly.
2. Generally speaking if you know what filenames you are going to be using, you put them in the Dat section and give them a variable name and then just refer to the variable. IF it doesn't work, you have the wrong syntax... If you promise to order Andre's book at some time in the future, I'll post some code for you in the morning.
If you want to ignore my first suggestion... any time you have a new problem, that isn't obvious after going through the corresponding Lab or section of the the Prop manual, crack open Mike Green's FemtoBasic... and look at how Mike does stuff. Everybody here wants to be like Mike... but it isn't Michael Jordan of which we speak so highly, it is Mike "the Answer Man" Green[noparse]:)[/noparse] There are some gleaned gems in PropDos by Oldbitcollector... he has borrowed from many of the luminaries, but puts it altogether in a nice package with a big payout.
3. By the way... even if you don't promise to order Andre's book... I'll still post the code in the morning unless someone beats me to it. It's on a different computer and it's just too far to move my keyster tonight.
Rich
ILMP
I learned a ton from reading and twisting his code in knots.
(A lot of what I learned from Femto was carried into PropDOS)
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
I'm tired... and when I'm tired, I write like I talk. I don't know what his nick is... but I'd like to.
Andre Lamothe http://www.league.org/2005cit/bios/lamothe.html
THE Book is "Game Programming for the Propeller-Powered HYDRA" It comes with a CD-ROM. It is in the Parallax Store
http://www.parallax.com/Store/Microcontrollers/PropellerProgrammingKits/tabid/144/txtSearch/hydra/List/1/ProductID/474/Default.aspx?SortField=ProductName,ProductName
thank you for your recommendations on Andre's Book. I already bought his SD Max card, which came with a description of FAT16, etc. And thanks to Andre, and Mike Green, OBC, SimonL, rayman, and many others, I have actually been able to get my Prop to communicate to an SD card, something that seemed impossible to me just a week ago. I seem to remember looking at the FemtoBasic at some point, but my first impression is that it was heavy on code and light on comments. Maybe I'm wrong about that. It's been a while. Generally speaking, I'm about as newbie as it gets around here, so if the material is not extremely dumbed down, I get lost pretty fast. I am not a computer dude but I leaped into this Prop thing two months ago so I could build instruments that utilize its parallel processors. Two months ago I knew absolutely nothing about the Propeller. Nor about object oriented programming. Now I have a system that continously reads six channels of temperature, 8 simultaneous channels of frequency, utilizes a real time clock, outputs some data onto a TV and reads tons of data onto an SD card in CSV format. And I've still got some pins left over. Somebody pinch me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It might be the Information Age but the Eon of Ignorance has yet to end.
Are you talking about AndreL ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It might be the Information Age but the Eon of Ignorance has yet to end.
About the comments in FemtoBasic... that is solved by having the crib sheet handy... what is the crib sheet? It is called the Quick Reference to Spin... and the Quick Reference to Propeller Assembly and it was created by ......................... and I think it is included in the download of the Prop Tool. Once you have figured out exactly what Mike is doing, it is usually pretty obvious why he is doing it.
The only problem is ... where are the quick reference guides?....that's my usual problem.