FB_FileTell
The function block "Fb_FileTell" gets the current position of the file pointer. The position is expressed as an offset relative to the beginning of the stream.
Note that when a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. For example, if a file is opened for an append and the last operation was a read, the file position is the point where the next read operation would start, not where the next write would start. (When a file is opened for appending, the file position is moved to end of file before any write operation.) If no I/O operation has yet occurred on a file opened for appending, the file position is the beginning of the file.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId;
hFile : UINT;
bExecute : BOOL;
tTimeout : TIME;
END_VAR
sNetId : Is a string containing the AMS network identifier of the target device to which the ADS command is directed.
hFile : Is occupied by the file handle already created by FB_FileOpen.
bExecute : The ADS command is triggered by a rising edge at this input.
tTimeout : States the time before the function is cancelled.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
nSeekPos : DINT; (* On error, nSEEKPOS returns -1 *)
END_VAR
bBusy: This output remains TRUE until the block has executed a command, but at the longest for the duration supplied to the ‘tTimeout’ input. While bBusy = TRUE, no new command will be accepted at the inputs. Please note that it is not the execution of the service but its acceptance whose time is monitored.
bError: This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in ‘nErrId’.
nErrId: Contains the command-specific ADS error code of the most recently executed command.
nSeekPos : This output returns the actual position of the file pointer.
Function specific ADS error code | Possible reason |
---|---|
0x703 | Invalid or unknown file handle. |
0x70E | File was opened with wrong method ( e.g. with 'obsolete' FILEOPEN function block ). |
Example of calling the 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 |
---|---|---|
TwinCAT v2.8.0 | PC or CX (x86) | TcSystem.Lib |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) | TcSystem.Lib |