Subscription (FB)¶
FUNCTION_BLOCK PUBLIC ABSTRACT Subscription EXTENDS CBML.LConC IMPLEMENTS ISubscription, IOPCUAClientSubscriptionCallback
Basic function block to create subscriptions. A subscription contains an array of Items to subscribe.
Note
This kind of function block should be generated automatically by a configuration
Usage (Declaration):
{attribute 'no_assign'}
{attribute 'call_after_init'}
FUNCTION_BLOCK FINAL Subscription EXTENDS UA.Subscription
VAR CONSTANT
    lrInterval : LREAL := 500.0;
END_VAR
VAR
    _aItems : ARRAY[0..4] OF UA.Item := [
        (*  0 *) (eType:=UA.IEC_BYTE, psNodeId:=ADR('ns=4;s=path.byValue'), lrInterval:=lrInterval),
        (*  1 *) (eType:=UA.IEC_BOOL, psNodeId:=ADR('ns=4;s=path.xValue'), lrInterval:=lrInterval),
        (*  2 *) (eType:=UA.IEC_DATE, psNodeId:=ADR('ns=4;s=path.datValue'), lrInterval:=lrInterval),
        (*  3 *) (eType:=UA.IEC_DINT, psNodeId:=ADR('ns=4;s=path.diValue'), lrInterval:=lrInterval),
        (*  4 *) (eType:=UA.IEC_DATEANDTIME, psNodeId:=ADR('ns=4;s=path.dtValue'), lrInterval:=lrInterval),
    ];
END_VAR
Note
Don’t forget the SUPER^(); in the implementation part.
Override the Init method of UA.Subscription and set _pItem and _udiItemCount:
{attribute 'call_after_init'}
METHOD PROTECTED FINAL Init
    _pItem := ADR(_aItems);
    _udiItemCount := SIZEOF(_aItems) / SIZEOF(UA.Item);
    SUPER^.Init();
Implement the method PrepareValues of UA.Subscription:
METHOD PROTECTED FINAL PrepareValues : UA.ERROR
    (*  0 *) _aItems[0].pValue := ADR(byValue);
    (*  1 *) _aItems[1].pValue := ADR(xValue);
    (*  2 *) _aItems[2].pValue := ADR(datValue);
    (*  3 *) _aItems[3].pValue := ADR(diValue);
    (*  4 *) _aItems[4].pValue := ADR(dtValue);
Here an example of the call:
mySubscription : Subscription := (
    itfConnection:=_Connection,
    xPublishingEnabled := TRUE,
    lrPublishingInterval := 100,
    udiLifetimeCount := 150,
    udiMaxKeepAliveCount := 50,
    udiMaxNotificationsPerPublish := 100,
    byPriority := 0
);
- InOut:
- Scope - Name - Type - Initial - Comment - Inherited from - Input - xEnable- BOOL- LConC - Output - xBusy- BOOL- LConC - xError- BOOL- LConC - Input - itfConnection- The connection of the UA.Client - xPublishingEnabled- BOOL- TRUE - Enables or disables the Subscription. TRUE: publishing is enabled for the Subscription. FALSE; publishing is disabled for the Subscription. The value of this parameter does not affect the value of the monitoring mode Attribute of MonitoredItems. - lrPublishingInterval- LREAL- This interval defines the cyclic rate that the Subscription is being requested to return Notifications to the Client. This interval is expressed in milliseconds. - udiLifetimeCount- UDINT- Requested lifetime count. The lifetime count shall be a minimum of three times the keep keep-alive count. When the publishing timer has expired this number of times without a Publish request being available to send a NotificationMessage, then the Subscription shall be deleted by the Server. - udiMaxKeepAliveCount- UDINT- Requested maximum keep-alive count. When the publishing timer has expired this number of times without requiring any NotificationMessage to be sent, the Subscription sends a keep-alive Message to the Client. - udiMaxNotificationsPerPublish- UDINT- The maximum number of notifications that the Client wishes to receive in a single Publish response. A value of zero indicates that there is no limit. - byPriority- BYTE- Indicates the relative priority of the Subscription. When more than one Subscription needs to send Notifications, the Server should de-queue a Publish request to the Subscription with the highest priority number. For Subscriptions with equal priority the Server should de-queue Publish requests in a round-robin fashion. A Client that does not require special priority settings should set this value to zero. - Output - xActive- BOOL- TRUE if the subscription is active. - eState- The subscription state. - eErrorID- Error code. 
Methods:
Structure:
