DeviceAR (FB)

FUNCTION_BLOCK DeviceAR

A Profinet Device application uses this function block for controlling all phases of the connection establishment.

In a Profinet context, this connection is also called Application Relation (AR). The AR maintains a list of configured modules, parameters, and cyclic and acylic communication channels.

One instance of this function block is used for one instance of an AR.

The connection establishment phase consist of these steps:

- Controller sends a Connect-req to the device. This request contains a list of submodules that the controller intends to control (and to exchange cyclic data).

- The Device checks the list of expected vs. the real submodules. In case of a mismatch the stack adds a Module Diff Block which contains all mismatching modules to the Connect-res.

- The Controller sends paramterization data for each configured submodule. The Profinet Device application can receive the parameter data with CommFB.RCVREC function block.

- The Controller sends a PrmEnd-req. for indicating that the paramterization phase is finished.

- The Device application applies the received parameterization data to its internal logic and the hardware.

- The Device application sends the ApplicationReady-req to th controller for indicating that it is ready for data-exchange.

The use of this fucntion block is optional.

But note that once it is enabled/registered for a Profinet Device, the application is responsible for confirming all AR related events within a certain time (typically 20 sec.).

Otherwise the controller will abort the connection with some error code like 'AR CMI timeout'.

Update Diagnosis

PROGRAM PLC_PRG
VAR
    ar : ProfinetCommon.DeviceAR;   // FB for controlling the AR establishment
    i : DINT;
    checkExp : ProfinetCommon.CheckExpSubmodule;
    moduleDiffCounter : DINT;
    prmDelay : TON;         // some delay for parameterizing the device (example)
    output : DINT;          // a counter variable
END_VAR


ar(xEnable := TRUE, DeviceID := pnDevice.DeviceID);
IF(ar.xAborted) THEN            // connection has been aborted
    ar(xConfirmConnect := FALSE, xConfirmPrmEnd := FALSE, xApplReady := FALSE);     //reset commands
    moduleDiffCounter := 0;     // reset counter
    prmDelay(IN := FALSE);      // reset timer

ELSIF(ar.xData) THEN                // connection estblishment phase sucessful, AR in data exchange
    output := output + 1;

ELSIF(ar.xConnect) THEN                 // received Connect-req., the AR establishment started
    IF(NOT ar.xConfirmConnect) THEN     // not yet confirmed ?
        // check submodule config the controller expects:
        checkExp(xEnable := TRUE, AR_ID := ar.AR_ID);
        FOR i := 0 TO checkExp.ExpectedSubmoduleCount - 1 DO
            checkExp(Index := i);
            IF(checkExp.xModuleDiff) THEN       //some module mismatch, see details
                moduleDiffCounter := moduleDiffCounter + 1;     // count mismatching modules
            END_IF
        END_FOR
        ar(xConfirmConnect := TRUE);        // confirm Connect-req. from controller
    END_IF

    IF(ar.xPrmEnd) THEN                     // received PrmEnd-req. from controller
        ar(xConfirmPrmEnd := TRUE);         // confirm PrmEnd-req.
        prmDelay(IN := TRUE, PT := T#2S);   // start prm-delay timer
    END_IF

    prmDelay();
    IF(prmDelay.Q) THEN             // timer expired
        ar(xApplReady := TRUE);     // Send Application-Ready to Controller --> AR will get into 'Data' state
    END_IF
END_IF
InOut:

Scope

Name

Type

Initial

Comment

Input

xEnable

BOOL

Enable function

DeviceID

BYTE

ID of the Profinet Device in the local Profinet Device application.

xConfirmConnect

BOOL

Send Connect-cnf to controller

xConfirmPrmEnd

BOOL

Send PrmEnd confirmation to controller

xApplReady

BOOL

Send Application-Ready to controller

Output

xBusy

BOOL

DeviceAR is operating and will receive connection related request and events.

xError

BOOL

DeviceAR does not operate due to internal error.

AR_ID

DWORD

CommFB.Constants.INVALID_ID

ID of this AR endpoint.

AR_Status

DeviceAR_State

Status of this AR endpoint.

xConnect

BOOL

Received Connect-Req. from Controller.

xPrmEnd

BOOL

Received PrmEnd-Ind from Controller: All data-records / parameters have been transmitted.

xData

BOOL

AR is in Data-Exchange

xAborted

BOOL

AR has been Aborted. (Abort reason see PNIOStatus)

PNIOStatus

UDINT

Profinet specific protocol status/error code.

ARInfo

AR_Info

Some information on the current AR