/// <summary> /// Creates the subscription. /// </summary> private void CreateSubscription() { // create the default subscription. m_subscription = new Subscription(); m_subscription.DisplayName = null; m_subscription.PublishingInterval = 1000; m_subscription.KeepAliveCount = 10; m_subscription.LifetimeCount = 100; m_subscription.MaxNotificationsPerPublish = 1000; m_subscription.PublishingEnabled = true; m_subscription.TimestampsToReturn = TimestampsToReturn.Both; m_session.AddSubscription(m_subscription); m_subscription.Create(); // a table used to track event types. m_eventTypeMappings = new Dictionary <NodeId, NodeId>(); NodeId knownEventId = ExpandedNodeId.ToNodeId(ObjectTypeIds.SystemCycleStatusEventType, m_session.NamespaceUris); m_knownEventTypes = new Dictionary <NodeId, Type>(); m_knownEventTypes.Add(knownEventId, typeof(SystemCycleStatusEventState)); TypeDeclaration type = new TypeDeclaration(); type.NodeId = ExpandedNodeId.ToNodeId(ObjectTypeIds.SystemCycleStatusEventType, m_session.NamespaceUris); type.Declarations = ClientUtils.CollectInstanceDeclarationsForType(m_session, type.NodeId); // the filter to use. m_filter = new FilterDeclaration(type, null); // declate callback. m_MonitoredItem_Notification = new MonitoredItemNotificationEventHandler(MonitoredItem_Notification); // create a monitored item based on the current filter settings. m_monitoredItem = new MonitoredItem(); m_monitoredItem.StartNodeId = Opc.Ua.ObjectIds.Server; m_monitoredItem.AttributeId = Attributes.EventNotifier; m_monitoredItem.SamplingInterval = 0; m_monitoredItem.QueueSize = 1000; m_monitoredItem.DiscardOldest = true; m_monitoredItem.Filter = m_filter.GetFilter(); // set up callback for notifications. m_monitoredItem.Notification += m_MonitoredItem_Notification; m_subscription.AddItem(m_monitoredItem); m_subscription.ApplyChanges(); }