21 usb – Rice Lake iRite IDE User Manual
Page 85

920i
Programming Reference - API Reference
81
5.21 USB
User program access to the USB file system requires new APIs for the user program to manipulate and use these
files. A user program may have only one file open at a time. Once opened, any further file accesses will be to that
file.
USBFileOpen( filename : string; mode : FileAccessMode ) : Syscode
This API is used to read a file from the flash drive. Opening a file as Read positions the internal pointer at the
start of the file. Opening a file as Create or Append positions the internal pointer at the end of the file. Any
attempt to read a file opened as Create or Append will return SysEndOfFile.
Parameters:
Filename
-
The 920i will look in a folder named whatever the 920i's UID is set for (defaulted to 1) for the
filename sent as the parameter. Use the entire path (without the drive). For example, if your file is stored on C:/
Examples/USB/Testing.txt the parameter would be:
Examples/USB/Testing.txt
FileAccessMode
-
A new enumeration (see Section 4.0) with the choices of FileCreate, FileAppend, or
FileRead.
SysCode values returned:
SysOk
SysNoFileSystemFound
SysPortBusy
SysFileNotFound
SysDirectoryNotFound
SysFileExists
SysInvalidFileFormat
SysBadFilename (over 8 characters)
SysEndOfFile
Example:
USBFileOpen(Testing.txt, FileCreate);
--Creates a new empty file called Testing.txt.
USBFileOpen(test,FileAppend);
--
Adds to a currently stored file called Testing.txt
USBFileOpen(test,FileRead);
--
Reads from a currently stored file
USBFileClose()
This API is used to close a currently opened file (see USBFileOpen). A file must be closed before device
removal or the file contents may be corrupted.
No parameters.
SysCode values returned:
SysOk
SysNoFileSystemFound
SysMediaChanged
SysNoFileOpen
USBFileDelete( filename : string )
This API deletes a file saved to the USB drive. To overwrite an existing file, the user program should first delete
the file, then reopen it with Create access.
Parameters:
Filename
- The 920i will look in a folder named whatever the 920i's UID is set for (defaulted to 1) for the
filename sent as the parameter.
SysCode values returned:
SysOk
SysNoFileSystemFound
SysPortBusy
SysFileNotFound
SysDirectoryNotFound
SysBadfilename
Example:
USBFileDelete(Testing.txt);