SD

Module NameSD
Import NameSD

Program Examples

Init

Function Init() As Byte

Init SD card and read file system. Will return one of the following values:

  • errOK
  • errNoResponse
  • errInvalidFormat
  • errRWError

DirExists

Function DirExists(dir As String) As Boolean
  • dir - Name string - can be a constant, variable or string expression.

Returns true if a directory exists, false otherwise.

ChDir

 Function ChDir(dir As String) As Boolean
  • dir - Name string - can be a constant, variable or string expression.

Change the directory. Returns true if success, false otherwise.

RmDir

 Function RmDir(dir As String) As Byte
  • dir - Name string - can be a constant, variable or string expression.

Remove an existring directory. Will return one of the following values:

  • errOK
  • errNotFound
  • errDirNotEmpty
  • errRWError

MkDir

Function MkDir(dir As String) As Byte
  • dir - Name string - can be a constant, variable or string expression.

Make a new directory. Will return one of the following values:

  • errOK
  • errExists
  • errDiskFull
  • errRootDirFull
  • errInUse
  • errRWError

FileExists

  Function FileExists(filename As String) As Boolean
  • filename - Name string - can be a constant, variable or string expression.

Returns true if found, false otherwise.

Open

 Function Open(filename As String) As Byte
  • filename - Name string - can be a constant, variable or string expression.

Opens a file for reading or writing. Will return one of the following values:

  • errOK
  • errNotFound
  • errInUse
  • errRWError

Close

Sub Close()

Close a file previously opended with a call to Open.

Create

 Function Create(filename As String) As Byte
  • filename - Name string - can be a constant, variable or string expression.

Create a new file on disk and open it. Will return one of the following values:

  • errOK
  • errExists
  • errDiskFull
  • errRootDirFull
  • errInUse
  • errRWError

Delete

Function Delete(filename As String) As Boolean
  • filename - Name string - can be a constant, variable or string expression.

Delete an existing file. Returns true if file deleted, false otherwise.

Append

 Function Append(filename As String) As Byte
  • filename - Name string - can be a constant, variable or string expression.

Open an existing file for writing to end of file. Will return one of the following values:

  • errOK
  • errNotFound
  • errDiskFull
  • errRootDirFull
  • errInUse
  • errRWError

Rename

Function Rename(oldFilename As String, newFilename As String) As Byte
  • oldfilename - Name of file to rename - can be a constant, variable or string expression.
  • newfilename - Name of new file - can be a constant, variable or string expression.

Rename a file. Will return one of the following values:

  • errOK
  • errExists
  • errNotFound
  • errRWError

Position

Function Position() As UInteger

Returns the current file position, in bytes.

EOF

 Function EOF() As Boolean

Returns true if a file opened for reading has reached the end of file, false otherwise.

IsFull

 Function IsFull() As Boolean

Returns true if the SD card is full, false otherwise.

Write

  "Compound" "Sub" Write(item)
  • item - Can be a byte or string constant, variable or expression.

Writes multiple values to an open file.

WriteByte

 Sub WriteByte(data As Byte)

Write a single byte value to an open file.

Read

  "Compound" "Sub" Read(item)
  • item - Can be a byte or string variable.

Reads multiple values from an open file.

ReadByte

 Function ReadByte() As Byte

Read a single byte from an open file.

Seek

 Function Seek(position As UInteger) As Byte
  • position - File position to locate.

Seek a position within an open file. Will return one of the following values:

  • errOK
  • errRWError
  • errFileNotOpen
  • errBeyondEOF

Size

  Function Size() As UInteger

Returns the size of an open file, in bytes.

FindFirst

 Function FindFirst(optional fileType As Bit = sdFile) As String(13)
  • fileType - Can be sdFile or sdDirectory

Read the first file or directory name. If the file or directory is not found, an empty string is returned. Note that the string will be padded to 8:3 format with spaces.

FindNext

  Function FindNext(Optional fileType As Bit = sdFile) As String(13)
  • fileType - Can be sdFile or sdDirectory

Read the next file or directory name. This routine is usually called after FindFirst. For example:

' file imports...
imports SD                         

' main program entry point...
sub Main()  
   dim sdAvailable as boolean = SD.Init() = errOK 

   if not sdAvailable then    
      Console.Write("SD not available...")
   else
      dim name as string = SD.FindFirst()
      while Name <> nothing 
         Console.Write(name,13,10)
         name = SD.FindNext()
      end while
   end if
end sub

If the file or directory is not found, an empty string is returned. Note that the string will be padded to 8:3 format with spaces.