FB_EcLogicalReadCmd

FB_EcLogicalReadCmd 1:

The master sends a logical EtherCAT read command (LRD) with the function block FB_EcLogicalReadCmd. In each slave, local address ranges (DPRAM) can be mapped to global logical address ranges. This command therefore addresses all EtherCAT slaves, which have mapping configured for the selected logical address range.

FB_EcLogicalReadCmd 2: Inputs

VAR_INPUT
    sNetId   : T_AmsNetId; 
    logAddr  : UDINT; 
    len      : UDINT;
    pDstBuf  : PVOID;
    bExecute : BOOL;
    tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

sNetId

T_AmsNetId

String containing the AMS network ID of the EtherCAT master device. (Type: T_AmsNetId)

logAddr

UDINT

Logical address

len

UDINT

Number of bytes to be read

pDstBuf

PVOID

Address (pointer) to the receive buffer

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.

FB_EcLogicalReadCmd 3: Outputs

VAR_OUTPUT
    bBusy  : BOOL;
    bError : BOOL;
    nErrId : UDINT;
    wkc    : 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.

nErrId

UDINT

Supplies the ADS error code associated with the most recently executed command if the bError output is set.

wkc

UINT

The working counter is incremented by each EtherCAT slave that has processed this command successfully. If only one EtherCAT slave was addressed by this command, this value should therefore be 1.

Example of an implementation in ST:

PROGRAM Test_LogicalReadCmd
VAR
    fbReadCmd : FB_EcLogicalReadCmd;
    bExecute  : BOOL;
    value     : USINT;
    logAddr   : UDINT :=16#10000;
    sNetId    : T_AmsNetId:='192.168.1.5.3.1';
    wkc       : UINT;
    bError    : BOOL;
    nErrId    : UDINT;
END_VAR

fbReadCmd (sNetId:=sNetID, logAddr:=logAddr, LEN := SIZEOF(value), pDstBuf:=ADR(value), bExecute:=bExecute);
wkc := fbReadCmd.wkc;
bError:= fbReadCmd.bError;
nErrId:= fbReadCmd.nErrId;

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT