TwinCAT 3 PLC Lib: Tc2_System

FB_FileTell

 fb_filetell

The function block determines the current position of the file pointer. The position indicates the relative offset from the start of the file.

Note that in files opened in “Append at end of file” mode, the current position is determined by the last I/O operation, not by the position of the next write access. After a read operation, for example, the file pointer is at the position where the next read access will take place, not at the position where the next write access will take place (in append mode, the file pointer is always moved to the end before a write operation).

If no previous I/O operation was performed and the file was opened in append mode, the file pointer is at the start of the file.

 

VAR_OUTPUT

VAR_OUTPUT
    bBusy    : BOOL;
    bError   : BOOL;
    nErrId   : UDINT;
    nSeekPos : DINT;(* On error, nSEEKPOS returns -1 *)
END_VAR

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.

nSeekPos: Returns the current position of the file pointer.

Command-specific error code
Possible cause
0x703
Invalid or unknown file handle.
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
    fbFileTell        : FB_FileTell;
    hFile             : UINT;
    bFileTell         : BOOL;
    bFileTellBusy     : BOOL;
    bFileTellError    : BOOL;
    nFileTellErrorId  : UDINT;
    nFileTellSeekPos  : DINT;
END_VAR
 
 

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)