You are here: Core Reference > Coding > Logic > WRITE_FILE_BYTE

WRITE_FILE_BYTE

Function Name

WRITE_FILE_BYTE

Description

Allows data (single byte) to be written to an open file or serial port. When the data has been written, the file or port needs to be closed by using the CLOSE_FILE function (see CLOSE_FILE).

Unlike WRITE_FILE, WRITE_FILE_EX allows a single byte to be written.

Arguments

FILEID {UDINT}

The FILEID is a number that identifies the file or port to which data is to be written.

DATA {BYTE}

The data that is to be written to the file or serial port.

For more information on the data types for the inputs and outputs, see Data Type Hierarchy.

Returns

Zero {UDINT}

The WRITE_FILE_BYTE function returns zero.

NOTE: You should only use the WRITE_FILE_BYTE function in ST Programs.

Example:

ST Program - WRITE_FILE_BYTE:

To use a WRITE_FILE_BYTE function in an ST program, you need to use this syntax:

  • WriteExport := WRITE_FILE_BYTE( FILEID, DATA );

Where WriteExport, FILEID, and DATA are variables that are declared earlier in the ST program. The FILEID variable has to be a UDINT and identifies the file or port to which the data is to be written and the DATA variable is the data that is written. The DATA has to be a byte data type, for example, 16xFF. The WriteExport variable will store the value that is returned by the WRITE_FILE_BYTE function.

A common use for the WRITE_FILE_BYTE function is to provide a serial ASCII export process. To achieve this, an OPEN_PORT function is used to open a serial port and then a WRITE_FILE_BYTE function is used to write data to the port:

  • FileId := OPEN_PORT('COM1,9600,8,N,1,NONE');
  • ErrorCode := WRITE_FILE_BYTE(FileId, WriteValue);
  • FileId := CLOSE_FILE(FileId);

In this code, the ST Program opens the defined COM port and then performs a WRITE_FILE_BYTE function. The WRITE_FILE_BYTE function writes the value that is stored in the WriteValue variable to the port (the FileId in the WRITE_FILE_BYTE function declaration corresponds to the FileId that is returned by the OPEN_PORT function). When the string has been written to the port, the CLOSE_FILE function is used to close the port. This allows byte data types to be written to a serial port so that they can be accessed by other applications etc.


ClearSCADA 2015 R2