Monitoring mode is used to read the values of server variables. It replaces the pooling method by periodically calling the UA_ReadList method.

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

  • Creating a subscription: To create a subscription, a valid connection handle is needed. The connection handle is acquired using UA_Connect one time only. UA_SubscriptionCreate creates a subscription and needs to be called for each subscription that is needed. The applicable SubscriptionHdl is returned on successful execution of the function block UA_SubscriptionCreate.

  • Monitoring an item: To monitor an item, a NodeHdl for that specific node is necessary. Thus, both the applicable UA_SubscriptionCreate and UA_NodeGetHandleList are to be called before calling the related UA_MonitoredItemAddList.

  • Adding items: UA_MonitoredItemAddList is used to add items to a subscription identified by a SubscriptionHdl. The items to be monitored are assigned to this FB in form of NodeHdl.

  • Terminating the subscription: When communication is finished, remember to delete the subscription. Release the NodeHdl before you disconnect. If UA_SubscriptionDelete is not called, the subscription will continue working, even if UA_NodeReleaseHandleList is called.

Monitoring Modes

Monitoring modes inverts the communication interaction: The control program initiates the communication, but this causes values to be pushed from the OPC UA server to the control program.

As shown in the diagram above, a subscriptions and monitored items need to be configured.

There are two modes for retrieving the most current values within the control program:

  • Controller-sync:

    Using the UA_MonitoredItemAddList function block with UAMonitoringSyncMode (UAMS_ControllerSync): updated values are retrieved after the call UA_MonitoredItemOperateList is finished. This means the logic of the control program determines when values are updated. If this block is not called, no updates will be delivered to the control program.

    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 transferred into the PLC variables.

  • FW-sync:

    The firmware internally updates the values in the controller memory.

    After adding monitored items, the control program might call UA_SubscriptionProcessed to learn if any values have been changed. However, the control program may have no control about when updates are deployed to the control program memory. In FW-sync, the update is performed at beginning of the MAST task.

Both monitoring modes – controller-sync and FW sync – are provided.

In general, a QueueSize greater than the PLC variable array size returns a detected error shown in the corresponding NodeErrorIDs in UA_MonitoredItemAddList immediately after the call returns. An overflow (values lost) is reported in the corresponding NodeQualityIDs, and the minimum lost values will be reported in the corresponding MinLostValueCount.

In general, a QueueSize greater than the PLC variable array size returns a detected error shown in the corresponding NodeErrorIDs in UA_MonitoredItemAddList immediately after the call returns. An overflow (values lost) is reported in the corresponding NodeQualityIDs, and the minimum lost values will be reported in the corresponding MinLostValueCount.

The parameter QueueSize defined in structure UAMonitoringParameter can be used to indicate the monitoring 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 maximum supported QueueSize is 3.