FB_EcGetMasterState

FB_EcGetMasterState 1:

The function block FB_EcGetMasterState allows the EtherCAT state of the master to be read. If the call is successful, the output variable state of type word, contains the EtherCAT state of the master.

VAR_INPUT

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

sNetId: This is a string that contains the AMS network identifier of the EtherCAT master device.

bExecute: The block is activated by a rising edge at this input.

tTimeout: Maximum time allowed for the execution of the function block.

VAR_OUTPUT

VAR_OUTPUT
    bBusy       : BOOL;
    bError      : BOOL;
    nErrId      : UDINT;
    state       : WORD; 
END_VAR

bBusy: This output is set when the function block is activated and remains set until an acknowledgement is received.

bError: This output is set up after the bBusy output has been reset if there has been an error in transmission of the command.

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

state: EtherCAT state of the master. Following values for state  are possible:

 

Constant

Value

Description

EC_DEVICE_STATE_INIT

0x01

Master is in the state Init

EC_DEVICE_STATE_PREOP

0x02

Master is in the state Pre-Opereational

EC_DEVICE_STATE_SAFEOP

0x04

Master is in the state Safe-Operational

EC_DEVICE_STATE_OP

0x08

Master is in the state Operational

 

Example of an implementation in ST:

PROGRAM TEST_GetMasterState
VAR
    fbGetMasterState        : FB_EcGetMasterState;
    sNetId          : T_AmsNetId := '172.16.2.131.2.1';
    bExecute            : BOOL;
    state           : WORD;
    bError          : BOOL;
    nErrId          : UDINT;
END_VAR
fbGetMasterState(sNetId:= sNetId, bExecute:=bExecute);
state:=fbGetMasterState.state;
bError:=fbGetMasterState.bError;
nErrId:=fbGetMasterState.nErrId;

 

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT v2.10.0 or higher

PC or CX (x86)

TcEtherCAT.lib
( Standard.Lib; TcBase.Lib; TcSystem.Lib, TcUtilities.Lib are included automatically )

TwinCAT v2.10.0 Build >= 1301 or higher

CX (ARM)