FATEngine filename issue
TCP71
Posts: 38
I have a (probably simple) question. I'm using SD3.01_FATEngine and have mounted the disk and can manually write a file to it. I need to create/write to a file using a filename that I have stored in a variable string and changes every time I have new data to write. The filename is always 8.3 bytes and contains a ASCII characters. My code looks something like this:
VAR
Byte FileName[11] 'String of the latest filename
Byte CardData[400] 'Data to be written
Pub WriteFile | Counter, Char
Card.newFile(FileName[0..11])
Card.openFile(FileName[0..11)
Counter := 0
repeat
Counter++
Card.writeByte(CardData[Counter])
until (CardData[Counter] == $0A)
Card.closeFile
How do I format the "FileName[0..11]" part to take the 12 ASCII characters as the filename for newFile to use?
Any and all help, again, appreciated.
VAR
Byte FileName[11] 'String of the latest filename
Byte CardData[400] 'Data to be written
Pub WriteFile | Counter, Char
Card.newFile(FileName[0..11])
Card.openFile(FileName[0..11)
Counter := 0
repeat
Counter++
Card.writeByte(CardData[Counter])
until (CardData[Counter] == $0A)
Card.closeFile
How do I format the "FileName[0..11]" part to take the 12 ASCII characters as the filename for newFile to use?
Any and all help, again, appreciated.
Comments
I am also having problems detecting whether a file exists or not.
If I know correctly --- You can only use 8+3 type filenames.
12345678.123
VAR
Byte FileName[11] 'String of the latest filename
The 11 bytes that make up the 8.3 filename are from 0 to 11(including the period). I need to get them from the FileName[11] into newFile(xxxxxxxx.xxx) position so newFile will use the name to create the file on the disk. For example, my variable FileName[11] contains the ascii characters "ITSATEST.TST" in order from 0 to 11. How do I get CARD.newFile(xxxxxxxx.xxx) to accept my FileName variable as an actual filename to use?
I don't looked on FATEngine - But normally in DOS You need omit period before You send that to write to Directory name
12345678123
What is the easiest way to create a dynamic filename string according to the date to pass to FATEngine?
For example, If I want the file name to be
ATDDMMYY.TXT
where DD is the date, MM is the month and YY is the 2 digit year.
SPIN does not have a sprintf command...
str[ 2 ] := (day / 10) + "0"
str[ 3 ] := (day // 10) + "0"
You do the same sort of thing for the month and year, use bytemove to copy in the "AT" and the ".TXT" with its zero byte terminator.
The code is using the fsrw object (Drv) for writing to the disk. SimplNum is the Simple_Numbers object. Str is the Strings2 object.
FNAMESIZE = 15; fname is declared as byte fName[FNAMESIZE]. The date and time values are hub variables that are updated from a timekeeping cog.
I then want to create a file on my SD card using FATEngine's function, newFile("06151120.162"). I just don't know how to make each respective Character in the array "FileName" be usable by newFile. It just errors out and wont compile. I can easily create the same file over and over again (eg. newFile("12345678.901") and it will create the file without issue, but I need to populate the actual newFile("XXXXXXXX.XXX") with my array of characters.
I kind of see how you are filling bytes at @fname with your time and date info. I guess I need to try filling a location of bytes in memory with my file name (06151120.162 in the example above), then point the function "newFile" in the FATEngine object to that location in memory? How does newFile know when to stop looking at the memory locations and the file name is complete. Is that the null character that needs to be at the end of the 8.3 array? I don't have any code in front of me currently, but I don't recall ending the manual file (that has the same file name all the time) with a null character, but I could be wrong.
The reason I'm using FATEngine and not FSRW is that I need to be able to clear all the files from the card using a simple user interface (I've got that working already, I just reformat the card and it works fine).
If there is an easier object to use to do this, I'm not stuck on FATEngine. The Fat16/32 full system driver would be fine, but I haven't looked at it. Thanks for all the help.
One more question,
How do I detect the existence of a file in uSD using FATEngine?
Edit: I tested. It worked.
Oh, ... thanks Kuroneko-san.
I appreciate all the help.