FB_EcGetAllExtSlaveStates

The FB_EcGetAllExtSlaveStates function block can be used to read the EtherCAT status, the extended EtherCAT status, and the link status of all slaves connected to the master. If the call is successful, the buffer passed in the pStateBuf parameter contains the requested status information as an array of type ST_EcExtendedSlaveState. The function block FB_EcGetAllExtSlaveStates is required when using the MX-System in order to detect empty MX slots (without an MX module inserted) in the PLC.
Inputs
VAR_INPUT
sNetId : T_AmsNetId;
pStateBuf : POINTER TO ARRAY[0..EC_MAX_SLAVES] OF ST_EcExtendedSlaveState;
cbBufLen : UDINT;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VARName | Type | Description |
|---|---|---|
sNetId | String containing the AMS network ID of the EtherCAT master device. | |
pStateBuf | POINTER TO ARRAY[0..EC_MAX_SLAVES] OF ST_EcExtendedSlaveState | Address of an ARRAY of ST_EcExtendedSlaveStates into which the extended slave statuses are to be written. |
cbBufLen | UDINT | Maximum available buffer size (in bytes) for the data to be read |
bExecute | BOOL | The function block is enabled 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;
nSlaves : UINT;
END_VARName | 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. Error 1798 (0x706) indicates a null pointer at the buffer address. Error 1797 (0x705) indicates inadequate buffer size. |
nSlaves | UINT | The number of slaves connected to the master |
Example for implementation in ST:
PROGRAM TEST_GetAllExtSlaveStates
VAR
fbGetAllExtSlaveStates : FB_EcGetAllExtSlaveStates;
sNetId : T_AmsNetId := '172.16.2.131.2.1';
bExecute : BOOL;
devStates : ARRAY[0..255] OF ST_EcExtendedSlaveState;
nSlaves : UINT := 0;
bError : BOOL;
nErrId : UDINT;
END_VAR
fbGetAllExtSlaveStates(sNetId:= sNetId, pStateBuf := ADR(devStates), cbBufLen:=SIZEOF(devStates), bExecute:=bExecute);
nSlaves := fbGetAllExtSlaveStates.nSlaves;
bError := fbGetAllExtSlaveStates.bError;
nErrId := fbGetAllExtSlaveStates.nErrId;Requirements
Development environment | Target platform | PLC libraries to include |
|---|---|---|
TwinCAT v3.1.4026.26 | PC or CX (x86, x64, Arm®) | Tc2_EtherCAT >= 3.8.1.0 |