Type
| Function block |
Description
| Writes data to a file that was opened previously.Assign the valid handle for the file to which data is to be written to the Handle input. This handle is created when the file is opened with the FILE_OPEN function block.Create a data buffer of sufficient size, which contains the data to be written, for the Buffer input. The data buffer for the data can be declared in a number of ways. The type of data buffer can be defined by the user, e.g., a byte array (see the following example). Strings cannot be used directly as data buffers. If a string is to be saved in a file, the string must first be saved in an array using the STRING_TO_BUF function block.
Example: Byte array used as data buffer type
TYPE FileBuffer : ARRAY [1..100] OF BYTE; END_TYPE In this example the data buffer length is 100 characters.
Assign the number of bytes to be written to the Length input.Activate the function block on a rising edge at the Execute input. Execution of the function block is complete when the Done output is set to 1.If the function block could not be executed successfully, the number of bytes written will be indicated at the LengthWritten output. It is the same as the number of characters to be written.If an error occurred during execution, the value at the Error output = 1. ErrorID indicates the number of the cause of the error. |
Notes
|
- The status of the Done, Error, and ErrorID outputs is maintained until a falling edge is detected at the Execute input. The status of the LengthWritten output is kept.
- 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: | Writes data to the file if a rising edge is detected. |
Handle
Data type: | UINT |
Description: | File handle of the file to which data is to be written. |
Length
Data type: | ANY_INT |
Description: | Number of characters to be written. The value must be greater than or equal to zero. |
Input/Output
Buffer
Data type: | ANY |
Description: | Data buffer containing data to be written. |
Outputs
Done
Data type: | BOOL |
Description: |
0 | The function block was not executed. |
1 | The function block was executed. |
|
LengthWritten
Data type: | UDINT |
Description: | Number of characters written. |
Error
Data type: | BOOL |
Description: |
0 | No error occurred during writing. |
1 | An error occurred during writing. |
|
ErrorID
Data type: | UINT |
Description: | Error number of error that occurred when writing:
0 | No error information available. |
1 | Invalid file handle. |
11 | No memory is available for writing the data. |
12 | The number of characters to be written is greater than the data buffer. |
14 | Invalid Length. The value must be >= 0. |
23 | No data could be written. |
|
|