SDFileSystem Records

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

SDFileSystem Records

Post by dman776 » Tue Apr 22, 2008 10:14 pm

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 

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Wed Apr 23, 2008 6:08 am

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.

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Wed Apr 23, 2008 6:44 pm

Thanks Steven. That fixed it right up.

Post Reply