File Management Functions
Name | Use |
---|---|
F_AOPEN | Create or open a file in append mode |
F_CLOSE | Close an open file |
F_COPY | Copy a file |
F_DELETE | Remove a file |
F_EOF | Test if the end of the file is reached in a file that is open for reading |
F_EXIST | Test if a file exists |
F_GETSIZE | Get the size of a file |
F_RENAME | Rename a file |
F_ROPEN | Open a file for reading |
F_SEEK | Set the current position of a file |
F_WOPEN | Create or reset a file and open it for writing |
FA_READ | Read a DINT integer from a binary file |
FA_WRITE | Write a DINT integer to a binary file |
FB_READ | Read binary data from a file |
FB_WRITE | Write binary data to a file |
FM_READ | Read a string value from a text file |
FM_WRITE | Write a string value to a text file |
SD_ISREADY | Check that the SD card is ready for read/write |
SD_MOUNT | Mount an SD card |
SD_UNMOUNT | Unmount an SD card |
F_AOPEN
Open a file in "append" mode
ID := F_AOPEN (PATH);
PATH : STRING | Name of the file. Can include a path name according to target system conventions. |
ID : DINT | ID of the open file or NULL if the file can't be read |
If the file does not exist, it is created. If the file already exists, it is opened at the end for appending.
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_COPY
Copy source file contents to a destination file. Please note that large files will take a noticeable amount of time to complete. For example, a 1000KB file takes approximately 0.6 seconds. The output status is set after the file copy operation is complete.
OK := F_COPY (SRC, DST);
SRC : STRING | Name of the source file (must exist). Can include a pathname according to target system conventions. |
DST : STRING | Name of the destination file. Can include a pathname according to target system conventions. |
OK : BOOL | TRUE is successful |
F_DELETE
Remove a file
OK := F_DELETE (PATH);
PATH : STRING | Name of the file (must exist). Can include a pathname according to target system conventions. |
OK : BOOL | TRUE if successful |
F_EOF
Test if the end of a file is encountered
OK := F_EOF (ID);
ID : DINT | ID of the open file |
OK : BOOL | TRUE if the end of the file has been encountered |
F_EOF must be used only for files open in read mode by the F_ROPEN function.
F_EXIST
Test if file exists
OK := F_EXIST (PATH);
PATH : STRING | Name of the file, can include a path name according to target system conventions. |
OK : BOOL | TRUE if the file exists |
F_GETSIZE
Get the size of a file. Note that this function block returns 0
when the file size is zero or if the file is not present.
SIZE := F_GETSIZE (PATH);
PATH : STRING | Name of the file, can include a path name according to target system conventions |
SIZE : DINT | Size of the file in bytes |
F_RENAME
Rename a file
OK := F_RENAME (PATH, NEWNAME);
PATH : STRING | Name of the file (must exist). Can include a pathname according to target system conventions. |
NEWNAME : STRING | New name for the file |
OK : BOOL | TRUE if successful |
F_ROPEN
Open a file for reading
Example
Structured Text
ID := F_ROPEN( PATH ) ;
Ladder Diagram
-
-
The positive transition on each file operation FB prevents to open the file every time the program runs (each cycle).
PATH : STRING | Name of the file; the file must exist. Can include a path name according to target system conventions. |
ID : DINT | ID of the open filer NULL if the file can't be read |
F_SEEK
Set the current position in an open file
OK := F_SEEK (ID, POS, ORG);
ID | DINT | ID of an open file |
POS | DINT | Number of bytes to offset from ORG. If ORG = SEEK_SET, then POS should be ≥ 0 If ORG = SEEK_END, then POS should be ≤ 0 If ORG = SEEK_CUR, then POS can be positive or negative |
ORG | DINT | Origin of the move: SEEK_SET = 0 - beginning of the file SEEK_CUR = 1 - current position SEEK_END = 2 - end of the file |
OK | BOOL | return check: TRUE if successful |
F_WOPEN
Open a file for writing
ID := F_WOPEN (PATH);
PATH : STRING | Name of the file. Can include a path name according to target system conventions. |
ID : DINT | ID of the open file or NULL if the file can't be read |
If the file does not exist, it is created. If the file already exists, its contents are cleared.
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 of error |
This function reads an integer values from a file. 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. After the file is opened, the first call to FA_READ will read the first integer data, the second call will read the next, etc. To re-start reading at the beginning of the file, close the file and re-open it.
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.
FB_READ
Read binary data from a file
OK := FB_READ (ID, V);
ID : DINT | ID of a file open for writing |
V : ANY | variable to be read; cannot be a string. |
OK : BOOL | return check; TRUE if successful |
This function reads binary data from a file. Variables are stored in binary format in the file, using memory conventions of the target system. After the file is opened, the first call to FB_READ will read the first binary data, the second call will read the next, etc. To re-start reading at the beginning of the file, close the file and re-open it.
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 a string. |
OK : BOOL | return check; TRUE if successful |
Variables 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 of error |
This function reads a string from a file. After the file is opened, the first call to FM_READ will read the first line of text, the second call will read the next line of text, etc. The maximum string length is defined by either the maximum length for the return variable or when the EOL (end of line) character is encountered, which ever occurs first. Close the file and reopen it to restart reading it at the beginning.
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.
String Escape Sequences
For greater formatting control over your STRING output, you may escape the STRING by prepending a $ and use a pre-defined sequence. This is called a string escape sequence.
Escape Sequence | Result |
---|---|
$$ | $ |
$' | ' |
$L | linefeed |
$N | newline |
$P | page (form feed) |
$R | return |
$T | tab |
$xx | hex value |
The following is an example of how STRING escape sequences can be used.
ID:=F_WOPEN('c:\ myfile.txt');
WOK:=FM_WRITE(ID,'123456$N');
//WOK:=FM_WRITE(ID,'$N');
WOK:=FM_WRITE(ID,'abcd$N');
WOK:=FM_WRITE(ID,'the end');
WOK:=F_Close(ID);
The example outputs a file which reads:
123456
abcd
the end
SD_MOUNT
Mount the SDCard on the PDMM. This will not perform any action, and always return TRUE with a Simulator.
OK := SD_MOUNT();
OK : BOOL | TRUE if mounting SDCard is successful |
-
-
Before performing, make sure the SDCard is inserted.
-
-
It is recommended that SD_MOUNT be used only when motion is not started.
SD_UNMOUNT
Un-mount the SDCard from the PDMM. This will not perform any action, and always return TRUE with a Simulator.
OK := SD_UNMOUNT();
OK : BOOL | TRUE if un-mounting SDCard is successful |
-
-
It is recommended that SD_UNMOUNT be used only when motion is not started.
SD_ISREADY
Verify if the SDCard is mounted on the PDMM. This will verify if the SDCard folder is available inside the userdata folder when using a Simulator.
OK := SD_ISREADY();
OK : BOOL | TRUE if the SDCard is mounted (PDMM / PCMM) |