FB_EcReqSlaveState

FB_EcReqSlaveState 1:

With this function block a slave can be set to a specified EtherCAT state. The requested EtherCAT state is transferred in the state variable. The function block becomes inactive as soon as it has sent the command to change state. Unlike the function block FB_EcSetSlaveState it does not wait until the EtherCAT slave has attained the new state.

See also: FB_EcSetSlaveState

FB_EcReqSlaveState 2: Inputs

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

Name

Type

Description

sNetId

T_AmsNetId

String containing the AMS network ID of the EtherCAT master device. (Type: T_AmsNetId)

nSlaveAddr

UINT

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

bExecute

BOOL

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

tTimeout

TIME

Maximum time allowed for the execution of the function block.

state

WORD

EtherCAT state requested from the master.
(See State)

State

EtherCAT state to which the slave is to be set. The possible State values are:

Constant

Value

Description

EC_DEVICE_STATE_INIT

0x01

Set slave to Init state

EC_DEVICE_STATE_PREOP

0x02

Set slave to Pre-operational state

EC_DEVICE_STATE_BOOTSTRAP

0x03

Set slave to Bootstrap state. This state is used for firmware downloads.

EC_DEVICE_STATE_SAFEOP

0x04

Set slave to Safe-operational state

EC_DEVICE_STATE_OP

0x08

Set slave to Operational state

EC_DEVICE_STATE_ERROR

0x10

If the error bit in the status byte is set in the EtherCAT slave (state.deviceState & EC_DEVICE_STATE_ERROR = TRUE), the error bit can be reset by setting EC_DEVICE_STATE_ERROR.

FB_EcReqSlaveState 3: Outputs

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

Name

Type

Description

bBusy

BOOL

This output is set when the function block is activated, and remains set until a 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.

Example of an implementation in ST:

PROGRAM TEST_ReqSlaveState
VAR
    fbGetSlaveState : FB_EcReqSlaveState;
    sNetId          : T_AmsNetId:= '172.16.2.131.2.1';
    bExecute        : BOOL;
    state           : WORD := EC_DEVICE_STATE_INIT;
    nSlaveAddr      : UINT := 1001;
    bError          : BOOL;
    nErrId          : UDINT;
END_VAR

fbGetSlaveState(sNetId:= sNetId, nSlaveAddr:= nSlaveAddr, bExecute:=bExecute, state:=state);
bError := fbGetSlaveState.bError;
nErrId := fbGetSlaveState.nErrId;

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT