FB_EcCoeSdoRead
 
The function block FB_EcCoeSdoRead allows data to be read from an object directory of an EtherCAT slave via 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 allow the object that is to be read to be selected. The function block FB_EcCoeSdoReadEx must be used for access to the complete parameter, including subelements.
 Inputs
VAR_INPUT
    sNetId     : T_AmsNetId; 
    nSlaveAddr : UINT; 
    nSubIndex  : BYTE; 
    nIndex     : WORD;
    pDstBuf    : PVOID; 
    cbBufLen   : UDINT; 
    bExecute   : BOOL;
    tTimeout   : TIME := DEFAULT_ADS_TIMEOUT; 
END_VARName  | Type  | Description  | 
|---|---|---|
sNetId  | T_AmsNetId  | String containing the AMS network ID of the EtherCAT master device. (Type: T_AmsNetId)  | 
nSlaveAddr  | UINT  | Fixed address of the EtherCAT slave to which the SDO upload command should be sent.  | 
nSubIndex  | BYTE  | Subindex of the object that is to be read.  | 
nIndex  | WORD  | Index of the object that is to be read.  | 
pDstBuf  | PVOID  | Address (pointer) to the receive buffer.  | 
cbBufLen  | UDINT  | Maximum available buffer size (in bytes) for the data to be read.  | 
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;
    cbRead : UDINT;
END_VARName  | Type  | Description  | 
|---|---|---|
bBusy  | BOOL  | This output is set when the function block is activated, and remains set until 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.  | 
cbRead  | UDINT  | Number of successfully read data bytes  | 
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;Prerequisites
Development environment  | Target platform  | PLC libraries to include  | 
|---|---|---|
TwinCAT v3.1.0  | PC or CX (x86, x64, Arm®)  | Tc2_EtherCAT  |