FB_CoERead_ByDriveRef

FB_CoERead_ByDriveRef 1:

The function block FB_CoERead_ByDriveRef can be used to read drive parameters by means of the "CANopen over EtherCAT (CoE)" protocol. 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. Via bCompleteAccess := TRUE the parameter can be read with subelements.

FB_CoERead_ByDriveRef 2: Inputs

VAR_INPUT
    stDriveRef       :  ST_DriveRef; (*Contains sNetID of EcMaster, nSlaveAddr of EcDrive, nDriveNo of EcDrive, either preset or read from NC*)
    nIndex           :  WORD; (*SoE IDN: e.g. “S_0_IDN+1” for S-0-0001 or “P_0_IDN+23” for P-0-0023*)
    nSubIndex        :  BYTE;
    pDstBuf          :  PVOID; (*Contains the address of the buffer for the received data*)
    cbBufLen         :  UDINT; (*Contains the max. number of bytes to be received*)
    bExecute         :  BOOL; (*Function block execution is triggered by a rising edge at this input*)
    tTimeout         :  TIME; (*States the time before the function is cancelled*)
    bCompleteAccess  :  BOOL;
END_VAR

Name

Type

Description

stDriveRef

ST_DriveRef

Structure containing the AMS network ID of the EtherCAT master device and the address of the slave device. The reference to the drive can be linked directly to the PLC in the System Manager. To this end an instance of ST_PlcDriveRef must be used and the NEtID of the Byte array converted to a string.

nIndex

WORD

Index of the object that is to be read.

nSubIndex

BYTE

Subindex 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.

bComplete
Access

BOOL

If bCompleteAccess is set, the whole parameter can be read in a single access.

FB_CoERead_ByDriveRef 3: Outputs

VAR_OUTPUT
    bBusy         : BOOL;
    bError        : BOOL;
    iAdsErrId     : UINT;
    iCANopenErrId : UINT;    
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.

iAdsErrId

UINT

Returns the ADS error code of the last executed command when the bError output is set.

iCANopenErrId

UINT

Returns the CANopen error code if the bError output is set.

Example of an implementation in ST:

PROGRAM MAIN
VAR
    fbCoERead       : FB_CoERead_ByDriveRef;
    stDriveRef      : ST_DriveRef; 
    nIndex          : WORD := 16#1018;
    nSubIndex       : BYTE := 1; 
    bExecute        : BOOL := TRUE;
    tTimeout        : TIME := T#5S;
    bCompleteAccess : BOOL := TRUE;
    vendorId        : UDINT;
    bError          : BOOL;
    nAdsErrId       : UDINT;
    nCANopenErrId   : UDINT;
END_VAR

fbCoERead(
    stDriveRef:= stDriveRef, 
    nIndex:= nIndex, 
    nSubIndex:= nSubIndex, 
    pDstBuf:= ADR(vendorId), 
    cbBufLen:= SIZEOF(vendorId), 
    bExecute:= bExecute, 
    tTimeout:= tTimeout, 
    bCompleteAccess:= bCompleteAccess, 
);

IF NOT fbCoERead.bBusy THEN
    bError:=fbCoERead.bError;
    nAdsErrId:=fbCoERead.iAdsErrId;
    nCANopenErrId:=fbCoERead.iCANopenErrId;
    bExecute := FALSE;
    fbCoERead(bExecute := bExecute);
END_IF

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT