FB_EcSoeWrite

FB_EcSoeWrite 1:

The function block FB_EcSoeWrite can be used to write drive parameters by means of the “Servo drive profile over EtherCAT (SoE)” protocol. To this end the slave must have a mailbox and support the SoE protocol. The drive parameter to be written is specified with the parameters nIdn (identification number), nElement and nDriveNo.

FB_EcSoeWrite 2: Inputs

VAR_INPUT
    sNetId     : T_AmsNetId; 
    nSlaveAddr : UINT; 
    nIdn       : WORD; 
    nElement   : BYTE;
    nDriveNo   : BYTE;
    pCommand   : BOOL;
    pSrcBuf    : PVOID; 
    cbBufLen   : UDINT; 
    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)

nSlaveAddr

UINT

Fixed address of the EtherCAT slave to which the SoE write command is to be sent.

nIdn

WORD

Identification number of the parameter to be written.

nElement

BYTE

Element number of the parameter to be written
(See nElement)

nDriveNo

BYTE

Drive number

bCommand

BOOL

This parameter should be set if internal command execution is to be used.

pSrcBuf

PVOID

Address (pointer) to the transmit buffer

cbBufLen

UDINT

Number of date to be sent in bytes

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.

nElement

Element number of the parameter to be written. The following values are permitted:

Value

Description

0x01

Data status

0x02

Name (read only)

0x04

Attribute

0x08

Unit

0x10

Minimum

0x20

Maximum

0x40

Value

0x80

Default

FB_EcSoeWrite 3: Outputs

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

Example of an implementation in ST:

PROGRAM TEST_SoEWrite
VAR
    fbSoeWrite  : FB_EcSoEWrite;
    sNetId      : T_AmsNetId:= '172.16.2.131.2.1';
    bExecute    : BOOL;
    nSlaveAddr  : UINT := 1006;
    nIdn        : WORD  := 15;
    nElement    : BYTE := 0;
    nDriveNo    : BYTE := 0;
    bCommand    : BOOL := FALSE;
    val         : UINT;
    bError      : BOOL;
    nErrId      : UDINT;
END_VAR

fbSoEWrite(sNetId:= sNetId,nSlaveAddr :=nSlaveAddr, nIdn := nIdn, nElement:=nElement, nDriveNo := nDriveNo,bCommand:=bCommand, pSrcBuf:= ADR(val), cbBufLen:=SIZEOF(val),bExecute:=bExecute);
bError := fbSoEWrite.bError;
nErrId := fbSoEWrite.nErrId;

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_EtherCAT