FUNCTION_BLOCK FB_SoEWrite

FUNCTION_BLOCK FB_SoEWrite 1:

The functionblock FB_SoEWrite can be used to write a parameter.

VAR_INPUT

VAR_INPUT
    NetId      : T_AmsNetId := '';
    Idn        : WORD;
    Element    : BYTE;
    pSrcBuf    : DWORD;
    BufLen     : UDINT;
    Execute    : BOOL;
    Timeout    : TIME := DEFAULT_ADS_TIMEOUT;
    sPassword  : ST_SoE_String;
END_VAR

NetId: A string containing the AMS network identifier of the PC.

Idn: Parameter number for the command, i.e. "S_0_IDN + 47" for executing a S-0-0047 command

Element: Shows on which parameter part is to be read, e.g. 16#40 is the value of the parameter. Most times only write access on this value is possible, other parameter parts are write-protected.

    EC_SOE_ELEMENT_DATASTATE :BYTE :=16#01;
    EC_SOE_ELEMENT_NAME      :BYTE :=16#02;
    EC_SOE_ELEMENT_ATTRIBUTE :BYTE :=16#04;
    EC_SOE_ELEMENT_UNIT      :BYTE :=16#08;
    EC_SOE_ELEMENT_MIN       :BYTE :=16#10;
    EC_SOE_ELEMENT_MAX       :BYTE :=16#20;
    EC_SOE_ELEMENT_VALUE     :BYTE :=16#40;
    EC_SOE_ELEMENT_DEFAULT   :BYTE :=16#80;

pSrcBuf:Contains the address of the buffer containing the data to be send.

BufLen:The maximum available buffer size for the data to be written, in bytes.

Execute: The block is activated by a rising edge at this input.

Timeout: Maximum time allowed for the execution of the function block.

Password: contains the password as Sercos-String. Not yet used. The password has to be written with FB_SoEWritePassword.

VAR_IN_OUT

VAR_IN_OUT
    Axis : AXIS_REF; (* Axis reference *)
END_VAR

Axis: Axis structure (see TcMC2.lib).

VAR_OUTPUT

VAR_OUTPUT
    Busy         : BOOL;
    Error        : BOOL;
    AdsErrId     : UINT;
    SercosErrId  : UINT;
END_VAR

Busy: This output is set when the function block is activated and remains set until an acknowledgement is received.

Error: This output is set up after the bBusy output has been reset if there has been an error in transmission of the command.

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

SercosErrId: Supplies the Sercos error code associated with the most recently executed command if the Error output is set.

Sample

fbWrite : FB_SoEWrite;
Idn     : WORD;
Write   : BOOL;
WriteValue : UINT;
Password   : ST_SoE_String;

(* NcAxis *)
Axis            : AXIS_REF;
IF Write THEN
    Idn := S_0_IDN + 33;
    fbWrite(
        Axis     := Axis,
        Idn      := Idn,
        Element  :=16#40,
        pSrcBuf  :=ADR(WriteValue),
        BufLen   :=SIZEOF(WriteValue),
        Password :=Password,
        Execute  :=TRUE,
        Timeout  :=DEFAULT_ADS_TIMEOUT,
    );
    IF NOT fbWrite.Busy THEN
        fbWrite(Axis := Axis,Execute := FALSE);
        Write := FALSE;
    END_IF
END_IF