Type
| Function block |
Description
| Opens an existing file in the parameterization memory with a specific name or creates a new file.Assign a STRING variable containing the name of the file to be opened to the Name input.Activate the function block on a rising edge at the Execute input. The file is opened.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 1 and Error = 0, a valid file handle is present at the Handle output.If an error occurred during execution, the value at the Error output = 1. ErrorID indicates the number of the cause of the error. |
Notes
|
- This function block can activate up to eight instances at the same time. 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. (If you are connected to the controller via SFTP or SSH, this is also the home directory.)
If the file name does not contain any path information, the file is searched for/created in this directory. Any relative path in the name must also refer to this directory.
- The value of the handle at the function block output is maintained even if the Execute input is no longer active. The file handle of the opened/created file is required for all further file operations.
- The status of the Done, Error and ErrorID outputs is maintained until a falling edge is detected at the Execute input.
- 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
Execute
Data type: | BOOL |
Description: | Opens/creates the file if a rising edge is detected. |
Name
Data type: | STRING |
Description: | Name of the file to be opened/created including path. See the "Notes" section above for more information on file directories. |
Outputs
Done
Data type: | BOOL |
Description: |
0 | The function block was not executed. |
1 | The function block was executed. |
|
Handle
Data type: | UINT |
Description: | File handle of the file opened or created. |
Error
Data type: | BOOL |
Description: |
0 | No error occurred when opening/creating the file. |
1 | An error occurred when opening/creating the file. |
|
ErrorID
Data type: | UINT |
Description: | Error number of error that occurred when opening/creating the file:
0 | No error information available. |
1 | Invalid file handle. |
2 | The maximum number of files is already open. |
4 | The file is already open. |
5 | The file is write-protected or access was denied. |
6 | File name not entered. |
|
|