Exemplo n.º 1
0
        /// <summary>
        /// Changes the filter used to select the events.
        /// </summary>
        public void ChangeFilter(FilterDeclaration filter, bool fetchRecent)
        {
            m_filter = filter;
            EventsLV.Items.Clear();

            int index = 0;

            if (m_filter != null)
            {
                // add or update existing columns.
                for (int ii = 0; ii < m_filter.Fields.Count; ii++)
                {
                    if (m_filter.Fields[ii].DisplayInList)
                    {
                        if (index >= EventsLV.Columns.Count)
                        {
                            EventsLV.Columns.Add(new ColumnHeader());
                        }

                        EventsLV.Columns[index].Text      = m_filter.Fields[ii].InstanceDeclaration.DisplayName;
                        EventsLV.Columns[index].TextAlign = HorizontalAlignment.Left;
                        index++;
                    }
                }
            }

            // remove extra columns.
            while (index < EventsLV.Columns.Count)
            {
                EventsLV.Columns.RemoveAt(EventsLV.Columns.Count - 1);
            }

            // adjust the width of the columns.
            for (int ii = 0; ii < EventsLV.Columns.Count; ii++)
            {
                EventsLV.Columns[ii].Width = -2;
            }

            // fetch recent history.
            if (fetchRecent)
            {
                ReadRecentHistory();
            }

            // update subscription.
            if (m_subscription != null && m_filter != null)
            {
                m_monitoredItem.Filter = m_filter.GetFilter();
                m_subscription.ApplyChanges();
            }
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the items with the current filter.
        /// </summary>
        private void UpdateItems()
        {
            List <FilterDeclarationField> fields = new List <FilterDeclarationField>();

            foreach (FilterDeclarationField field in m_filter.Fields)
            {
                // only keep fields that are used.
                if (field.Selected || field.FilterEnabled)
                {
                    fields.Add(field);
                    continue;
                }

                // add mandatory fields.
                switch (field.InstanceDeclaration.BrowsePathDisplayText)
                {
                case Opc.Ua.BrowseNames.EventId:
                case Opc.Ua.BrowseNames.EventType:
                case Opc.Ua.BrowseNames.Time:
                {
                    field.Selected = true;
                    fields.Add(field);
                    break;
                }
                }
            }

            m_filter.Fields = fields;

            // construct filter.
            EventFilter filter = m_filter.GetFilter();

            // update items.
            for (int ii = 0; ii < m_dataset.Tables[0].Rows.Count; ii++)
            {
                MonitoredItem monitoredItem = (MonitoredItem)m_dataset.Tables[0].Rows[ii][0];
                monitoredItem.Filter = filter;
            }

            // apply changes.
            m_subscription.ApplyChanges();

            // show results.
            for (int ii = 0; ii < m_dataset.Tables[0].Rows.Count; ii++)
            {
                DataRow       row           = m_dataset.Tables[0].Rows[ii];
                MonitoredItem monitoredItem = (MonitoredItem)row[0];
                UpdateRow(row, monitoredItem.Status);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadRecentHistory()
        {
            // check if session is active.
            if (m_session != null)
            {
                // check if area supports history.
                IObject area = m_session.NodeCache.Find(m_areaId) as IObject;

                if (area != null && ((area.EventNotifier & EventNotifiers.HistoryRead) != 0))
                {
                    // get the last hour or 10 events.
                    ReadEventDetails details = new ReadEventDetails();
                    details.StartTime        = DateTime.UtcNow.AddSeconds(30);
                    details.EndTime          = details.StartTime.AddHours(-1);
                    details.NumValuesPerNode = 10;
                    details.Filter           = m_filter.GetFilter();

                    // read the history.
                    ReadHistory(details, m_areaId);
                }
            }
        }
Exemplo n.º 5
0
        /// <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();
        }