FB_EcReqSlaveState
The function block FB_EcReqSlaveState requests the master to set an EtherCAT slave to the requested state. The parameter state specifies the EtherCAT state the slave should be set to.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId;
nSlaveAddr : UINT;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
state : WORD;
END_VAR
sNetId: This is a string that contains the AMS network identifier of the EtherCAT master device.
nSlaveAddr: Fixed address of the EtherCAT slave.
bExecute: The block is activated by a rising edge at this input.
tTimeout: Maximum time allowed for the execution of the function block.
state: EtherCAT state the slave should be set to. Following values can be passed here:
Constant | Value | Description |
---|---|---|
EC_DEVICE_STATE_INIT | 0x01 | Set Slave to the init state |
EC_DEVICE_STATE_PREOP | 0x02 | Set Slave to Pre-Operational |
EC_DEVICE_STATE_BOOTSTRAP | 0x03 | Set Slave to the Bootstrap state. This state is used for firmware download. |
EC_DEVICE_STATE_SAFEOP | 0x04 | Set Slave to Safe-Operational |
EC_DEVICE_STATE_OP | 0x08 | Set Slave to Operational |
EC_DEVICE_STATE_ERROR | 0x10 | If the Error-Bit is set in the EtherCAT Status-Byte ( state.deviceState & EC_DEVICE_STATE_ERROR = TRUE), one can clear it by passing EC_DEVICE_STATE_ERROR. |
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
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.
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 system type | PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 or higher | PC or CX (x86) | TcEtherCAT.lib |
TwinCAT v2.10.0 Build >= 1301 or higher | CX (ARM) |