-

FILE_OPEN_2

Type Function block
Description Opens an existing file in read-write mode in the parameterization memory with a specific name or creates a new file and provides a handle to be used in subsequent file access operations (read/write, etc.).

Assign a STRING variable containing the name of the file to be opened to the NAME input.

As soon as the REQ input is set to TRUE, the inputs are validated. The REQ input must remain set to TRUE, until the file open/create operation is completed (regardless of whether the operation succeeded or failed). The BUSY output is TRUE while the operation is being executed asynchronously on a Service Thread. Execution of the function block is complete when the DONE output is set to TRUE.

If the file to be opened does not exist, it is created. The file is opened with read and write access rights. If DONE is set to TRUE and ERROR = FALSE, a valid file handle is present at the HANDLE output.

If an error occurred during execution, ERROR is set to TRUE, and the error code can be read from the STATUS output.
Notes
  • This function block can be instantiated up to eight times. This means that only eight different files can be opened at the same time.
  • The file to be opened must not be write-protected, because files are always opened with read and write access rights.
  • The variable in which the file name is entered must be a STRING data type. The length of the file name must not exceed 80 characters including the path. User-defined strings are not allowed.

    With PLCnext Technology controllers, the default file path is /opt/plcnext. Because this folder is write-protected at all secure-by-default controllers (for example, Virtual PLCnext Control, AXC F 1252 controller), file names without path are not recommended.

    As of firmware version 2025.0, both device classes (PLCnext Technology controllers and secure-by-default controllers) contain a folder /opt/plcnext/custom to which the firmware has write access.

    For a complete list of secure-by-default controllers, refer to the PLCnext Info Center.

  • The value of the HANDLE at the function block output is maintained even if the REQ input is no longer active. The file handle of the opened/created file is required for all subsequent file operations.
  • The status of the outputs DONE, BUSY, ERROR, and STATUS are maintained as long as REQ is TRUE.

    Do not reset the REQ input until the FB is finished by setting the DONE state. Resetting the REQ input will result in resetting the outputs to their default values.

  • When the function block is used as global function block, it is not thread-safe. In this case, make sure to prevent concurrent calls (e.g., by using the MUTEX function block).
  • Function blocks have to be instantiated. The instance name of the function block has to be declared in the 'Variables' table of the POU where the FB is going to be used. The instance name must be unique within the POU.
Parameters Inputs

REQ

NAME

Outputs

DONE

BUSY

ERROR

STATUS

HANDLE