FB_EcGetMasterState
The function block FB_EcGetMasterState
can be used to read the EtherCAT state of the master. If the call is successful, the State output variable of type WORD contains the requested status information.
Inputs
VAR_INPUT
sNetId : T_AmsNetId;
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. (Type: T_AmsNetId) |
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. |
Outputs
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
state : WORD;
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. |
state | WORD | Current EtherCAT state of the master. (See State) |
state
Current EtherCAT state of the master. The possible values are:
Constant | Value | Description |
---|---|---|
EC_DEVICE_STATE_INIT | 0x01 | Master is in Init state |
EC_DEVICE_STATE_PREOP | 0x02 | Master is in Pre-operational state |
EC_DEVICE_STATE_SAFEOP | 0x04 | Master is Safe-operational state |
EC_DEVICE_STATE_OP | 0x08 | Master is Operational state |
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 platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.0 | PC or CX (x86, x64, ARM) | Tc2_EtherCAT |