FILEOPEN

FILEOPEN 1:

With this function block a new file can be created, or a closed existing file can be re-opened for further processing.

VAR_INPUT

VAR_INPUT
    NETID       : T_AmsNetId;  (* ams net id *)
    FPATHNAME   : T_MaxString;    (* default max filename length = 255 *)
    OPENMODE    : DWORD;        (* open mode flags *)
    OPEN        : BOOL;     (* open control input *)
    TMOUT       : TIME;
END_VAR

NETID : is a string containing the AMS network ID of the target device to which the ADS command is directed.

FPATHNAME : contains the path and file name of the file to be opened.

FILEOPEN 2:

The path can only point to the local file system of the computer. This means that network paths cannot be used here!

OPENMODE : contains the mode in which the file is to be opened. The codes listed below are the various opening modes which are already pre-defined as constants in the library and which can accordingly be passed symbolically to the function block. 

OPEN : the ADS command is triggered by a rising edge at this input.

TMOUT : specifies the time until the abortion of the function.

VAR_OUTPUT

VAR_OUTPUT
    BUSY        : BOOL;
    ERR         : BOOL;
    ERRID       : UDINT;
    HFILE       : UINT;     (* file handle *)
END_VAR

BUSY : this output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the 'Timeout' input. While Busy = TRUE, no new command will be accepted at the inputs.

FILEOPEN 3:

It is not the execution of the service but its acceptance whose time is monitored.

ERR : this output is set to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in 'ErrorId'. If the function block has a timeout error, 'Error' is TRUE and 'ErrorId' is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs.

ERRID : contains the instruction-specific error code of the most recently executed command. Is reset to 0 by the execution of a command at the inputs.

HFILE : contains the file handle created for the file when opening has been successful.

 

Sample of calling the function block in FBD:

FILEOPEN 4:

This should create (or overwrite) the file "TestFile2.txt" in the root directory of drive "C:". In the sample a proper handle is created for the file. This handle is now passed to the file function blocks described below as an identifier for the file to be processed.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.7.0

PC or CX (x86)

PLCSystem.Lib

TwinCAT v2.8.0

PC or CX (x86)

TcSystem.Lib

TwinCAT v2.10.0 Build >= 1301

CX (ARM)

TcSystem.Lib