FB_EcPhysicalWriteCmd

FB_EcPhysicalWriteCmd 1:

The function block FB_EcPhysicalWriteCmd sends an EtherCAT write command (FPWR, APWR, BWR) to a specific slave or to all EtherCAT slaves (Broadcast). This command can be sent by the PLC to write to a register or the DPRAM of an EtherCAT Slave Controller.

       

VAR_INPUT

VAR_INPUT
    sNetId   : T_AmsNetId; 
    adp      : UINT;
    ado      : UINT;
    len      : UDINT;
    eType    : E_EcAdressingType := eAdressingType_Fixed;
    pSrcBuf  : DWORD;
    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.

adp: This value defines which EtherCAT slave is addressed by this command. Which slave is addressed by this value depends on the addressing type defined by eType:

eType

Description

eAdressingType_Fixed

The slave is addressed by its configured EtherCAT address. The EtherCAT addresses of all slaves can be read out with FB_EcGetAllSlaveAddr.

eAdressingType_AutoInc

The slave is addressed by its position in the bus. The first slave has an address of 0(adp=0) and the adp of  all following slaves is decremented by one.


1.Slave adp = 0
2.Slave adp = 16#ffff (-1)
3.Slave adp = 16#fffe(-2)
4.Slave adp = 16#fffd(-3)
etc.

eAdressingType_BroadCAST

All slaves are addressed by this command. The value adp can be set to 0.

ado: Physical memory(DPRAM) or register one wants to write to.

len: Count of bytes to write.

eType: Depending on the value of eType different EtherCAT commands are sent:

eType

Command

eAdressingType_Fixed

Configured Address Physical Read ( FPRD)

eAdressingType_AutoInc

Auto Increment Physical Read ( APRD)

eAdressingType_BroadCAST

Broadcast Read ( BRD)

The individual commands only differ in how the slaves are addressed (see adp).

pSrcBuf:The address (pointer) of the source buffer.

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;
    wkc     : 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.

wkc: The working counter is incremented by 1 for each EtherCAT slave that is addressed by this command. If only on EherCAT slave is addressed by this command, the working counter will be 1.

Sample for an implementation in ST: 

PROGRAM Test_PhysicalWriteCmd
VAR
    fbWriteCmd  : FB_EcPhysicalWriteCmd;
    bExecute    : BOOL;
    value       : UINT :=16#5555;
    adp         : UINT:=16#3E9;
    ado         : UINT:=16#1100;
    eType       : E_EcAdressingType := eAdressingType_Fixed;
    sNetId      : T_AmsNetId:='192.168.1.5.3.1';
    
    wkc         : UINT;
    bError      : BOOL;
    nErrId      : UDINT;
END_VAR
fbWriteCmd (sNetId:=sNetID, ado:=ado, adp:=adp, eType:=eType, LEN := SIZEOF(value), pSrcBuf:=ADR(value), bExecute:=bExecute);
wkc := fbWriteCmd.wkc;
bError:=fbWriteCmd.bError;
nErrId:=fbWriteCmd.nErrId;

Requirements

Development Environment

Target System

PLC Libraries to include

TwinCAT v2.10.0 Build >= 1314 or higher

PC or CX (x86)

TcEtherCAT.Lib
( Standard.Lib; TcBase.Lib; TcSystem.Lib, TcUtilities.Lib  are included automatically  )

TwinCAT v2.10.0 Build >= 1314 or higher

CX (ARM)