TSDName???

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

TSDName???

Post by ohararp » Sun Nov 04, 2007 4:49 pm

Steven,

Do you have any example files usign the TSDName structure? I am having a little trouble setting up a routine using this format. I don't have any "good" code to post since I am just starting out on this adventure.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

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

Post by Steven » Sun Nov 04, 2007 8:42 pm

This is a simple example:

Code: Select all

Device = 18F452
Clock = 20

Include "USART.bas"
Include "SDFileSystem.bas"

Dim FileName As TSDName

FileName.Name = "TESTFILE"
FileName.Extension = "TXT"

SD.Init(spiOscDiv4)

SD.NewFile(FileName)
SD.CloseFile
Hope this helps - let me know if you need more.

Steve

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Tue Nov 06, 2007 4:22 am

Steven,

I was on the right path. Here is a snippet of code that will check for a file and will skip over it until that file is not found.

Code: Select all

Sub INIT_SD_CHECK_WRITE()
    Dim LOOPS_FL As Byte
    Dim CHECK As Boolean
    Clear(LOOPS_FL)
    Repeat 
        Select LOOPS_FL
            Case < 10
                FILE.Name = "DEVXX00" + DecToStr(LOOPS_FL)        'File Name, upper case only!
            Case < 100
                FILE.Name = "DEVXX0" + DecToStr(LOOPS_FL)        'File Name, upper case only!
            Case < 255    
                FILE.Name = "DEVXX" + DecToStr(LOOPS_FL)        'File Name, upper case only!
        EndSelect
        FILE.Extension = "GPX"                             'File Ext, upper case only!  
        CHECK = FileExists(FILE)                     'Check if file already exists
        Inc(LOOPS_FL)
    Until CHECK = FALSE
    SD.NewFile(FILE)
    SD.SaveFile()
End Sub
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

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

Post by Steven » Tue Nov 06, 2007 7:27 am

Hi Ryan,

Here is another version of your code that might help - I haven't compiled it, so don't know if it will actually compile to more bytes...

Code: Select all

Function INIT_SD_CHECK_WRITE() as Boolean 
Dim LOOPS_FL As Byte 
    FILE.Extension = "GPX"
    Clear(LOOPS_FL) 
    Repeat 
        FILE.Name = "DEVXX" + DecToStr(LOOPS_FL, 3)
        Inc(LOOPS_FL) 
    Until SD.NewFile(FILE) = errOK or LOOPS_FL = 0   
    INIT_SD_CHECK_WRITE = Not(LOOPS_FL = 0)
    SD.SaveFile() 
End Function
Regards,

Steve

OK, have now tried to compile - slightly less program bytes, but slightly more RAM - note that the code above returns a boolean (true if it's been able to open a new file).

Post Reply