FB_EnumRouteEntry

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 must 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.

VAR_INPUT

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

sNetID: Here a string containing the network address of the TwinCAT Computer can be given, whose AMS Router connection should be read. The string can also be empty for the local computer.

eCmd: Control command for the enumeration block.

bExecute: The function 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.

VAR_OUTPUT

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

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

bError:  If an ADS error should occur during the execution of the command, then this output is set, after the bBusy output has been reset. 

nErrId: When the bError output is set, this variable supplies the ADS error code.

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 if bEOE = FALSE and bError = FALSE.

stRoute: Structure element with latest read connection parameter.

 

Example in ST:

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
VAR
    fbEnum  : FB_EnumRouteEntry := ( sNetID := '', tTimeout := T#5s );
    bEnum   : BOOL := TRUE;
    nState  : BYTE := 0;
    sInfo   : T_MaxString;
END_VAR

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

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

    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 ) );
                    ADSLOGSTR( ADSLOG_MSGTYPE_HINT OR ADSLOG_MSGTYPE_LOG, 'ROUTE INFO: %s', sInfo );
                    fbEnum.eCmd := eEnumCmd_Next; (* enum next entry *)
                 nState  := 1;
                ELSE (* no more route entries *)
                 nState  := 0;
                END_IF
            ELSE (* log error *)
             ADSLOGSTR( ADSLOG_MSGTYPE_ERROR OR ADSLOG_MSGTYPE_LOG, 'FB_EnumRouteEntry error:%s', DWORD_TO_HEXSTR( fbEnum.nErrID, 0, FALSE ) );
                nState  := 0;
            END_IF
        END_IF
END_CASE

 

The written Log messages in the TwinCAT System Manager Logger output:

FB_EnumRouteEntry 2:

Requirements

Development environment

Target system type

PLC libraries to include

TwinCAT v2.9.0 Build > 1033

TwinCAT v2.10.0 Build > 1257

PC or CX (x86)

TcUtilities.Lib

( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically )

TwinCAT v2.10.0 Build >= 1301

CX (ARM)