Function BlockFileWriteLinePLCopen motion icon

Description

This function block writes a string value to a file. An end-of-line character is systematically written after the string value.

Figure 7-216: The FileWriteLine Function Block

String Escape Sequences

For greater formatting control over your STRING output, you may escape the STRING by prepending 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

The following is an example of how STRING escape sequences can be 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

Related Functions

FileClose, FileEOF, FileOpenA, FileOpenR, FileOpenW, FileReadBinData, FileReadLine, FileSeek, FileWriteBinData

See also: File Management

Arguments

Input

Execute Description On the rising edgeClosed A rising edge is the transition of a digital signal from low to high. It is also called positive edge write a string value to a file.
  Data Type BOOL
  Range 0, 1
  Unit N/A
  Default
ID Description ID of the open file.
  Data Type UDINT
  Range N/A
  Unit N/A
  Default
IN Description The string value to be written.
  Data Type STRING
  Range N/A
  Unit N/A
  Default

Output

Done Description If TRUE, then the command completed successfully
  Data Type BOOL
Error Description If TRUE, an error has occurred
  Data Type BOOL
ErrorID Description Indicates the error if Error output is set to TRUE. See the table in Search IndexFile and TCP/IP Function Block ErrorID Output
  Data Type DINT

Example

Structured Text

(* 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;