-

FILE_WRITE

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

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

Handle

Length

Input/Output

Buffer

Outputs

Done

LengthWritten

Error

ErrorID