The following functions enable sequential read / write operations in disk files:
F_ROPEN
open a file for reading
F_WOPEN create or reset
a file and open it for writing
F_AOPEN create or open
a file in append mode
F_CLOSE close an open
file
F_EOF test
if the end of file is reached in a file open for
read
FA_READ read a DINT
integer from a binary file
FA_WRITE write a DINT integer
to a binary file
FM_READ read a STRING
value from a text file
FM_WRITE write a STRING value
to a text file
FB_READ read binary data from a file
FB_WRITE write
binary data to a file
F_EXIST
test if a file
exist
F_GETSIZE
get the size of a file
F_COPY copy a file
F_DELETE
remove a
file
F_RENAME
rename a file
Related function blocks:
LogFileCSV log values of variables to a CSV file
Each file is identified in the application by a unique handle manipulated as a DINT value. The file handles are allocated by the target system. Handles are returned by the Open functions and used in all other calls for identifying the file.
Important notes
|
F_ROPEN: open a file for reading
ID := F_ROPEN (PATH);
PATH : STRING name of the file - the file must exist
may include a path name according to target
system conventions.
ID : DINT ID of the
open file or NULL if the file cant be read
F_WOPEN: open a file for writing
ID := F_WOPEN (PATH);
PATH : STRING name of the file
may include a path name according to target
system conventions.
ID : DINT ID of the
open file or NULL if the file cant be open
If the file does not exist, it is created. If the file already exists, its contents is cleared.
F_AOPEN: open a file in "append" mode
ID := F_WOPEN (PATH);
PATH : STRING name of the file
may include a pathname according to target
system conventions.
ID : DINT ID of the
open file or NULL if the file cant be open
If the file does not exist, it is created. If the file already exists, it is open at the end for append.
F_CLOSE: close an open file
OK := F_CLOSE (ID);
ID : DINT
ID of the open
file
OK : BOOL
return check: TRUE if
successful
F_EOF: test if end of file is encountered
OK := F_EOF (ID);
ID : DINT
ID of a file open for
reading
OK : BOOL
TRUE if the end of file has
been encountered
F_EOF must be used only for files open in read mode by the F_ROPEN function.
FA_READ: read a DINT value from a file
Q := FA_READ (ID);
ID : DINT
ID of a file open for
reading
Q : DINT
read value or 0 in case or
error
Integer values read by FA_READ must have been written by the FA_WRITE function. Integers are stored in binary format in the file, using memory conventions of the target system.
FA_WRITE: write a DINT value to a file
OK := FA_WRITE (ID, IN);
ID : DINT
ID of a file open for
writing
IN : DINT
integer value to be
written
OK : BOOL return
check: TRUE if successful
Integers are stored in binary format in the file, using memory conventions of the target system.
FM_READ: read a STRING value from a file
Q := FM_READ (ID);
ID : DINT
ID of a file open for
reading
Q : STRING
read value or empty string
in case or error
This function is intended to read a text line in the file. Reading stops when end of line character is encountered. Reading stops when the maximum length declared for the return variable is reached.
FM_WRITE: write a STRING value to a file
OK := FM_WRITE (ID, IN);
ID : DINT
ID of a file open for
writing
IN :
STRING string value to be
written
OK : BOOL return
check: TRUE if successful
This function writes a text line in the file. End of line character is systematically written after the input string.
FB_READ: read binary data from a file
OK := FB_READ (ID, V);
ID : DINT
ID of a file open for
reading
V :
ANY variable to be read (cannot be string)
OK : BOOL
return check: TRUE if successful
Variables are stored in binary format in the file, using memory conventions of the target system.
FB_WRITE: write binary data to a file
OK := FB_WRITE (ID, V);
ID : DINT
ID of a file open for
writing
V :
ANY variable to be written (cannot be string)
OK : BOOL return
check: TRUE if successful
Variables are stored in binary format in the file, using memory conventions of the target system.
F_EXIST: test if file exist
OK := F_EXIST (PATH);
PATH : STRING name of the file
may include a pathname according to target
system conventions.
OK : BOOL TRUE if the
file exists
F_GETSIZE: get file size
SIZE := F_GETSIZE (PATH);
PATH : STRING name of the file
may include a pathname according to target
system conventions.
SIZE : DINT Size of the file
in bytes
F_COPY: copy a file
OK := F_COPY (SRC, DST);
SRC : STRING name of the source file (must exist)
may include a pathname according to target
system conventions.
DST : STRING name of the
destination file
may include a pathname according to target
system conventions.
OK : BOOL TRUE if
successful
F_DELETE: remove a file
OK := F_DELETE (PATH);
PATH : STRING name of the file (must exist)
may include a pathname according to target
system conventions.
OK : BOOL TRUE if
successful
F_RENAME: rename a file
OK := F_RENAME (PATH, NEWNAME);
PATH : STRING
name of the file (must exist)
may include a pathname
according to target system conventions.
NEWNAME : STRING new name for the
file
OK : BOOL TRUE if successful