fsFileOpen (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


This will open an existing file for reading and writing. The function returns a FILE descriptor (ID) for the file, and it is necessary to verify that the file has been successfully opened with the fsFileStatus function. The data pointer used when reading and writing data will always point at the end of file when opened.

It is possible to have 16 files open simultaneously - each with a unique FILE descriptor.

 

 

Input:                

name : STRING

Name of the file to open. Both absolute and relative paths are allowed.

 

Returns: FILE

FILE descriptor. Use the fsFileStatus to verify the operation.

 

Declaration:

FUNCTION fsFileOpen : FILE;
VAR_INPUT
   name : STRING;
END_VAR;

 

 

Example:

...
IF fsFileExists(name := "gpslog.dat") THEN
   fd := fsFileOpen(name := "gpslog.dat");
ELSE
   fd := fsFileCreate(name := "gpslog.dat");
END_IF;
IF fsFileStatus(fd:=fd) = 0 THEN
   // File open, write data
   ...
   fsFileWrite(fd := fdbuffer := ADDR(gps.latitude), length := SIZEOF(gps.latitude));
   fsFileWrite(fd := fdbuffer := ADDR(gps.longitude), length := SIZEOF(gps.longitude));
   ...
   fsFileClose(fd := fd);
ELSE
   // Error when opening/creating file
   ...
END_IF;
...