A filter to apply when monitoring data changes.
Пример #1
0
        /// <summary>
        /// Returns the AbsoluteDeadband if the filter specifies one. Zero otherwize.
        /// </summary>
        public static double GetAbsoluteDeadband(MonitoringFilter filter)
        {
            DataChangeFilter datachangeFilter = filter as DataChangeFilter;

            if (datachangeFilter == null)
            {
                return(0.0);
            }

            if (datachangeFilter.DeadbandType != (uint)Opc.Ua.DeadbandType.Absolute)
            {
                return(0.0);
            }

            return(datachangeFilter.DeadbandValue);
        }
Пример #2
0
        /// <summary>
        /// Prompts the user to edit the monitored item.
        /// </summary>
        public bool ShowDialog(Session session, MonitoredItem monitoredItem, bool isEvent)
        {
            if (!monitoredItem.Created)
            {
                NodeBTN.Session = session;
                NodeBTN.SelectedNode = monitoredItem.StartNodeId;
            }

            // hide fields not used for events.
            NodeLB.Visible = !monitoredItem.Created;
            NodeTB.Visible = !monitoredItem.Created;
            NodeBTN.Visible = !monitoredItem.Created;
            AttributeLB.Visible = !isEvent && !monitoredItem.Created;
            AttributeCB.Visible = !isEvent && !monitoredItem.Created;
            IndexRangeLB.Visible = !isEvent && !monitoredItem.Created;
            IndexRangeTB.Visible = !isEvent && !monitoredItem.Created;
            DataEncodingLB.Visible = !isEvent && !monitoredItem.Created;
            DataEncodingCB.Visible = !isEvent && !monitoredItem.Created;
            MonitoringModeLB.Visible = !monitoredItem.Created;
            MonitoringModeCB.Visible = !monitoredItem.Created;
            SamplingIntervalLB.Visible = true;
            SamplingIntervalUP.Visible = true;
            QueueSizeLB.Visible = !isEvent;
            QueueSizeUP.Visible = !isEvent;
            DiscardOldestLB.Visible = true;
            DiscardOldestCK.Visible = true;
            DeadbandTypeLB.Visible = !isEvent;
            DeadbandTypeCB.Visible = !isEvent;
            DeadbandValueLB.Visible = !isEvent;
            DeadbandValueUP.Visible = !isEvent;
            TriggerTypeLB.Visible = !isEvent;
            TriggerTypeCB.Visible = !isEvent;
            
            // fill in values.
            SamplingIntervalUP.Value = monitoredItem.SamplingInterval;
            DiscardOldestCK.Checked = monitoredItem.DiscardOldest;

            if (!isEvent)
            {
                AttributeCB.SelectedIndex = (int)(monitoredItem.AttributeId - 1);
                IndexRangeTB.Text = monitoredItem.IndexRange;
                MonitoringModeCB.SelectedItem = monitoredItem.MonitoringMode;
                QueueSizeUP.Value = monitoredItem.QueueSize;

                DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter;

                if (filter != null)
                {
                    DeadbandTypeCB.SelectedItem = (DeadbandType)filter.DeadbandType;
                    DeadbandValueUP.Value = (decimal)filter.DeadbandValue;
                    TriggerTypeCB.SelectedItem = filter.Trigger;
                }

                if (!monitoredItem.Created)
                {
                    // fetch the available encodings for the first node in the list from the server.
                    IVariableBase variable = session.NodeCache.Find(monitoredItem.StartNodeId) as IVariableBase;

                    DataEncodingCB.Items.Add(new EncodingInfo());
                    DataEncodingCB.SelectedIndex = 0;

                    if (variable != null)
                    {
                        if (session.NodeCache.IsTypeOf(variable.DataType, Opc.Ua.DataTypeIds.Structure))
                        {
                            foreach (INode encoding in session.NodeCache.Find(variable.DataType, Opc.Ua.ReferenceTypeIds.HasEncoding, false, true))
                            {
                                DataEncodingCB.Items.Add(new EncodingInfo() { EncodingName = encoding.BrowseName });

                                if (monitoredItem.Encoding == encoding.BrowseName)
                                {
                                    DataEncodingCB.SelectedIndex = DataEncodingCB.Items.Count - 1;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                AttributeCB.SelectedIndex = ((int)Attributes.EventNotifier - 1);
            }

            if (base.ShowDialog() != DialogResult.OK)
            {
                return false;
            }

            // update monitored item.
            if (!monitoredItem.Created)
            {
                monitoredItem.StartNodeId = NodeBTN.SelectedNode;
                monitoredItem.DisplayName = session.NodeCache.GetDisplayText(monitoredItem.StartNodeId);
                monitoredItem.RelativePath = null;
                monitoredItem.AttributeId = (uint)(AttributeCB.SelectedIndex + 1);
                monitoredItem.MonitoringMode = (MonitoringMode)MonitoringModeCB.SelectedItem;
            }

            monitoredItem.SamplingInterval = (int)SamplingIntervalUP.Value;
            monitoredItem.DiscardOldest = DiscardOldestCK.Checked;

            if (!isEvent)
            {
                if (!monitoredItem.Created)
                {
                    monitoredItem.IndexRange = IndexRangeTB.Text.Trim();
                    monitoredItem.Encoding = ((EncodingInfo)DataEncodingCB.SelectedItem).EncodingName;
                }

                monitoredItem.QueueSize = (uint)QueueSizeUP.Value;

                DataChangeTrigger trigger = (DataChangeTrigger)TriggerTypeCB.SelectedItem;
                DeadbandType deadbandType = (DeadbandType)DeadbandTypeCB.SelectedItem;

                if (monitoredItem.Filter != null || deadbandType != DeadbandType.None || trigger != DataChangeTrigger.StatusValue)
                {
                    DataChangeFilter filter = new DataChangeFilter();
                    filter.DeadbandType = (uint)deadbandType;
                    filter.DeadbandValue = (double)DeadbandValueUP.Value;
                    filter.Trigger = trigger;
                    monitoredItem.Filter = filter;
                }
            }
            else
            {
                if (!monitoredItem.Created)
                {
                    monitoredItem.IndexRange = null;
                    monitoredItem.Encoding = null;
                }

                monitoredItem.QueueSize = 0;
                monitoredItem.Filter = new EventFilter();
            }
            
            return true;
        }
Пример #3
0
        /// <summary>
        /// Changes the deadband for the currently selected monitored items.
        /// </summary>
        private void Monitoring_Deadband_Click(object sender, EventArgs e)
        {
            try
            {
                // check if operation is currently allowed.
                if (m_session == null || m_subscription == null || MonitoredItemsLV.SelectedItems.Count == 0)
                {
                    return;
                }

                // determine the filter being requested.
                DataChangeFilter filter = new DataChangeFilter();
                filter.Trigger = DataChangeTrigger.StatusValue;

                if (sender == Monitoring_Deadband_Absolute_5MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Absolute;
                    filter.DeadbandValue = 5.0;
                }
                else if (sender == Monitoring_Deadband_Absolute_10MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Absolute;
                    filter.DeadbandValue = 10.0;
                }
                else if (sender == Monitoring_Deadband_Absolute_25MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Absolute;
                    filter.DeadbandValue = 25.0;
                }
                else if (sender == Monitoring_Deadband_Percentage_1MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Percent;
                    filter.DeadbandValue = 1.0;
                }
                else if (sender == Monitoring_Deadband_Percentage_5MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Percent;
                    filter.DeadbandValue = 5.0;
                }
                else if (sender == Monitoring_Deadband_Percentage_10MI)
                {
                    filter.DeadbandType = (uint)DeadbandType.Percent;
                    filter.DeadbandValue = 10.0;
                }
                else
                {
                    filter = null;
                }

                // update the monitoring mode.
                List<MonitoredItem> itemsToChange = new List<MonitoredItem>();

                for (int ii = 0; ii < MonitoredItemsLV.SelectedItems.Count; ii++)
                {
                    MonitoredItem monitoredItem = MonitoredItemsLV.SelectedItems[ii].Tag as MonitoredItem;

                    if (monitoredItem != null)
                    {
                        monitoredItem.Filter = filter;
                        itemsToChange.Add(monitoredItem);
                    }
                }

                // apply the changes to the server.
                m_subscription.ApplyChanges();

                // update the display.
                for (int ii = 0; ii < itemsToChange.Count; ii++)
                {
                    ListViewItem item = itemsToChange[ii].Handle as ListViewItem;

                    if (item != null)
                    {
                        item.SubItems[8].Text = String.Empty;

                        if (ServiceResult.IsBad(itemsToChange[ii].Status.Error))
                        {
                            itemsToChange[ii].Filter = null;
                            item.SubItems[8].Text = itemsToChange[ii].Status.Error.StatusCode.ToString();
                        }

                        item.SubItems[4].Text = DeadbandFilterToText(itemsToChange[ii].Status.Filter);
                    }
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }