FileWriteLine

PLCopen motion icon

 Function Block - Writes a string value to a text file.

An end-of-line character is systematically written after the string value.

Inputs

Input

Data Type

See Data Types.

Range

Unit

Default

Description

Execute

BOOL

FALSE, TRUE

N/A

No default

On the rising edge, write a string value to a file.

ID

UDINT

No range

N/A

No default

The ID of the open file.

IN

STRING

No range

N/A

No default

The string value to be written.

Outputs

Output

Data Type

See Data Types.

Range

Unit

Description

Done

BOOL

FALSE, TRUE

N/A

If TRUE, the command completed successfully.

Error

BOOL

FALSE, TRUE

N/A

If TRUE, an error has occurred.

ErrorID

DINT

Enumerated

N/A

String Escape Sequences

For greater formatting control over the STRING output, escape the STRING by pre-pending a $ and use a pre-defined sequence. This is called a string escape sequence.

Escape Sequence

Result

$'

'

$$

$

$L

linefeed

$N

newline

$P

page (form feed)

$R

return

$T

tab

$xx

hex value

Example: The is how STRING escape sequences are used.

ID:=FileOpenW('c:\ myfile.txt');
WOK:=FileWriteLine(ID,'123456$N');
//WOK:=FileWriteLine(ID,'$N');
WOK:=FileWriteLine(ID,'abcd$N');
WOK:=FileWriteLine(ID,'the end');
WOK:=FileClose(ID);

The example outputs a file which reads:

123456
abcd
the end

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* FileWriteLine example *)
CASE StepCounter OF
0:
  Inst_FileWriteLine(TRUE, MyOutputFileID, 'Hello, world.');
  StepCounter := StepCounter + 1;
1:
  Inst_FileWriteLine(TRUE, MyOutputFileID, 'Hello, world.');
  IF Inst_FileWriteLine.Done THEN
     Inst_FileWriteLine(FALSE, 0, '');
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;

See Also