The following function blocks are used to create subscriptions and to add monitored items to this subscription.

To create a subscription, a valid connection handle is required. The connection handle is to be acquired using UA_Connect once. UA_SubscriptionCreate will create a subscription, and needs to be called for every subscription needed. The applicable SubscriptionHdl will be returned on successful execution of the function block UA_SubscriptionCreate. In order to monitor an item, a NodeHdl for that specific node is required. In other words, both the applicable UA_SubscriptionCreate and UA_NodeGetHandleList are to be called before calling the related UA_MonitoredItemAddList. UA_MonitoredItemAddList is used to add items to a subscription identified by a SubscriptionHdl. The items to be monitored are to be assigned to this FB in form of NodeHdl. UA_MonitoredItemModifyList can be used to modify monitoring settings like sampling interval, deadband type, and deadband value and hence it can be called optionally.

Take note to delete the subscription. Release the NodeHdl before you disconnect. Unless UA_SubscriptionDelete is called the Subscription will continue working, even if UA_NodeReleaseHandleList is called.

image007.png

Figure 3: Subscription and MonitoredItem sequence

Monitoring of nodes does invert the communication interaction: The control program is initiating the communication but as a consequence the values will be pushed from the OPC UA Server to the control program.

Like shown in the block diagram above, a subscription and monitored items have to be set up.

There are two modes to actually retrieve latest values within the control program:

  • Controller-sync: Using the UA_MonitoredItemAddList function block with UAMonitoringSyncMode “UAMS_ControllerSync” – updated values shall be retrieved after the call UA_MonitoredItemOperateList is finished. This means the control program can decide when values are updated. If this block is not called no updates to the control program will be delivered. The currently specified handling of monitored items and subscriptions is based on linking one UA node (identified by NodeHdl) to one PLC variable (defined in the PLC program). By calling the function block UA_MonitoredItemOperateList values delivered from the UA server are transfered into the PLC variables.Please see more detailed explanations in vendor specific documentation in particular in cases of QueueSize > 1.
  • FW-sync: The firmware could internally update the values of the memory of the controller.After adding monitored items, the control program might call UA_SubscriptionProcessed to know that any values have been changed, but it might be that the control program has no control about when updates are deployed to the control program memory.

In general, a QueueSize bigger than the PLC variable array size will return an error shown in the corresponding NodeErrorIDs in UA_MonitoredItemAddList directly after the call returns, an overflow (values lost) will be shown in the corresponding NodeQualityIDs and the minimum lost values will be shown in the corresponding MinLostValueCount.

The vendor has to decide which mode to provide. Vendor documentation should describe the selected behavior. Especially for the FW-sync way a detailed documentation should state when (i.e., beginning of control program cycle) updates are available to the control program.

A vendor may provide both modes (Controller-sync and FW-sync). The parameter QueueSize defined in structure UAMonitoringParameter indicates the mode: With configuration of QueueSize > 1 for the intention not to lose data changes it also becomes the user’s responsibility to fetch those values one at a time thus QueueSize is used to determine the mode of operation as follows:

  • QueueSize > 0 with a sample queue of that size. If ‘0’ the QueueSize ‘1’ will be applied. This means for a monitored item both, locally and on the server side as many as QueueSize data changes can be stored. The server discards data changes if the publish interval is too large. The client discards data changes if the UA_MonitoredItemOperateList cycle is not sufficient. Discard oldest policy is implied.

The mode of operation is configured independently for each monitored item (input parameter SyncMode of FB UA_MonitoredItemAddList).

Note: For vendors who support both Controller- and FW-sync: If NodeHdls are registered to a subscription with Controller-sync and afterwards UA_SubscriptionProcessed FB for this subscription will be called will result in an error shown in the corresponding NodeErrorIDs and the UA_SubscriptionProcessed FB call will fail.