FB_EcGetExtSlaveState

FB_EcGetExtSlaveState 1:

The function block FB_EcGetExtSlaveState allows the EtherCAT status, the extended EtherCAT status and the link status of an individual EtherCAT slave to be read. If the call is successful, the output variable extState, whose type is ST_EcSlaveState, contains the requested status information. The function block FB_EcGetExtSlaveState is required when using the MX-System in order to detect empty MX slots (without an MX module inserted) in the PLC.

FB_EcGetExtSlaveState 2: Inputs

VAR_INPUT
    sNetId     : T_AmsNetId; 
    nSlaveAddr : UINT; 
    bExecute   : BOOL; 
    tTimeout   : TIME := DEFAULT_ADS_TIMEOUT; 
END_VAR

Name

Type

Description

sNetId

T_AmsNetId

String containing the AMS network ID of the EtherCAT master device.

nSlaveAddr

UINT

Fixed address of the EtherCAT slave whose state is to be read.

bExecute

BOOL

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

tTimeout

TIME

Maximum time allowed for the execution of the function block.

FB_EcGetExtSlaveState 3: Outputs

VAR_OUTPUT
    bBusy    : BOOL;
    bError   : BOOL;
    nErrId   : UDINT;
    extState : ST_EcExtendedSlaveState;
END_VAR

Name

Type

Description

bBusy

BOOL

This output is set when the function block is activated, and remains set until feedback is received.

bError

BOOL

This output is set after the bBusy output has been reset when an error occurs in the transmission of the command.

nErrId

UDINT

Supplies the ADS error code associated with the most recently executed command if the bError output is set.

extState

ST_EcExtendedSlaveState

Structure that contains the extended EtherCAT status and the link status of the slave. (Type: ST_EcExtendedSlaveState)

Example for implementation in ST:

PROGRAM TEST_GetExtSlaveState
VAR
    fbGetExtSlaveState : FB_EcGetExtSlaveState;
    sNetId             : T_AmsNetId := '172.16.2.131.2.1';
    bExecute           : BOOL;
    extState           : ST_EcExtendedSlaveState;
    nSlaveAddr         : UINT := 1001;
    bError             : BOOL;
    nErrId             : UDINT;
END_VAR

fbGetExtSlaveState(sNetId:= sNetId, nSlaveAddr:= nSlaveAddr, bExecute:=bExecute);
extState := fbGetExtSlaveState.extState;
bError   := fbGetExtSlaveState.bError;
nErrId   := fbGetExtSlaveState.nErrId;

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4026.26

PC or CX (x86, x64, Arm®)

Tc2_EtherCAT >= 3.8.1.0