FB_EnumFindFileEntry

FB_EnumFindFileEntry 1:

This function block searches a directory for a file or a subdirectory whose name is similar to the specified name. Any entries found can be read individually. See also description of the FB_EnumFindFileList function block. The input parameter eCmd is used for navigating through the list of entries. The eCmd input determines whether the first or the next input is read, for example.

Important notes:

A new search may be started only if the previous search has been fully completed. The function block instance may need to be activated several times (by a rising edge at the bExecute input) for a complete search. The search is only fully complete if bEOE =TRUE was reached or if the search was terminated prematurely with ECMD = eEnumCmd_Abort.

For the TwinCAT system, the search may not yet be completed if the PLC application has already found the file or directory that was sought.

If not all entries are to be read (i.e. bEOE=TRUE is not reached), the function block subsequently has to be called with the input parameter eCmd = eEnumCmd_Abort. This is necessary in order to complete the search and release all internal resources (file handles). If bEOE=TRUE was reached or if an error occurs, eEnumCmd_Abort is automatically executed internally.

FB_EnumFindFileEntry 2: Inputs

VAR_INPUT
    sNetID    : T_AmsNetID;
    sPathName : T_MaxString;
    eCmd      : E_EnumCmdType := eEnumCmd_First;
    bExecute  : BOOL;
    tTimeout  : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetID

T_AmsNetID

A string with the network address of the TwinCAT computer on which a directory search is to be executed can be specified here. For the local computer an empty string may be specified.

sPathName

T_MaxString

A valid directory name or directory with file name as string. The string can contain (* and ? ) as wildcards. If the path ends with a wildcard, dot or the directory name, the user must have access rights to this path and its subdirectories.

eCmd

E_EnumCmdType

eEnumCmd_First adds the first data field to the buffer, eEnumCmd_Next adds the next data field. No other parameter values are used.

bExecute

BOOL

The function block is enabled by a positive edge at this input.

tTimeout

TIME 

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

FB_EnumFindFileEntry 3: Outputs

VAR_OUTPUT
    bBusy      : BOOL;
    bError     : BOOL;
    nErrId     : UDINT;
    bEOE       : BOOL;
    stFindFile : ST_FindFileEntry;
END_VAR

Name

Type

Description

bBusy

BOOL

When the function block is enabled, this output is set and remains set until a feedback is received.

bError

BOOL

If an error occurs during the transmission of the command, this output is set after the bBusy output is reset.

nErrId

UDINT

Returns the ADS error number when the bError output is set.

bEOE

BOOL

End of enumeration was reached. During the first attempt to read a non-existing entry this output is set to TRUE. This means that read entries are valid as long as bEOE = FALSE and bError = FALSE.

stFindFile

ST_FindFileEntry

If successful this structure variable returns information about the file that was found.

Example:

See: Example: File search (FB_EnumFindFileEntry, FB_EnumFindFileList).

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (WES7/Win7/Win10: TC RT x86/x64, WEC6/7: TC RT x86, WEC7: TC CE7 ARMV7, TC/BSD: TC RT x64, TC OS ARMT2)

Tc2_Utilities (System)