Function Description

The WR_DATA_TO_FILE function enables a direct address variable (%MW1000), a located variable (VAR0 @ %MW1000), or an unlocated variable to be written to a file.

The value written is added after the current position in the file. After writing, the current position of the file is updated.

NOTE: When you use the WR_DATA_TO_FILE function with string data type, It creates in the file an array of bytes whose size is the maximum size declared (for instance if you declare a STRING[100] it writes 100 bytes in the file).If you read it with an EFB of Control Expert the function read the 100 bytes but it sees only the first characters before the first NULL character. if you use a third party software or tool and if you've got many null characters in the 100 bytes, it could see many string instead of one.
NOTE: It is still possible to modify the status of a file in the file system although the file is already open. The status of a file (Read Only, Read/Write) is not evaluated when the file is opened, but only when data.

The additional parameters EN and ENO can be configured.

FBD Representation

The representation in FBD of the WR_DATA_TO_FILE function is as follows:

Ladder Representation

The representation in Ladder of the WR_DATA_TO_FILE function is as follows:

IL representation

Representation:

CAL WR_DATA_TO_FILE_Instance (REQ:=WriteDataToFileStart, FILEDESC:=WriteDataToFileDescriptor, VARIABLE:=WriteDataToFileVariable, DONE=>WriteDataToFileDone, ERROR=>WriteDataToFileError, STATUS=>WriteDataToFileStatus)

ST representation

Representation:

WR_DATA_TO_FILE_Instance (REQ:=WriteDataToFileStart, FILEDESC:=WriteDataToFileDescriptor, VARIABLE:=WriteDataToFileVariable, DONE=>WriteDataToFileDone, ERROR=>WriteDataToFileError, STATUS=>WriteDataToFileStatus);

Parameter Description

The following table describes the input parameters:

Parameter

Type

Comment

FILEDESC

DINT

This parameter specifies the file descriptor returned by the CREATE_FILE or OPEN_FILE functions.

VARIABLE

ANY

This parameter specifies the variable to write to the file.

Any direct address variable (%MW1000), located variable (VAR0 @ %MW1000), or unlocated variable (single type, table, structure) can be written.

To write a table of %MW or direct variables, the syntax used is %MW1000:10 (10 words from %MW1000).

Description of common parameters.