This closes a file. When all read and write operations are done, close the file to avoid accidental write operations if the media is removed or an error occurs in the program to avoid data corruption.
Input:
fd : FILE
FILE descriptor for the file retrieved from fsFileOpen or fsFileCreate.
Returns: INT
0
|
- File closed.
|
-8
|
- File not open.
|
-16
|
- Media not present.
|
-22
|
- Media is busy.
|
Declaration:
FUNCTION fsFileClose : INT;
VAR_INPUT
fd : FILE;
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
...
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
...
END_IF;
...
|