FB_FileGets

FB_FileGets 1:

The function block FB_FileGest 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 null termination is appended automatically. The file must have been opened in text mode.

FB_FileGets 2:

This function block is only suitable for logging in real-time to a limited extent.
For good performance, we recommend using the TF3500 TwinCAT Analytics Logger product, which is subject to a charge.

FB_FileGets 3: Inputs

VAR_INPUT
    sNetId    : T_AmsNetId;
    hFile     : UINT;
    bExecute  : BOOL;
    tTimeout  : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetId

T_AmsNetId

String containing the AMS network ID of the target device to which the ADS command is addressed (type: T_AmsNetId).

hFile

UINT

File handle, which was generated when the function block FB_FileOpen was created.

bExecute

BOOL

The function block is activated by a rising edge at this input.

tTimeout

TIME

States the length of the timeout that may not be exceeded by execution of the ADS command.

FB_FileGets 4: Outputs

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

Name

Type

Description

bBusy

BOOL

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

BOOL

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

nErrId  

UDINT

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

sLine

T_MaxString

String that was read (type: T_MaxString).

bEOF

BOOL

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

0x703

Invalid or unknown file handle.

0x70A

No memory for read buffer.

0x70E

File was opened with wrong method (e.g. with obsolete FILEOPEN function block).

Example of calling the function block in FBD:

PROGRAM Test
VAR
    fbFileGets        : FB_FileGets;
    hFile             : UINT;
    bFileGets         : BOOL;
    bFileGetsBusy     : BOOL;
    bFileGetsError    : BOOL;
    nFileGetsErrorId  : UDINT;
    strBuffer         : STRING;
    bFileGetsEOF      : BOOL;
END_VAR
FB_FileGets 5:

Requirements

Development environment

Target system type

PLC libraries to include (Category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_System (System)