FB_EnumRouteEntry 1:

This function block is used to transfer information to other TwinCAT systems via the AMS router connections (remote routes). If several connections are used the function block has to be called up repeatedly. Only one entry can be handled for each call. 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.


    sNetID    : T_AmsNetID;
    eCmd      : E_EnumCmdType := eEnumCmd_First;
    bExecute  : BOOL;
    tTimeout  : TIME := DEFAULT_ADS_TIMEOUT;

sNetID: Here you can enter a string with the network address of the TwinCAT computer whose AMS router connections are to be read (type: T_AmsNetID). If it is to be run on the local computer, an empty string can be entered.

eCmd: Control command for the enumeration block (type: E_EnumCmdType).

bExecute: the block is activated by a positive edge at this input.

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


    bBusy    : BOOL;
    bError   : BOOL;
    nErrId   : UDINT;
    bEOE     : BOOL;
    stRoute  : ST_AmsRouteEntry;

bBusy: When the function block is activated this output is set. It remains set until a feedback is received.

bError: In the event of an error during the command transfer, this output is set once the bBusy output has been reset.

nErrId: Supplies the ADS error number when the bError output is set.

bEOE: 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.

stRoute: Structural element containing the last read connection parameters (type: ST_AmsRouteEntry).


The configured AMS router connections are to be read on the local TwinCAT system and written into the TwinCAT System Manager logger output as messages.

PROGRAM P_EnumRouteEntries
    fbEnum : FB_EnumRouteEntry := ( sNetID := '', tTimeout := T#5s );
    bEnum  : BOOL := TRUE;
    nState : BYTE := 0;
    sInfo  : T_MaxString;

A rising edge at the bEnum variable triggers reading of the connection information.

CASE nState OF
    IF bEnum THEN (* flag set ? *)
        bEnum := FALSE; (* reset flag *)
        fbEnum.eCmd := eEnumCmd_First; (* enum first entry *)
        nState := 1;

    1: (* enum one entry *)
    fbEnum( bExecute := FALSE );
    fbEnum( bExecute := TRUE );
    nState := 2;

    2: (* wait until function block not busy *)
    fbEnum( bExecute := FALSE );
    IF NOT fbEnum.bBusy THEN
        IF NOT fbEnum.bError THEN
            IF NOT fbEnum.bEOE THEN
                sInfo := CONCAT( 'Name: ', fbEnum.stRoute.sName );
                sInfo := CONCAT( sInfo, ' Address: ' );
                sInfo := CONCAT( sInfo, fbEnum.stRoute.sAddress );
                sInfo := CONCAT( sInfo, ' Transport: ' );
                sInfo := CONCAT( sInfo, ROUTETRANSPORT_TO_STRING( fbEnum.stRoute.eTransport ) );
                    fbEnum.eCmd := eEnumCmd_Next; (* enum next entry *)
                nState := 1;
            ELSE (* no more route entries *)
                nState := 0;
        ELSE (* log error *)
            nState := 0;

Log messages in the TwinCAT System Manager logger output:

FB_EnumRouteEntry 2:


Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_Utilities (System)