FB_EcSetSlaveState

FB_EcSetSlaveState 1:

With this function block a slave can be set to a specified EtherCAT state. The requested EtherCAT state is transferred with the reqState variable. The function block sends the command to change state and, unlike the function block FB_EcRegSlaveState, remains active until the EtherCAT slave has attained the new state or the maximum time tTimeout is exceeded. The current state is output in the currState variable.

See also: FB_EcReqSlaveState

FB_EcSetSlaveState 2: Inputs

VAR_INPUT
    sNetId     : T_AmsNetId;
    nSlaveAddr : UINT;     
    bExecute   : BOOL; 
    tTimeout   : TIME := T#10s; 
    reqState   : 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.

reqState

WORD

EtherCAT state to which the slave is to be set. (See reqState)

reqState

EtherCAT state to which the slave is to be set. The possible values for reqState 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 (currState.deviceState AND EC_DEVICE_STATE_ERROR = TRUE), the error bit can be reset by setting EC_DEVICE_STATE_ERROR.

FB_EcSetSlaveState 3: Outputs

VAR_OUTPUT
    bBusy     : BOOL;
    bError    : BOOL;
    nErrId    : UDINT;
    currState : ST_EcSlaveState;
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.

currState

ST_EcSlave
State

Current EtherCAT state of the slave

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT