SDFileSystem
Moderators: David Barker, Jerry Messina
SDFileSystem
Hi Steven,
In the routine listed below as I using the filesize() routine correctly ?
I am expecting a long word back, but what I don't understand is does the filesize() routine only work if I have a file open so it knows which one I want ?
Thanks
If SD.OpenFile("file.bin") = errOK Then
repeat
// Do Something
// Get FileSize
MyFileSize = SD.FileSize() // My filesize now holds the size of file.bin
until SD.EOF
In the routine listed below as I using the filesize() routine correctly ?
I am expecting a long word back, but what I don't understand is does the filesize() routine only work if I have a file open so it knows which one I want ?
Thanks
If SD.OpenFile("file.bin") = errOK Then
repeat
// Do Something
// Get FileSize
MyFileSize = SD.FileSize() // My filesize now holds the size of file.bin
until SD.EOF
Yes, you are right about having to open a file before using FileSize. In your example above though you open the file, then enter a repeat loop until you get to the end of the file, but without incrementing your way through the file by reading from it - this will lock you in the repeat loop. Try something like below:
Code: Select all
If SD.OpenFile("file.bin") = errOK Then
MyFileSize = SD.FileSize() // My filesize now holds the size of file.bin
SD.CloseFile
EndIf
Thanks Steven
Thanks for the help
Is it possible to have more than one file open with the SD module?
The scenario that I'm looking to do is like the following...
1) open a data file and read bytes from it that would be sent to the USART
2) open an MP3 file on the SD card and stream it to a VLSI audio decoder
The data files would typically be anywhere from 2K to 20K in size (so, they won't fit in a RAM buffer).
Thanks
The scenario that I'm looking to do is like the following...
1) open a data file and read bytes from it that would be sent to the USART
2) open an MP3 file on the SD card and stream it to a VLSI audio decoder
The data files would typically be anywhere from 2K to 20K in size (so, they won't fit in a RAM buffer).
Thanks
Not as the module stands at the moment. It's one of my future plans and one that I've been thinking about in the last few days as it happens. When I ported the code to Swordfish I built in a fair amount of code that should make this relatively easy. I'm not promising when I'll do it, but it's in the pipeline. For now, could you get away with opening one, buffering some of it, closing it then opening the other, using FSeek to quickly move to the next point in the file, and so on...? I guess it may not be fast enough if you are sending an MP3 file?
Steve
Steve
I am also having trouble reading a file from my SD card.
My file byte data like this (shown in hex): FF 01 02 FF 04 05 .... etc
However the vByte variable always returns a "0".
any thoughts?
Code: Select all
If SD.OpenFile("SEQ_01.DAT") <> errOK Then
// get delay and setup timer
vByte=SD.ReadByte()
if SD.RWError = False then
SetDelay(vByte)
LCD.WriteAt(2,1,Convert.DecToStr(vByte))
else
LCD.WriteAt(2,1,"RWError")
end if
Else
LCD.WriteAt(2,1,"!open")
EndIf
However the vByte variable always returns a "0".
any thoughts?
Here is the init using MSSP...
resonator is 10Mhz using the HSPLL (40Mhz)
Code: Select all
While Not SD.Init(spiOscDiv16)
LCD.WriteAt(2,1,"Insert card")
Wend
Ooops, missed an error in your first code. It should be:
not:
Does that fix it, or is there more to it?
Steve
Code: Select all
If SD.OpenFile("SEQ_01.DAT") = errOK Then
Code: Select all
If SD.OpenFile("SEQ_01.DAT") <> errOK Then
Steve
Steven,
Are you thinking of adding a ReadNBytes() function to the SD module?
I think it would be nice to be able to buffer a chunk of data.
I'm thinking of something like this (from the ISRRX module):
Are you thinking of adding a ReadNBytes() function to the SD module?
I think it would be nice to be able to buffer a chunk of data.
I'm thinking of something like this (from the ISRRX module):
Code: Select all
Public Function ReadNBytes(ByRef pRetBuf As Byte, ByVal pCount As Word) As Word
Dim vByte As Byte
Dim RetBuf As POSTINC0
FSR0 = AddressOf(pRetBuf)
Result = 0
While pCount>0
vByte = SD.ReadByte()
RetBuf = vByte
Inc(Result)
Dec(pCount)
Wend
RetBuf = 0
End Function
Last edited by dman776 on Thu Feb 21, 2008 8:27 pm, edited 1 time in total.