FB_EcCoeSdoRead
The FB_EcCoeSdoRead function block allows data to be read from an EtherCAT slave through an SDO (Service Data Object) access. This requires the slave to have a mailbox and to support the "CANopen over EtherCAT" (CoE) protocol. The nSubIndex and nIndex parameters select the object that is to be read.
VAR_INPUT
VAR_INPUT
sNetId : T_AmsNetId;
nSlaveAddr : UINT;
nSubIndex : BYTE;
nIndex : WORD;
pDstBuf : DWORD;
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.
nSlaveAddr: Fixed address of the EtherCAT slave to which the SDO upload command should be sent.
nSubIndex:Sub-index of the object that is to be read.
nIndex: Index of the object that is to be read.
pDstBuf:The address (pointer) of the receive buffer.
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;
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_SdoRead
VAR
fbSdoRead : FB_EcCoESdoRead;
sNetId : T_AmsNetId := '172.16.2.131.2.1';
bExecute : BOOL;
nSlaveAddr : UINT := 1006;
nIndex : WORD := 16#1018;
nSubIndex : BYTE :=1;
vendorId : UDINT;
bError : BOOL;
nErrId : UDINT;
END_VAR
fbSdoRead(sNetId:= sNetId,nSlaveAddr :=nSlaveAddr, nIndex:=nIndex, nSubIndex :=nSubIndex, pDstBuf:= ADR(vendorId), cbBufLen:=SIZEOF(vendorId),bExecute:=bExecute);
bError:=fbSdoRead.bError;
nErrId:=fbSdoRead.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) |