.NET Based OPC UA Client/Server SDK  3.3.3.537
Event Monitored Items – Create Event Monitored Items

Prerequisites

A session and a subscription with the server must be established.

Description

The following dialog shows an example dialog for the Create Event Monitored Items service. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

clienttutorials_create_event_monitored_items.png

Enter the desired values for “Sampling Interval” and “Queue Size” into the corresponding input fields at “Monitoring Parameters”. To set the Sampling Interval to the same value as the Publishing Interval, enter “-1”. Check the box near “Discard Oldest” to discard the oldest values when the queue overflows. At “Monitoring Mode”, you can choose between “Reporting”, “Sampling” and “Disabled”.

Press the button “Select Node” to open a browse window for selecting the variables to monitor.

clienttutorials_create_event_monitored_items2.png

After selection, the variables are listed at “Monitored Items to Create”. Select an item and press the button “Event Filter” to add, edit or delete BaseEventTypes for each item.

clienttutorials_create_event_monitored_items3.png

Choose “Add” to open a browse window and choose additional fields to return with each event.

clienttutorials_create_event_monitored_items4.png

To modify a variable, choose “Edit” from the context menu, and double click on the value to open a dialog window for editing.

clienttutorials_create_event_monitored_items5.png

When finished, press the button “Create” to actually start monitoring the attribute “Event Notifier” of the listed items. Check the box in front of “Use Asynchronous Pattern” to call “BeginCreate” instead of “Create”.

Sample Code

The following code starts monitoring the attribute “Event Notifier” of the specified items according to the given monitoring parameters and event filter.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// nothing to do if no session.
if (session == null)
{
return;
}
// build list of items which have not been added yet.
List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
foreach (ListViewItem item in MonitoredItemsLV.Items)
{
MonitoredItem monitoredItem = (MonitoredItem)item.Tag;
if (monitoredItem.ClientHandle == 0)
{
monitoredItem.UserData = item;
monitoredItems.Add(monitoredItem);
}
}
// create monitored items.
List<StatusCode> results = m_subscription.CreateMonitoredItems(
monitoredItems,
new RequestSettings() { OperationTimeout = 10000 });
// update results in the list.
for (int ii = 0; ii < results.Count; ii++)
{
UpdateItem((ListViewItem)monitoredItems[ii].UserData, monitoredItems[ii]);
}
// adjust widths.
foreach (ColumnHeader header in MonitoredItemsLV.Columns)
{
header.Width = -2;
}
}
catch (Exception exception)
{
ExceptionDlg.ShowInnerException(this.Text, exception);
}
finally
{
Cursor = Cursors.Default;
}