TwinCAT 3 PLC Lib: Tc2_System


The function block reads strings from a file. The string is read up to and including the line feed character, or up to the end of the file or the maximum permitted length of sLine. The zero termination is appended automatically. The file must have been opened in text mode.



    bBusy   : BOOL;
    bError  : BOOL;
    nErrId  : UDINT;
    sLine   : T_MaxString;
    bEOF    : BOOL;

bBusy: When the function block is activated, this output is set to TRUE and remains set until feedback is received. As long as bBusy is TRUE, no new command can be executed.

bError: If an error occurs during command execution, this output is set, once the bBusy output has been reset.

nErrId: Returns the ADS error code or the command-specific error code when the bError output is set.

sLine: String that was read (type: T_MaxString).

bEOF: This output is set if the end of the file was reached and no further data bytes could be read (cbRead=0). This output is not set if further data bytes could be read (cbRead>0).

Command-specific error code
Possible cause
Invalid or unknown file handle.
No memory for read buffer.
File was opened with wrong method (e.g. with obsolete FILEOPEN function block).

Example of calling the function block in FBD:

    fbFileGets        : FB_FileGets;
    hFile             : UINT;
    bFileGets         : BOOL;
    bFileGetsBusy     : BOOL;
    bFileGetsError    : BOOL;
    nFileGetsErrorId  : UDINT;
    strBuffer         : STRING;
    bFileGetsEOF      : BOOL;


Development environment
Target system type
PLC libraries to include (Category group)
TwinCAT v3.1.0
PC or CX (x86, x64, ARM)
Tc2_System (System)