fsFileCreate (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This function will create a new file and return a FILE descriptor (ID) for the new file. When the function returns, it is necessary to verify that the file has been successfully created with the fsFileStatus function. The data pointer used when reading and writing data to the file will be initialized to point at the beginning of the file.

 

Note: if a file with the name already exists, it will be overwritten without warning; use fsFileExists to check if the file already exists.

 

Input:                

name : STRING

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

 

Returns: FILE

FILE descriptor. Use the fsFileStatus to verify the operation.

 

Declaration:

FUNCTION fsFileCreate : 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 := fd, buffer := ADDR(gps.latitude), length := SIZEOF(gps.latitude));
  fsFileWrite(fd := fd, buffer := ADDR(gps.longitude), length := SIZEOF(gps.longitude));
  ...
  fsFileClose(fd := fd);
ELSE
  // Error when opening/creating file
  ...
END_IF;
...