FB_EcGetAllSlaveStates
The FB_EcGetAllSlaveStates function block allows the EtherCAT status and the Link status of all the slaves connected to the master to be read. When the call is successful, the buffer passed in the parameter pStateBuf contains the requested status information as an array of ST_EcSlaveState.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId;
pStateBuf : POINTER TO ARRAY[0..EC_MAX_SLAVES] OF ST_EcSlaveState;
cbBufLen : UDINT;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
sNetId: This is a string that contains the AMS network identifier of the EtherCAT master device.
pStateBuf : The address of an array of ST_EcSlaveStates into which the slave statuses are to be written.
cbBufLen:The maximum available buffer size for the data to be read, in bytes.
bExecute: The block is activated by a rising edge at this input.
tTimeout: Maximum time allowed for the execution of the function block.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
nSlaves : UINT;
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.
nSlaves: The number of slaves connected to the master.
Example of an implementation in ST:
PROGRAM TEST_GetAllSlaveStates
VAR
fbGetAllSlaveStates : FB_EcGetAllSlaveStates;
sNetId : T_AmsNetId := '172.16.2.131.2.1';
bExecute : BOOL;
devStates : ARRAY[0..255] OF ST_EcSlaveState;
nSlaves : UINT := 0;
bError : BOOL;
nErrId : UDINT;
END_VAR
fbGetAllSlaveStates(sNetId:= sNetId, pStateBuf := ADR(devStates), cbBufLen:=SIZEOF(devStates), bExecute:=bExecute);
nSlaves:=fbGetAllSlaveStates.nSlaves;
bError:=fbGetAllSlaveStates.bError;
nErrId:=fbGetAllSlaveStates.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) |