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.
F_FLUSH  force the writing to the disk of the contents of the file open for writing
F_SEEK  set the current position of a file

F_SAVERETAIN  store RETAIN variables to a file.
F_LOADERETAIN  load RETAIN variables from a file

Fixed_Image See also

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.

attentionAttention

  • File are opened and closed directly by the Operating System of the target. Opening some files may be dangerous for system safety and integrity. The number of open files may be limited by the target system.
  • Opening a file may be unsuccessful (invalid path or file name, too many open files...) Your application should process such error cases in a safe way.
  • File management may be not available on some targets. Please refer to OEM instructions for further details about available features.
  • Valid paths for storing files depend on the target implementation. Please refer to OEM instructions for further details about available paths.
  • If you use a flash disk, it is your responsibility not to call write functions too often, in order not to destroy the flash. This particularly applies to F_SAVERETAIN function.

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_AOPEN (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.
OK : BOOL   return check: TRUE if successful.

Variables are stored in binary format in the file, using memory conventions of the target system.

FR_READ: read an array from a file

Q := FR_READ (ID, DATA, OFF, NB);

ID : DINT ID of a file open for reading
DATA : ANY    array of variables to be read. CANNOT BE STRING
OFF : DINT    offset in the array of the first read element
NB : DINT    number of elements to read
Q : DINT   number of elements actually read

Variables are stored in binary format in the file, using memory conventions of the target system.

FR_WRITE: write an array to a file

Q := FR_write (ID, DATA, OFF, NB);

ID : DINT ID of a file open for writing.
DATA : ANY    array of variables to be written. CANNOT BE STRING
OFF : DINT    offset in the array of the first written element
NB : DINT    number of elements to write
Q : DINT   number of elements actually written

Variables are stored in binary format in the file, using memory conventions of the target system.

F_FLUSH: store to disk contents of a file open for writing

OK := F_FLUSH (ID);

ID : DINT ID of a file open.
OK : BOOL   return check: TRUE if successful

F_SEEK: set the current position in an open file

OK := F_SEEK (ID, POS, ORG);

ID : DINT ID of a file open
POS : DINT relative position from the specified origin
ORG : DINT origin of the move:

0=beginning of the file
1=current position
2=end of the file

OK : BOOL   return check: TRUE if successful

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.

F_SAVERETAIN: save RETAIN variabes to a file

OK := F_SAVERETAIN (PATH);

PATH : STRING   name of the file
               may include a pathname according to target system conventions.
OK : BOOL      TRUE if successful.

F_LOADRETAIN: reload RETAIN variables from a file

OK := F_LOADRETAIN (PATH);

PATH : STRING   name of the file (must exist)
               may include a pathname according to target system conventions.
OK : BOOL      TRUE if successful.

File Management functions

IEC 61131-3 Automation platform > Programming - Reference guide > Advanced operations > File Management functions

Previous chapterNext chapter


Created with the Personal Edition of HelpNDoc: iPhone web sites made easy