FileWriteLine

PLCopen motion icon

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

Inputs

Input

Data Type

Range

Unit

Default

Description

Execute

BOOL

0 to 1

N/A

No default

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

ID

UDINT

N/A

N/A

No default

The ID of the open file.

IN

STRING

N/A

N/A

No default

The string value to be written.

Outputs

Output

Data Type

Range

Unit

Description

Done

BOOL

 

 

If TRUE, the command completed successfully.

Error

BOOL

 

 

If TRUE, an error has occurred.

ErrorID

DINT

 

 

Indicates the error if Error output is TRUE.

See the table in File and TCP/IP Function Block ErrorIDs.

Remarks

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

Figure 1: FileWriteLine

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