Page 1 of 1

SDFileSystem Records

Posted: Tue Apr 22, 2008 10:14 pm
by dman776
I'm trying to use the Records features of the the SDFilesystem module (4.0.9), but, am getting strange results.

The following code snippet always displays "00000000.000" on my LCD instead of the expected "abcdefghijkl".

Any clues to why?

Code: Select all

    Repeat
    Until SD.Init()=errOK
    LCD.WriteAt(2,1,"ok            ")
    DelayMS(250)

// write schedule
    LCD.WriteAt(2,1,"deleting      ")
    SD.DeleteFile("SCHED01.CFG")
    LCD.WriteAt(2,1,"creating new  ")
    SD.NewFile(FSCHEDULE,"SCHED01.CFG")
    SD.CloseAll()
    
    LCD.WriteAt(2,1,"opening       ")
    SD.OpenFileRW(FSCHEDULE,"SCHED01.CFG")

    Schedule.PlayOrder=1
    Schedule.SequenceFile="abcdefghijkl"
    SD.NewRecord(FSCHEDULE,AddressOf(Schedule))
        
    Schedule.PlayOrder=2
    Schedule.SequenceFile="12345678.012"
    SD.NewRecord(FSCHEDULE,AddressOf(Schedule))

    LCD.WriteAt(2,1,"saving        ")    
    SD.SaveAll
    SD.CloseAll

    Schedule.PlayOrder=99
    Schedule.SequenceFile="00000000.000"

    LCD.WriteAt(2,1,"opening       ")    
    // read schedule
    If SD.OpenFileRW(FSCHEDULE,"SCHED01.CFG") = errOK Then
        LCD.WriteAt(2,1,"Reading SCHED01")
        If SD.GetRecord(FSCHEDULE,0,AddressOf(Schedule)) = errOK Then
           LCD.WriteAt(1,1,Schedule.SequenceFile)
        Else
            LCD.WriteAt(1,1,"error getRec")
        EndIf
    Else
        LCD.WriteAt(1,1,"Error opening")
    End If 

Posted: Wed Apr 23, 2008 6:08 am
by Steven
When you open the file with

Code: Select all

    SD.OpenFileRW(FSCHEDULE,"SCHED01.CFG")
you also need to add the record length parameter at the end.

You need to work out the number of bytes in your structure for this. If you have problems with this, post your structure code.

Posted: Wed Apr 23, 2008 6:44 pm
by dman776
Thanks Steven. That fixed it right up.