Exemplo n.º 1
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 public DataChangeMonitoredItem(
     MonitoredNode source,
     uint id,
     uint attributeId,
     NumericRange indexRange,
     QualifiedName dataEncoding,
     DiagnosticsMasks diagnosticsMasks,
     TimestampsToReturn timestampsToReturn,
     MonitoringMode monitoringMode,
     uint clientHandle,
     double samplingInterval,
     bool alwaysReportUpdates)
 {
     m_source = source;
     m_id = id;
     m_attributeId = attributeId;
     m_indexRange = indexRange;
     m_dataEncoding = dataEncoding;
     m_timestampsToReturn = timestampsToReturn;
     m_diagnosticsMasks = diagnosticsMasks;
     m_monitoringMode = monitoringMode;
     m_clientHandle = clientHandle;
     m_samplingInterval = samplingInterval;
     m_nextSampleTime = DateTime.UtcNow.Ticks;
     m_readyToPublish = false;
     m_readyToTrigger = false;
     m_alwaysReportUpdates = alwaysReportUpdates;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public bool ShowDialog(ref MonitoringMode monitoringMode)
        {
            MonitoringModeCB.SelectedItem = monitoringMode;

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

            monitoringMode = (MonitoringMode)MonitoringModeCB.SelectedItem;

            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public DataChangeMonitoredItem(
            MonitoredNode source,
            uint id,
            uint attributeId,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval,
            uint queueSize,
            bool discardOldest,
            DataChangeFilter filter,
            Range range,
            bool alwaysReportUpdates)
        {
            m_source = source;
            m_id = id;
            m_attributeId = attributeId;
            m_indexRange = indexRange;
            m_dataEncoding = dataEncoding;
            m_timestampsToReturn = timestampsToReturn;
            m_diagnosticsMasks = diagnosticsMasks;
            m_monitoringMode = monitoringMode;
            m_clientHandle = clientHandle;
            m_samplingInterval = samplingInterval;
            m_nextSampleTime = DateTime.UtcNow.Ticks;
            m_readyToPublish = false;
            m_readyToTrigger = false;
            m_queue = null;
            m_filter = filter;
            m_range = 0;
            m_alwaysReportUpdates = alwaysReportUpdates;
        
            if (range != null)
            {
                m_range = range.High  - range.Low;
            }

            if (queueSize > 1)
            {
                m_queue = new MonitoredItemQueue();
                m_queue.SetQueueSize(queueSize, discardOldest, diagnosticsMasks);
                m_queue.SetSamplingInterval(samplingInterval);
            }
        }
        /// <summary>
        /// Creates the subscription.
        /// </summary>
        private void CreateSubscription()
        {
            if (m_subscription != null)
            {
                m_subscription.Dispose();
                m_subscription = null;
            }

            // get the current session.
            Session session = m_server.Session;

            if (session == null)
            {
                return;
            }

            // create the subscription.
            m_subscription = new Subscription();
            m_subscription.PublishingEnabled          = Active;
            m_subscription.PublishingInterval         = (int)Math.Max(BufferTime, 1000);
            m_subscription.KeepAliveCount             = (uint)Math.Max(Math.Ceiling(((double)KeepAlive) / m_subscription.PublishingInterval), 10);
            m_subscription.LifetimeCount              = m_subscription.KeepAliveCount * 3;
            m_subscription.MaxNotificationsPerPublish = MaxSize;
            m_subscription.TimestampsToReturn         = TimestampsToReturn.Neither;
            m_subscription.Priority                  = 0;
            m_subscription.FastEventCallback         = OnEventNotification;
            m_subscription.DisableMonitoredItemCache = true;

            session.AddSubscription(m_subscription);
            m_subscription.Create();

            // update the monitored items.
            EventFilter    filter         = m_filter.GetFilter();
            MonitoringMode monitoringMode = (Active)?MonitoringMode.Reporting:MonitoringMode.Disabled;

            foreach (MonitoredItem monitoredItem in m_notifiers.Values)
            {
                monitoredItem.Filter         = filter;
                monitoredItem.MonitoringMode = monitoringMode;
                m_subscription.AddItem(monitoredItem);
            }

            m_subscription.ApplyChanges();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new data change monitored item.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="monitoredItemId">The unique identifier for the monitiored item.</param>
        /// <param name="attributeId">The attribute to monitor.</param>
        /// <param name="indexRange">The index range to use for array values.</param>
        /// <param name="dataEncoding">The data encoding to return for structured values.</param>
        /// <param name="diagnosticsMasks">The diagnostics masks to use.</param>
        /// <param name="timestampsToReturn">The timestamps to return.</param>
        /// <param name="monitoringMode">The initial monitoring mode.</param>
        /// <param name="clientHandle">The handle assigned by the client.</param>
        /// <param name="samplingInterval">The sampling interval.</param>
        /// <param name="queueSize">The queue size.</param>
        /// <param name="discardOldest">Whether to discard the oldest values when the queue overflows.</param>
        /// <param name="filter">The data change filter to use.</param>
        /// <param name="range">The range to use when evaluating a percentage deadband filter.</param>
        /// <param name="alwaysReportUpdates">Whether the monitored item should skip the check for a change in
        /// value.</param>
        /// <returns>The new monitored item.</returns>
        public DataChangeMonitoredItem CreateDataChangeItem(
            ISystemContext context,
            uint monitoredItemId,
            uint attributeId,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval,
            uint queueSize,
            bool discardOldest,
            DataChangeFilter filter,
            Range range,
            bool alwaysReportUpdates)
        {
            DataChangeMonitoredItem monitoredItem = new DataChangeMonitoredItem(
                this,
                monitoredItemId,
                attributeId,
                indexRange,
                dataEncoding,
                diagnosticsMasks,
                timestampsToReturn,
                monitoringMode,
                clientHandle,
                samplingInterval,
                queueSize,
                discardOldest,
                filter,
                range,
                alwaysReportUpdates);

            if (m_monitoredItems == null)
            {
                m_monitoredItems      = new List <DataChangeMonitoredItem>();
                m_node.OnStateChanged = OnNodeChange;
            }

            m_monitoredItems.Add(monitoredItem);

            return(monitoredItem);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes the object with its node type.
 /// </summary>
 public MemoryBufferMonitoredItem(
     IServerInternal server,
     INodeManager nodeManager,
     object mangerHandle,
     uint offset,
     uint subscriptionId,
     uint id,
     Session session,
     ReadValueId itemToMonitor,
     DiagnosticsMasks diagnosticsMasks,
     TimestampsToReturn timestampsToReturn,
     MonitoringMode monitoringMode,
     uint clientHandle,
     MonitoringFilter originalFilter,
     MonitoringFilter filterToUse,
     Range range,
     double samplingInterval,
     uint queueSize,
     bool discardOldest,
     double minimumSamplingInterval)
     :
     base(
         server,
         nodeManager,
         mangerHandle,
         subscriptionId,
         id,
         session,
         itemToMonitor,
         diagnosticsMasks,
         timestampsToReturn,
         monitoringMode,
         clientHandle,
         originalFilter,
         filterToUse,
         range,
         samplingInterval,
         queueSize,
         discardOldest,
         minimumSamplingInterval)
 {
     m_offset = offset;
 }
		/// <summary>
		/// Initializes the object with its node type.
		/// </summary>
        public MemoryBufferMonitoredItem(
            IServerInternal     server,
            INodeManager        nodeManager,
            object              mangerHandle,
            uint                offset,
            uint                subscriptionId,
            uint                id,
            Session             session,
            ReadValueId         itemToMonitor,
            DiagnosticsMasks    diagnosticsMasks,
            TimestampsToReturn  timestampsToReturn,
            MonitoringMode      monitoringMode,
            uint                clientHandle,
            MonitoringFilter    originalFilter,
            MonitoringFilter    filterToUse,
            Range               range,
            double              samplingInterval,
            uint                queueSize,
            bool                discardOldest,
            double              minimumSamplingInterval)
        :
            base(
                server,
                nodeManager,
                mangerHandle,
                subscriptionId,
                id,
                session,
                itemToMonitor,
                diagnosticsMasks,
                timestampsToReturn,
                monitoringMode,
                clientHandle,
                originalFilter,
                filterToUse,
                range,
                samplingInterval,
                queueSize,
                discardOldest,
                minimumSamplingInterval)
		{
            m_offset = offset;
        }
Exemplo n.º 8
0
        public static Entry For(MonitoringMode mm)
        {
            string mmText = null;

            switch (mm)
            {
            case MonitoringMode.Disabled:
                mmText = "Disabled";
                break;

            case MonitoringMode.Sampling:
                mmText = "Sampling";
                break;

            case MonitoringMode.Reporting:
                mmText = "Reporting";
                break;
            }
            return(new StringEntry(mmText));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Called after changing the MonitoringMode for a MonitoredItem.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="handle">The handle for the node.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        /// <param name="previousMode">The previous monitoring mode.</param>
        /// <param name="monitoringMode">The current monitoring mode.</param>
        protected override void OnMonitoringModeChanged(
            ServerSystemContext context,
            NodeHandle handle,
            MonitoredItem monitoredItem,
            MonitoringMode previousMode,
            MonitoringMode monitoringMode) {
            if (SystemScanRequired(handle.MonitoredNode, monitoredItem)) {
                BaseVariableState source = handle.Node as BaseVariableState;

                if (previousMode != MonitoringMode.Disabled &&
                    monitoredItem.MonitoringMode == MonitoringMode.Disabled) {
                    m_system.StopMonitoringValue(monitoredItem.Id);
                }

                if (previousMode == MonitoringMode.Disabled &&
                    monitoredItem.MonitoringMode != MonitoringMode.Disabled) {
                    m_system.StartMonitoringValue(monitoredItem.Id, monitoredItem.SamplingInterval, source);
                }
            }
        }
Exemplo n.º 10
0
        private void SetMonitoringModeMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_subscription == null)
                {
                    return;
                }

                MonitoredItem[] monitoredItems = (MonitoredItem[])GetSelectedItems(typeof(MonitoredItem));

                if (monitoredItems.Length > 0)
                {
                    MonitoringMode monitoringMode = monitoredItems[0].MonitoringMode;

                    if (!new SetMonitoringModeDlg().ShowDialog(ref monitoringMode))
                    {
                        return;
                    }

                    List <ServiceResult> errors = m_subscription.SetMonitoringMode(monitoringMode, monitoredItems);

                    if (errors != null)
                    {
                        string errorString = string.Empty;

                        foreach (ServiceResult result in errors)
                        {
                            errorString += System.Environment.NewLine + result;
                        }

                        throw new Exception(String.Format("SetMonitoringMode error: {0}", errorString));
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new monitored item.
 /// </summary>
 /// <param name="server">The server.</param>
 /// <param name="nodeManager">The node manager.</param>
 /// <param name="managerHandle">The manager handle.</param>
 /// <param name="subscriptionId">The subscription id.</param>
 /// <param name="id">The id.</param>
 /// <param name="session">The session.</param>
 /// <param name="itemToMonitor">The item to monitor.</param>
 /// <param name="diagnosticsMasks">The diagnostics masks.</param>
 /// <param name="timestampsToReturn">The timestamps to return.</param>
 /// <param name="monitoringMode">The monitoring mode.</param>
 /// <param name="clientHandle">The client handle.</param>
 /// <param name="originalFilter">The original filter.</param>
 /// <param name="filterToUse">The filter to use.</param>
 /// <param name="range">The range.</param>
 /// <param name="samplingInterval">The sampling interval.</param>
 /// <param name="queueSize">Size of the queue.</param>
 /// <param name="discardOldest">if set to <c>true</c> [discard oldest].</param>
 /// <param name="minimumSamplingInterval">The minimum sampling interval.</param>
 /// <returns>The monitored item.</returns>
 protected virtual MonitoredItem CreateMonitoredItem(
     IServerInternal server,
     INodeManager nodeManager,
     object managerHandle,
     uint subscriptionId,
     uint id,
     Session session,
     ReadValueId itemToMonitor,
     DiagnosticsMasks diagnosticsMasks,
     TimestampsToReturn timestampsToReturn,
     MonitoringMode monitoringMode,
     uint clientHandle,
     MonitoringFilter originalFilter,
     MonitoringFilter filterToUse,
     Range range,
     double samplingInterval,
     uint queueSize,
     bool discardOldest,
     double minimumSamplingInterval)
 {
     return(new MonitoredItem(
                server,
                nodeManager,
                managerHandle,
                subscriptionId,
                id,
                session,
                itemToMonitor,
                diagnosticsMasks,
                timestampsToReturn,
                monitoringMode,
                clientHandle,
                originalFilter,
                filterToUse,
                range,
                samplingInterval,
                queueSize,
                discardOldest,
                minimumSamplingInterval));
 }
Exemplo n.º 12
0
        private void MonitoringModeMI_Click(object sender, EventArgs e)
        {
            try {
                MonitoringMode monitoringMode = m_monitoredItem.MonitoringMode;

                if (sender == MonitoringModeReportingMI)
                {
                    monitoringMode = MonitoringMode.Reporting;
                }
                else if (sender == MonitoringModeSamplingMI)
                {
                    monitoringMode = MonitoringMode.Sampling;
                }
                else if (sender == MonitoringModeDisabledMI)
                {
                    monitoringMode = MonitoringMode.Disabled;
                }

                m_monitoredItem.Subscription.SetMonitoringMode(monitoringMode, new MonitoredItem[] { m_monitoredItem });
            } catch (Exception exception) {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MonitoredItemBase"/> class.
        /// </summary>
        /// <param name="name">the key.</param>
        /// <param name="nodeId">the ExpandedNodeId to monitor.</param>
        /// <param name="attributeId">the attribute to monitor.</param>
        /// <param name="indexRange">the range of array indexes to monitor.</param>
        /// <param name="monitoringMode">the monitoring mode.</param>
        /// <param name="samplingInterval">the sampling interval.</param>
        /// <param name="filter">the properties that trigger a notification.</param>
        /// <param name="queueSize">the length of the queue used by the server to buffer values.</param>
        /// <param name="discardOldest">a value indicating whether to discard the oldest entries in the queue when it is full.</param>
        public MonitoredItemBase(string name, ExpandedNodeId nodeId, uint attributeId = AttributeIds.Value, string?indexRange = null, MonitoringMode monitoringMode = MonitoringMode.Reporting, int samplingInterval = -1, MonitoringFilter?filter = null, uint queueSize = 0, bool discardOldest = true)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (nodeId == null)
            {
                throw new ArgumentNullException(nameof(nodeId));
            }

            Name             = name;
            NodeId           = nodeId;
            AttributeId      = attributeId;
            IndexRange       = indexRange;
            MonitoringMode   = monitoringMode;
            SamplingInterval = samplingInterval;
            Filter           = filter;
            QueueSize        = queueSize;
            DiscardOldest    = discardOldest;
            ClientId         = (uint)Interlocked.Increment(ref lastClientId);
        }
 /// <summary>
 /// Updates the monitoring mode.
 /// </summary>
 public void SetMonitoringMode(MonitoringMode monitoringMode)
 {
     m_monitoringMode = monitoringMode;
 }
        /// <summary>
        /// Changes the monitoring mode for an item.
        /// </summary>
        protected virtual ServiceResult SetMonitoringMode(
            ISystemContext context,
            IMonitoredItem monitoredItem,
            MonitoringMode monitoringMode, 
            out bool processed)
        {
            processed = false;

            // check for valid handle.
            MonitoredNode monitoredNode = monitoredItem.ManagerHandle as MonitoredNode;

            if (monitoredNode == null)
            {
                return ServiceResult.Good;
            }

            if (IsHandleInNamespace(monitoredNode.Node) == null)
            {
                return ServiceResult.Good;
            }

            // owned by this node manager.
            processed = true;

            // check for valid monitored item.
            DataChangeMonitoredItem datachangeItem = monitoredItem as DataChangeMonitoredItem;

            // update monitoring mode.
            MonitoringMode previousMode = datachangeItem.SetMonitoringMode(monitoringMode);

            // need to provide an immediate update after enabling.
            if (previousMode == MonitoringMode.Disabled && monitoringMode != MonitoringMode.Disabled)
            {
                DataValue initialValue = new DataValue();

                initialValue.Value = null;
                initialValue.ServerTimestamp = DateTime.UtcNow;
                initialValue.SourceTimestamp = DateTime.MinValue;
                initialValue.StatusCode = StatusCodes.Good;

                ServiceResult error = monitoredNode.Node.ReadAttribute(
                    context,
                    datachangeItem.AttributeId,
                    datachangeItem.IndexRange,
                    datachangeItem.DataEncoding,
                    initialValue);

                datachangeItem.QueueValue(initialValue, error);
            }
            
            // do any post processing.
            OnSetMonitoringMode(context, monitoredNode, datachangeItem, previousMode, monitoringMode);

            return ServiceResult.Good;
        }
Exemplo n.º 16
0
        public MonitoredItem CreateMonitoredItem(string displayName, string nodeId, int samplingInterval, MonitoringFilter filterValue = null, int queueSize = 1, MonitoringMode mode = MonitoringMode.Reporting)
        {
            var monitoredItem = new MonitoredItem
            {
                DisplayName      = displayName,
                StartNodeId      = new NodeId(nodeId),
                AttributeId      = Attributes.Value,
                MonitoringMode   = mode,
                SamplingInterval = samplingInterval,
                QueueSize        = (uint)queueSize,
                CacheQueueSize   = queueSize,
                DiscardOldest    = true
            };

            if (filterValue == null)
            {
                return(monitoredItem);
            }

            monitoredItem.Filter = filterValue;
            return(monitoredItem);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Called when a monitored item monitoring mode is changed.
        /// </summary>
        protected override void OnMonitoringModeChanged(ServerSystemContext context, NodeHandle handle, MonitoredItem monitoredItem, MonitoringMode previousMode, MonitoringMode monitoringMode)
        {
            // check if monitored item requires scaning.
            if (!IsScanRequired(handle, monitoredItem))
            {
                return;
            }

            // check if starting scan.
            if (previousMode == MonitoringMode.Disabled && monitoringMode != MonitoringMode.Disabled)
            {
                StartScan(handle, monitoredItem);
            }

            // check if stopping scan.
            if (previousMode != MonitoringMode.Disabled && monitoringMode == MonitoringMode.Disabled)
            {
                StopScan(handle, monitoredItem);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates a new data change monitored item.
        /// </summary>
        public MemoryBufferMonitoredItem CreateDataChangeItem(
            ServerSystemContext context,
            MemoryTagState      tag,
            uint                subscriptionId,
            uint                monitoredItemId,
            ReadValueId         itemToMonitor,
            DiagnosticsMasks    diagnosticsMasks,
            TimestampsToReturn  timestampsToReturn,
            MonitoringMode      monitoringMode,
            uint                clientHandle,
            double              samplingInterval)

            /*
            ISystemContext context,
            MemoryTagState tag,
            uint monitoredItemId,
            uint attributeId,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval)*/
        {
            lock (m_dataLock)
            {
                MemoryBufferMonitoredItem monitoredItem = new MemoryBufferMonitoredItem(
                    m_server,
                    m_nodeManager,
                    this,
                    tag.Offset,
                    0,
                    monitoredItemId,
                    context.OperationContext.Session,
                    itemToMonitor,
                    diagnosticsMasks,
                    timestampsToReturn,
                    monitoringMode,
                    clientHandle,
                    null,
                    null,
                    null,
                    samplingInterval,
                    0,
                    false,
                    0);

                /*
                MemoryBufferMonitoredItem monitoredItem = new MemoryBufferMonitoredItem(
                    this,
                    monitoredItemId,
                    tag.Offset,
                    attributeId,
                    diagnosticsMasks,
                    timestampsToReturn,
                    monitoringMode,
                    clientHandle,
                    samplingInterval);
                */

                if (itemToMonitor.AttributeId != Attributes.Value)
                {
                    m_nonValueMonitoredItems.Add(monitoredItem.Id, monitoredItem);
                    return monitoredItem;
                }

                int elementCount = (int)(SizeInBytes.Value / ElementSize);

                if (m_monitoringTable == null)
                {
                    m_monitoringTable = new MemoryBufferMonitoredItem[elementCount][];
                    m_scanTimer = new Timer(DoScan, null, 100, 100);
                }

                int elementOffet = (int)(tag.Offset / ElementSize);

                MemoryBufferMonitoredItem[] monitoredItems = m_monitoringTable[elementOffet];

                if (monitoredItems == null)
                {
                    monitoredItems = new MemoryBufferMonitoredItem[1];
                }
                else
                {
                    monitoredItems = new MemoryBufferMonitoredItem[monitoredItems.Length + 1];
                    m_monitoringTable[elementOffet].CopyTo(monitoredItems, 0);
                }

                monitoredItems[monitoredItems.Length - 1] = monitoredItem;
                m_monitoringTable[elementOffet] = monitoredItems;
                m_itemCount++;

                return monitoredItem;
            }
        }
        public void CreateMonitoredItem(
            Session session, Subscription subscription, NodeId nodeId, MonitoringMode mode)
        {
            if (subscription == null)
            {
                subscription = session.DefaultSubscription;
                if (session.AddSubscription(subscription))
                    subscription.Create();
            }
            else
            {
                session.AddSubscription(subscription);
            }

            // add the new monitored item.
            MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);

            monitoredItem.StartNodeId = nodeId;
            monitoredItem.AttributeId = Attributes.Value;
            monitoredItem.DisplayName = nodeId.Identifier.ToString();
            monitoredItem.MonitoringMode = mode;
            monitoredItem.SamplingInterval = mode == MonitoringMode.Sampling ? 1000 : 0;
            monitoredItem.QueueSize = 0;
            monitoredItem.DiscardOldest = true;

            monitoredItem.Notification += MonitoredItem_Notification;
            subscription.AddItem(monitoredItem);
            subscription.ApplyChanges();
        }
        /// <summary>
        /// Creates a new data change monitored item.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="monitoredItemId">The unique identifier for the monitiored item.</param>
        /// <param name="attributeId">The attribute to monitor.</param>
        /// <param name="indexRange">The index range to use for array values.</param>
        /// <param name="dataEncoding">The data encoding to return for structured values.</param>
        /// <param name="diagnosticsMasks">The diagnostics masks to use.</param>
        /// <param name="timestampsToReturn">The timestamps to return.</param>
        /// <param name="monitoringMode">The initial monitoring mode.</param>
        /// <param name="clientHandle">The handle assigned by the client.</param>
        /// <param name="samplingInterval">The sampling interval.</param>
        /// <param name="queueSize">The queue size.</param>
        /// <param name="discardOldest">Whether to discard the oldest values when the queue overflows.</param>
        /// <param name="filter">The data change filter to use.</param>
        /// <param name="range">The range to use when evaluating a percentage deadband filter.</param>
        /// <param name="alwaysReportUpdates">Whether the monitored item should skip the check for a change in value.</param>
        /// <returns>The new monitored item.</returns>
        public DataChangeMonitoredItem CreateDataChangeItem(
            ISystemContext context,
            uint monitoredItemId,
            uint attributeId,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval,
            uint queueSize,
            bool discardOldest,
            DataChangeFilter filter,
            Range range,
            bool alwaysReportUpdates)
        {
            DataChangeMonitoredItem monitoredItem = new DataChangeMonitoredItem(
                this,
                monitoredItemId,
                attributeId,
                indexRange,
                dataEncoding,
                diagnosticsMasks,
                timestampsToReturn,
                monitoringMode,
                clientHandle,
                samplingInterval,
                queueSize,
                discardOldest,
                filter,
                range,
                alwaysReportUpdates);

            if (m_monitoredItems == null)
            {
                m_monitoredItems = new List<DataChangeMonitoredItem>();
                m_node.OnStateChanged = OnNodeChange;
            }

            m_monitoredItems.Add(monitoredItem);

            return monitoredItem;
        }
        /// <summary>
        /// Called after changing the MonitoringMode for a MonitoredItem.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="handle">The handle for the node.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        /// <param name="previousMode">The previous monitoring mode.</param>
        /// <param name="monitoringMode">The current monitoring mode.</param>
        protected override void OnMonitoringModeChanged(
            ServerSystemContext context,
            NodeHandle handle,
            MonitoredItem monitoredItem,
            MonitoringMode previousMode,
            MonitoringMode monitoringMode)
        {
            if (SystemScanRequired(handle.MonitoredNode, monitoredItem))
            {
                BaseVariableState source = handle.Node as BaseVariableState;

                if (previousMode != MonitoringMode.Disabled && monitoredItem.MonitoringMode == MonitoringMode.Disabled)
                {
                    m_system.StopMonitoringValue(monitoredItem.Id);
                }

                if (previousMode == MonitoringMode.Disabled && monitoredItem.MonitoringMode != MonitoringMode.Disabled)
                {
                    m_system.StartMonitoringValue(monitoredItem.Id, monitoredItem.SamplingInterval, source);
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// create and add monitored item in subscription list
        /// <summary>
        private void CreateMonitoredItem(string userInputName,
                                         Session session, Subscription subscription, ExpandedNodeId exNodeId, string displayName, MonitoringMode mode)
        {
            if (subscription == null)
            {
                subscription = session.DefaultSubscription;
                if (session.AddSubscription(subscription))
                {
                    subscription.Create();
                    subscription.PublishingEnabled = true;
                    if (m_sessionConfig != null)
                    {
                        subscription.PublishingInterval = m_sessionConfig.publishinterval;
                    }
                    else
                    {
                        subscription.PublishingInterval = 1000;
                    }
                }
            }
            else
            {
                session.AddSubscription(subscription);
            }

            // add the new monitored item.
            MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem)
            {
                StartNodeId      = (NodeId)exNodeId,
                AttributeId      = Attributes.Value,
                DisplayName      = String.Format("{0} ({1} - {2})", userInputName, displayName, exNodeId.ToString()),
                MonitoringMode   = mode,
                SamplingInterval = mode == MonitoringMode.Sampling ? 1000 : 0,
                QueueSize        = 0,
                DiscardOldest    = true
            };

            subscription.AddItem(monitoredItem);
            subscription.ApplyChanges();
        }
Exemplo n.º 23
0
 public EventQueueMonitoredItem(ISubscription target, PropertyInfo property, NodeId nodeId, uint attributeId = 12, string indexRange = null, MonitoringMode monitoringMode = MonitoringMode.Reporting, int samplingInterval = -1, MonitoringFilter filter = null, uint queueSize = 0, bool discardOldest = true)
     : base(target, property, nodeId, attributeId, indexRange, monitoringMode, samplingInterval, filter, queueSize, discardOldest)
 {
 }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MonitoredItemBase"/> class.
        /// </summary>
        /// <param name="target">the target model to store the published value.</param>
        /// <param name="property">the property of the model to store the published value.</param>
        /// <param name="nodeId">the NodeId to monitor.</param>
        /// <param name="attributeId">the attribute to monitor.</param>
        /// <param name="indexRange">the range of array indexes to monitor.</param>
        /// <param name="monitoringMode">the monitoring mode.</param>
        /// <param name="samplingInterval">the sampling interval.</param>
        /// <param name="filter">the properties that trigger a notification.</param>
        /// <param name="queueSize">the length of the queue used by the server to buffer values.</param>
        /// <param name="discardOldest">a value indicating whether to discard the oldest entries in the queue when it is full.</param>
        public MonitoredItemBase(ISubscription target, PropertyInfo property, NodeId nodeId, uint attributeId = AttributeIds.Value, string indexRange = null, MonitoringMode monitoringMode = MonitoringMode.Reporting, int samplingInterval = -1, MonitoringFilter filter = null, uint queueSize = 0, bool discardOldest = true)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (nodeId == null)
            {
                throw new ArgumentNullException(nameof(nodeId));
            }

            this.Target           = target;
            this.Property         = property;
            this.NodeId           = nodeId;
            this.AttributeId      = attributeId;
            this.IndexRange       = indexRange;
            this.MonitoringMode   = monitoringMode;
            this.SamplingInterval = samplingInterval;
            this.Filter           = filter;
            this.QueueSize        = queueSize;
            this.DiscardOldest    = discardOldest;
            this.ClientId         = (uint)Interlocked.Increment(ref lastClientId);
        }
Exemplo n.º 25
0
        public EventQueueMonitoredItem(object target, PropertyInfo property, NodeId nodeId, uint attributeId = 12, string indexRange = null, MonitoringMode monitoringMode = MonitoringMode.Reporting, int samplingInterval = -1, MonitoringFilter filter = null, uint queueSize = 0, bool discardOldest = true)
            : base(property.Name, nodeId, attributeId, indexRange, monitoringMode, samplingInterval, filter, queueSize, discardOldest)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            this.Target   = target;
            this.Property = property;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates a new data change monitored item.
        /// </summary>
        public MemoryBufferMonitoredItem CreateDataChangeItem(
            ServerSystemContext context,
            MemoryTagState tag,
            uint subscriptionId,
            uint monitoredItemId,
            ReadValueId itemToMonitor,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval)

        /*
         * ISystemContext context,
         * MemoryTagState tag,
         * uint monitoredItemId,
         * uint attributeId,
         * DiagnosticsMasks diagnosticsMasks,
         * TimestampsToReturn timestampsToReturn,
         * MonitoringMode monitoringMode,
         * uint clientHandle,
         * double samplingInterval)*/
        {
            lock (m_dataLock)
            {
                MemoryBufferMonitoredItem monitoredItem = new MemoryBufferMonitoredItem(
                    m_server,
                    m_nodeManager,
                    this,
                    tag.Offset,
                    0,
                    monitoredItemId,
                    context.OperationContext.Session,
                    itemToMonitor,
                    diagnosticsMasks,
                    timestampsToReturn,
                    monitoringMode,
                    clientHandle,
                    null,
                    null,
                    null,
                    samplingInterval,
                    0,
                    false,
                    0);

                /*
                 * MemoryBufferMonitoredItem monitoredItem = new MemoryBufferMonitoredItem(
                 *  this,
                 *  monitoredItemId,
                 *  tag.Offset,
                 *  attributeId,
                 *  diagnosticsMasks,
                 *  timestampsToReturn,
                 *  monitoringMode,
                 *  clientHandle,
                 *  samplingInterval);
                 */

                if (itemToMonitor.AttributeId != Attributes.Value)
                {
                    m_nonValueMonitoredItems.Add(monitoredItem.Id, monitoredItem);
                    return(monitoredItem);
                }

                int elementCount = (int)(SizeInBytes.Value / ElementSize);

                if (m_monitoringTable == null)
                {
                    m_monitoringTable = new MemoryBufferMonitoredItem[elementCount][];
                    m_scanTimer       = new Timer(DoScan, null, 100, 100);
                }

                int elementOffet = (int)(tag.Offset / ElementSize);

                MemoryBufferMonitoredItem[] monitoredItems = m_monitoringTable[elementOffet];

                if (monitoredItems == null)
                {
                    monitoredItems = new MemoryBufferMonitoredItem[1];
                }
                else
                {
                    monitoredItems = new MemoryBufferMonitoredItem[monitoredItems.Length + 1];
                    m_monitoringTable[elementOffet].CopyTo(monitoredItems, 0);
                }

                monitoredItems[monitoredItems.Length - 1] = monitoredItem;
                m_monitoringTable[elementOffet]           = monitoredItems;
                m_itemCount++;

                return(monitoredItem);
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Removes an item from the sampling interval.
 /// </summary>
 private void RemoveItemToSamplingInterval(
     double samplingInterval,
     MonitoringMode monitoringMode)
 {
     // TBD
 }
Exemplo n.º 28
0
 public DataValueQueueMonitoredItem(PropertyInfo property, NodeId nodeId, uint attributeId = 13, string indexRange = null, MonitoringMode monitoringMode = MonitoringMode.Reporting, int samplingInterval = -1, MonitoringFilter filter = null, uint queueSize = 0, bool discardOldest = true)
     : base(property, nodeId, attributeId, indexRange, monitoringMode, samplingInterval, filter, queueSize, discardOldest)
 {
 }
Exemplo n.º 29
0
        /// <summary>
        /// Reports a modified monitored item.
        /// </summary>
        public static void ReportModifyMonitoredItem(
            NodeId nodeId,
            uint serverHandle,
            double samplingInterval,
            uint queueSize,
            bool discardOldest,
            MonitoringFilter filter,
            MonitoringMode monitoringMode)
        {
            if (!m_eventsEnabled)
            {
                return;
            }

            lock (m_events)
            {
                Event e = new Event();
                e.EventType = EventType.ModifyItem;
                e.NodeId = nodeId;
                e.ServerHandle = serverHandle;
                e.Timestamp = HiResClock.UtcNow;
                e.Value = null;
                e.Parameters = new MonitoringParameters();
                e.Parameters.SamplingInterval = samplingInterval;
                e.Parameters.QueueSize = queueSize;
                e.Parameters.DiscardOldest = discardOldest;
                e.Parameters.Filter = new ExtensionObject(filter);
                e.MonitoringMode = monitoringMode;
                m_events.Enqueue(e);
            }
        }
 /// <summary>
 /// Creates a new data change monitored item.
 /// </summary>
 /// <param name="context">The system context.</param>
 /// <param name="monitoredItemId">The unique identifier for the monitiored item.</param>
 /// <param name="attributeId">The attribute to monitor.</param>
 /// <param name="indexRange">The index range to use for array values.</param>
 /// <param name="dataEncoding">The data encoding to return for structured values.</param>
 /// <param name="diagnosticsMasks">The diagnostics masks to use.</param>
 /// <param name="timestampsToReturn">The timestamps to return.</param>
 /// <param name="monitoringMode">The initial monitoring mode.</param>
 /// <param name="clientHandle">The handle assigned by the client.</param>
 /// <param name="samplingInterval">The sampling interval.</param>
 /// <param name="alwaysReportUpdates">Whether the monitored item should skip the check for a change in value.</param>
 /// <returns>The new monitored item.</returns>
 public DataChangeMonitoredItem CreateDataChangeItem(
     ISystemContext context,
     uint monitoredItemId,
     uint attributeId,
     NumericRange indexRange,
     QualifiedName dataEncoding,
     DiagnosticsMasks diagnosticsMasks,
     TimestampsToReturn timestampsToReturn,
     MonitoringMode monitoringMode,
     uint clientHandle,
     double samplingInterval,
     bool alwaysReportUpdates)
 {
     return CreateDataChangeItem(
         context,
         monitoredItemId,
         attributeId,
         indexRange,
         dataEncoding,
         diagnosticsMasks,
         timestampsToReturn,
         monitoringMode,
         clientHandle,
         samplingInterval,
         0,
         false,
         null,
         null,
         alwaysReportUpdates);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Creates a new data change monitored item.
        /// </summary>
        public MemoryBufferMonitoredItem CreateDataChangeItem(
            ServerSystemContext context,
            MemoryTagState tag,
            uint monitoredItemId,
            ReadValueId itemToMonitor,
            DiagnosticsMasks diagnosticsMasks,
            TimestampsToReturn timestampsToReturn,
            MonitoringMode monitoringMode,
            uint clientHandle,
            double samplingInterval)
        {
            lock (_dataLock) {
                var monitoredItem = new MemoryBufferMonitoredItem(
                    Server,
                    NodeManager,
                    this,
                    tag.Offset,
                    0,
                    monitoredItemId,
                    context.OperationContext.Session,
                    itemToMonitor,
                    diagnosticsMasks,
                    timestampsToReturn,
                    monitoringMode,
                    clientHandle,
                    null,
                    null,
                    null,
                    samplingInterval,
                    0,
                    false,
                    0);

                if (itemToMonitor.AttributeId != Attributes.Value)
                {
                    _nonValueMonitoredItems.Add(monitoredItem.Id, monitoredItem);
                    return(monitoredItem);
                }

                var elementCount = (int)(SizeInBytes.Value / ElementSize);

                if (_monitoringTable == null)
                {
                    _monitoringTable = new MemoryBufferMonitoredItem[elementCount][];
                    _scanTimer       = new Timer(DoScan, null, 100, 100);
                }

                var elementOffet = (int)(tag.Offset / ElementSize);

                var monitoredItems = _monitoringTable[elementOffet];

                if (monitoredItems == null)
                {
                    monitoredItems = new MemoryBufferMonitoredItem[1];
                }
                else
                {
                    monitoredItems = new MemoryBufferMonitoredItem[monitoredItems.Length + 1];
                    _monitoringTable[elementOffet].CopyTo(monitoredItems, 0);
                }

                monitoredItems[monitoredItems.Length - 1] = monitoredItem;
                _monitoringTable[elementOffet]            = monitoredItems;
                _itemCount++;

                return(monitoredItem);
            }
        }
        /// <summary>
        /// Invokes the SetMonitoringMode service.
        /// </summary>
        /// <param name="requestHeader">The request header.</param>
        /// <param name="subscriptionId">The subscription id.</param>
        /// <param name="monitoringMode">The monitoring mode to be set for the MonitoredItems.</param>
        /// <param name="monitoredItemIds">The list of MonitoredItems to modify.</param>
        /// <param name="results">The list of results for the MonitoredItems to modify.</param>
        /// <param name="diagnosticInfos">The diagnostic information for the results.</param>
        /// <returns>
        /// Returns a <see cref="ResponseHeader"/> object
        /// </returns>
        public override ResponseHeader SetMonitoringMode(
            RequestHeader                requestHeader,
            uint                         subscriptionId, 
            MonitoringMode               monitoringMode,
            UInt32Collection             monitoredItemIds,
            out StatusCodeCollection     results, 
            out DiagnosticInfoCollection diagnosticInfos)
        {
            OperationContext context = ValidateRequest(requestHeader, RequestType.SetMonitoringMode);
                
            try
            {
                if (monitoredItemIds == null || monitoredItemIds.Count == 0)
                {
                    throw new ServiceResultException(StatusCodes.BadNothingToDo);
                }         

                ServerInternal.SubscriptionManager.SetMonitoringMode(
                    context,
                    subscriptionId,
                    monitoringMode,
                    monitoredItemIds,
                    out results,
                    out diagnosticInfos);

                return CreateResponse(requestHeader, context.StringTable);
            }
            catch (ServiceResultException e)
            {
                lock (ServerInternal.DiagnosticsLock)
                {
                    ServerInternal.ServerDiagnostics.RejectedRequestsCount++;

                    if (IsSecurityError(e.StatusCode))
                    {
                        ServerInternal.ServerDiagnostics.SecurityRejectedRequestsCount++;
                    }
                }

                throw TranslateException(context, e);
            }  
            finally
            {
                OnRequestComplete(context);
            }
        }
Exemplo n.º 33
0
		/// <summary>
		/// Deletes the monitored items in a subscription.
		/// </summary>
		private void DeleteMonitoredItems(
			OperationContext             context,
            UInt32Collection             monitoredItemIds,
            bool                         doNotCheckSession,
            out StatusCodeCollection     results,
            out DiagnosticInfoCollection diagnosticInfos)
        {
            if (context == null)          throw new ArgumentNullException("context");
            if (monitoredItemIds == null) throw new ArgumentNullException("monitoredItemIds");

            int count = monitoredItemIds.Count;

            bool diagnosticsExist = false;
            results = new StatusCodeCollection(count);
            diagnosticInfos = null;

            if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
            {
                diagnosticInfos = new DiagnosticInfoCollection(count);
            }
            
            // build list of items to modify.
            List<IMonitoredItem> monitoredItems = new List<IMonitoredItem>(count);
            List<ServiceResult> errors = new List<ServiceResult>(count);
            double[] originalSamplingIntervals = new double[count];
            MonitoringMode[] originalMonitoringModes = new MonitoringMode[count];

            bool validItems = false;

            lock (m_lock)
            {
                // check session.
                if (!doNotCheckSession)
                {
                    VerifySession(context);
                }

                // clear lifetime counter.
                ResetLifetimeCount();
                
                for (int ii = 0; ii < count; ii++)
                {
                    LinkedListNode<IMonitoredItem> node = null;

                    if (!m_monitoredItems.TryGetValue(monitoredItemIds[ii], out node))
                    {
                        monitoredItems.Add(null);
                        errors.Add(StatusCodes.BadMonitoredItemIdInvalid);

                        // update diagnostics.
                        if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                        {
                            DiagnosticInfo diagnosticInfo = ServerUtils.CreateDiagnosticInfo(m_server, context, errors[ii]);
                            diagnosticsExist = true;
                            diagnosticInfos.Add(diagnosticInfo);
                        }

                        continue;
                    }
                    
                    IMonitoredItem monitoredItem = node.Value;
                    monitoredItems.Add(monitoredItem);

                    // remove the item from the internal lists.
                    m_monitoredItems.Remove(monitoredItemIds[ii]);
                    m_itemsToTrigger.Remove(monitoredItemIds[ii]);

                    //remove the links towards the deleted monitored item
                    List<ITriggeredMonitoredItem> triggeredItems = null;
                    foreach (KeyValuePair<uint, List<ITriggeredMonitoredItem>> item in m_itemsToTrigger)
                    {
                        triggeredItems = item.Value;
                        for (int jj = 0; jj < triggeredItems.Count; jj++)
                        {
                            if (triggeredItems[jj].Id == monitoredItemIds[ii])
                            {
                                triggeredItems.RemoveAt(jj);
                                break;
                            }
                        }
                    }
                    
                    if (node.List != null)
                    {
                        node.List.Remove(node);
                    }

                    originalSamplingIntervals[ii] = monitoredItem.SamplingInterval;
                    originalMonitoringModes[ii] = monitoredItem.MonitoringMode;

                    errors.Add(null);
                    validItems = true;

                    // update diagnostics.
                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        diagnosticInfos.Add(null);
                    }
                }
            }
   
            // update items.
            if (validItems)
            {
                m_server.NodeManager.DeleteMonitoredItems(
                    context,
                    m_id,
                    monitoredItems,
                    errors);
            }
            
            lock (m_lock)
            {
                // update diagnostics.
                for (int ii = 0; ii < errors.Count; ii++)
                {
                    ServiceResult error = errors[ii];

                    if (error == null)
                    {
                        results.Add(StatusCodes.Good);
                    }
                    else
                    {
                        results.Add(error.StatusCode);
                    }

                    // update diagnostics.
                    if (ServiceResult.IsGood(error))
                    {
                        RemoveItemToSamplingInterval(originalSamplingIntervals[ii], originalMonitoringModes[ii]);
                    }

                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        if (error != null && error.Code != StatusCodes.Good)
                        {
                            diagnosticInfos[ii] = ServerUtils.CreateDiagnosticInfo(m_server, context, error);
                            diagnosticsExist = true;
                        }
                    }
                }

                // clear diagnostics if not required.
                if (!diagnosticsExist && diagnosticInfos != null)
                {
                    diagnosticInfos.Clear();
                }

                // update diagnostics.
                lock (m_diagnostics)
                {
                    m_diagnostics.MonitoredItemCount = 0;
                    m_diagnostics.DisabledMonitoredItemCount = 0;
                }

                // TraceState("ITEMS DELETED");
            }
        }
Exemplo n.º 34
0
 /// <summary>
 /// Does any processing after a monitored item is created.
 /// </summary>
 protected override void OnSetMonitoringMode(
     ISystemContext systemContext,
     MonitoredNode monitoredNode,
     DataChangeMonitoredItem monitoredItem,
     MonitoringMode previousMode,
     MonitoringMode currentMode)
 {
     // nothing to do.
 }
		/// <summary>
		/// Initializes the object with its node type.
		/// </summary>
        public MonitoredItem(
            IServerInternal     server,
            INodeManager        nodeManager,
            object              mangerHandle,
            uint                subscriptionId,
            uint                id,
            Session             session,
            ReadValueId         itemToMonitor,
            DiagnosticsMasks    diagnosticsMasks,
            TimestampsToReturn  timestampsToReturn,
            MonitoringMode      monitoringMode,
            uint                clientHandle,
            MonitoringFilter    originalFilter,
            MonitoringFilter    filterToUse,
            Range               range,
            double              samplingInterval,
            uint                queueSize,
            bool                discardOldest,
            double              sourceSamplingInterval)
		{
            if (itemToMonitor == null) throw new ArgumentNullException("itemToMonitor");
            
			Initialize();
            
            m_server                  = server;
            m_nodeManager             = nodeManager;
            m_managerHandle           = mangerHandle;
            m_subscriptionId          = subscriptionId;
            m_id                      = id;
            m_session                 = session;
            m_nodeId                  = itemToMonitor.NodeId;
            m_attributeId             = itemToMonitor.AttributeId;
            m_indexRange              = itemToMonitor.IndexRange;
            m_parsedIndexRange        = itemToMonitor.ParsedIndexRange;
            m_encoding                = itemToMonitor.DataEncoding;
            m_diagnosticsMasks        = diagnosticsMasks;
            m_timestampsToReturn      = timestampsToReturn;
            m_monitoringMode          = monitoringMode;
            m_clientHandle            = clientHandle;
            m_originalFilter          = originalFilter;
            m_filterToUse             = filterToUse;
            m_range                   = 0;
            m_samplingInterval        = samplingInterval;
            m_queueSize               = queueSize;
            m_discardOldest           = discardOldest;
            m_sourceSamplingInterval  = (int)sourceSamplingInterval;
            m_calculator              = null;
            m_nextSamplingTime        = DateTime.UtcNow.Ticks;
            m_alwaysReportUpdates     = false;
            
            m_typeMask = MonitoredItemTypeMask.DataChange;

            if (originalFilter is EventFilter)
            {
                m_typeMask = MonitoredItemTypeMask.Events;

                if (itemToMonitor.NodeId == Objects.Server)
                {
                    m_typeMask |= MonitoredItemTypeMask.AllEvents;
                }
            }

            // create aggregate calculator.
            ServerAggregateFilter aggregateFilter = filterToUse as ServerAggregateFilter;

            if (filterToUse is ServerAggregateFilter)
            {
                m_calculator = m_server.AggregateManager.CreateCalculator(
                    aggregateFilter.AggregateType,
                    aggregateFilter.StartTime,
                    DateTime.MaxValue,
                    aggregateFilter.ProcessingInterval,
                    aggregateFilter.Stepped,
                    aggregateFilter.AggregateConfiguration);
            }

            if (range != null)
            {
                m_range = range.High - range.Low;
            }

            // report change to item state.
            ServerUtils.ReportCreateMonitoredItem(
                m_nodeId,
                m_id,
                m_samplingInterval,
                m_queueSize,
                m_discardOldest,
                m_filterToUse,
                m_monitoringMode);

            InitializeQueue();
		}
Exemplo n.º 36
0
        /// <summary>
        /// Invokes the SetMonitoringMode service.
        /// </summary>
        public virtual ResponseHeader SetMonitoringMode(
            RequestHeader                requestHeader,
            uint                         subscriptionId,
            MonitoringMode               monitoringMode,
            UInt32Collection             monitoredItemIds,
            out StatusCodeCollection     results,
            out DiagnosticInfoCollection diagnosticInfos)
        {
            results = null;
            diagnosticInfos = null;

            ValidateRequest(requestHeader);

            // Insert implementation.

            return CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported);
        }
		/// <summary>
		/// Changes the monitoring mode for the item.
		/// </summary>
        void IEventMonitoredItem.SetMonitoringMode(MonitoringMode monitoringMode)
        {
            SetMonitoringMode(monitoringMode);            
        }
        /// <summary>
        /// Changes the monitoring mode for a set of monitored items.
        /// </summary>
        public virtual void SetMonitoringMode(
            OperationContext     context, 
            MonitoringMode       monitoringMode, 
            IList<IMonitoredItem> monitoredItems, 
            IList<bool>          processedItems, 
            IList<ServiceResult> errors)
        {
            ServerSystemContext systemContext = m_systemContext.Copy(context);

            lock (Lock)
            {
                for (int ii = 0; ii < monitoredItems.Count; ii++)
                {
                    // skip items that have already been processed.
                    if (processedItems[ii])
                    {
                        continue;
                    }

                    // update monitoring mode.
                    bool processed = false;

                    errors[ii] = SetMonitoringMode(
                        systemContext,
                        monitoredItems[ii],
                        monitoringMode,
                        out processed);

                    // indicate whether it was processed or not.
                    processedItems[ii] = processed;
                }
            }
        }
Exemplo n.º 39
0
        /// <summary>
        /// Called after changing the MonitoringMode for a MonitoredItem.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="handle">The handle for the node.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        /// <param name="previousMode">The previous monitoring mode.</param>
        /// <param name="monitoringMode">The current monitoring mode.</param>
        protected override void OnMonitoringModeChanged(
            ServerSystemContext context,
            NodeHandle handle,
            MonitoredItem monitoredItem,
            MonitoringMode previousMode,
            MonitoringMode monitoringMode)
        {
            if (previousMode != MonitoringMode.Disabled)
            {
                m_diagnosticsMonitoringCount--;
            }

            if (monitoringMode != MonitoringMode.Disabled)
            {
                m_diagnosticsMonitoringCount++;
            }
                
            if (m_diagnosticsMonitoringCount == 0 && m_diagnosticsScanTimer != null)
            {
                if (m_diagnosticsScanTimer != null)
                {
                    m_diagnosticsScanTimer.Dispose();
                    m_diagnosticsScanTimer = null;
                }
            }
            else
            {
                if (m_diagnosticsScanTimer != null)
                {
                    m_diagnosticsScanTimer = new Timer(DoScan, null, 1000, 1000);
                }
            }
        }
 /// <summary>
 /// Does any processing after a monitored item is created.
 /// </summary>
 protected virtual void OnSetMonitoringMode(
     ISystemContext systemContext,
     MonitoredNode monitoredNode,
     DataChangeMonitoredItem monitoredItem,
     MonitoringMode previousMode,
     MonitoringMode currentMode)
 {
     // does nothing.
 }
Exemplo n.º 41
0
        /// <summary>
        /// Changes the monitoring mode for the currently selected monitored items.
        /// </summary>
        private void Monitoring_MonitoringMode_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 monitoring mode being requested.
                MonitoringMode monitoringMode = MonitoringMode.Disabled;

                if (sender == Monitoring_MonitoringMode_ReportingMI)
                {
                    monitoringMode = MonitoringMode.Reporting;
                }

                if (sender == Monitoring_MonitoringMode_SamplingMI)
                {
                    monitoringMode = MonitoringMode.Sampling;
                }

                // 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)
                    {
                        itemsToChange.Add(monitoredItem);
                    }
                }

                // apply the changes to the server.
                m_subscription.SetMonitoringMode(monitoringMode, itemsToChange);

                // 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))
                        {
                            item.SubItems[8].Text = itemsToChange[ii].Status.Error.StatusCode.ToString();
                        }

                        item.SubItems[2].Text = itemsToChange[ii].Status.MonitoringMode.ToString();
                    }
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Exemplo n.º 42
0
 /// <summary>
 /// Adds an item to the sampling interval.
 /// </summary>
 private void ModifyItemSamplingInterval(
     double oldInterval,
     double newInterval,
     MonitoringMode monitoringMode)
 {
     // TBD
 }
Exemplo n.º 43
0
        /// <summary>
        /// Prompts the user to specify a monitoring mode.
        /// </summary>
        public MonitoringMode ShowDialog(MonitoringMode monitoringMode)
        {
            NodeLB.Visible = false;
            NodeTB.Visible = false;
            NodeBTN.Visible = false;
            AttributeLB.Visible = false;
            AttributeCB.Visible = false;
            IndexRangeLB.Visible = false;
            IndexRangeTB.Visible = false;
            DataEncodingLB.Visible = false;
            DataEncodingCB.Visible = false;
            MonitoringModeLB.Visible = true;
            MonitoringModeCB.Visible = true;
            SamplingIntervalLB.Visible = false;
            SamplingIntervalUP.Visible = false;
            QueueSizeLB.Visible = false;
            QueueSizeUP.Visible = false;
            DiscardOldestLB.Visible = false;
            DiscardOldestCK.Visible = false;
            DeadbandTypeLB.Visible = false;
            DeadbandTypeCB.Visible = false;
            DeadbandValueLB.Visible = false;
            DeadbandValueUP.Visible = false;
            TriggerTypeLB.Visible = false;
            TriggerTypeCB.Visible = false;

            MonitoringModeCB.SelectedItem = monitoringMode;

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

            return (MonitoringMode)MonitoringModeCB.SelectedItem;
        }
Exemplo n.º 44
0
 /// <summary>
 /// Changes the monitoring mode for an item.
 /// </summary>
 private void ModifyItemMonitoringMode(
     double samplingInterval,
     MonitoringMode oldMode,
     MonitoringMode newMode)
 {
     // TBD
 }
Exemplo n.º 45
0
        private bool CreateSubscr()
        {
            try
            {
                foreach (Config.DataGroup dataGroup in config.DataGroups)
                {
                    if (dataGroup.Active && dataGroup.DataItems.Count > 0)
                    {
                        if (Localization.UseRussian)
                        {
                            WriteToLog("Создание подписки на чтение данных" +
                                       (string.IsNullOrEmpty(dataGroup.Name) ? "" : ". Наименование: " + dataGroup.Name));
                        }
                        else
                        {
                            WriteToLog("Create data reading subscription" +
                                       (string.IsNullOrEmpty(dataGroup.Name) ? "" : ". Name: " + dataGroup.Name));
                        }

                        foreach (Config.DataItem dataItem in dataGroup.DataItems)
                        {
                            if (dataItem.Active)
                            {
                                MonitoringMode mm = new MonitoringMode();
                                if (dataItem.Mode == "Reporting")
                                {
                                    mm = MonitoringMode.Reporting;
                                }
                                else if (dataItem.Mode == "Sampling")
                                {
                                    mm = MonitoringMode.Sampling;
                                }
                                else if (dataItem.Mode == "Disabled")
                                {
                                    mm = MonitoringMode.Disabled;
                                }

                                KPTag tag;
                                if (kpTagsByName.TryGetValue(dataItem.Name, out tag))
                                {
                                    ItemsOPCUA.Add(new ItemOPCUA(null, dataItem.Id, mm, dataItem.Signal, tag.Signal - 1));
                                }
                                else
                                {
                                    WriteToLog("Error to assign signal to the name: " + dataItem.Name);
                                }
                            }
                        }
                    }
                }

                ReferenceDescriptionCollection references;
                references = m_session.FetchReferences(ObjectIds.ObjectsFolder);
                // parcourir
                BrowseNodesId(ObjectIds.ObjectsFolder, ItemsOPCUA);

                if (m_subscription != null)
                {
                    m_subscription.ApplyChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                WriteToLog((Localization.UseRussian ?
                            "Ошибка при создании подписки на чтение данных: " :
                            "Error creating data reading subscription: ") + ex.Message);
                return(false);
            }
        }
Exemplo n.º 46
0
		/// <summary>
		/// Changes the monitoring mode for a set of items.
		/// </summary>
        public void SetMonitoringMode(
            OperationContext             context,
            MonitoringMode               monitoringMode,
            UInt32Collection             monitoredItemIds,
            out StatusCodeCollection     results, 
            out DiagnosticInfoCollection diagnosticInfos)
        {  
            if (context == null)          throw new ArgumentNullException("context");
            if (monitoredItemIds == null) throw new ArgumentNullException("monitoredItemIds");

            int count = monitoredItemIds.Count;

            bool diagnosticsExist = false;
            results = new StatusCodeCollection(count);
            diagnosticInfos = null;

            if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
            {
                diagnosticInfos = new DiagnosticInfoCollection(count);
            }
        
            // build list of items to modify.
            List<IMonitoredItem> monitoredItems = new List<IMonitoredItem>(count);
            List<ServiceResult> errors = new List<ServiceResult>(count);
            MonitoringMode[] originalMonitoringModes = new MonitoringMode[count];

            bool validItems = false;

            lock (m_lock)
            {
                // check session.
                VerifySession(context);

                // clear lifetime counter.
                ResetLifetimeCount();

                for (int ii = 0; ii < count; ii++)
                {
                    LinkedListNode<IMonitoredItem> node = null;

                    if (!m_monitoredItems.TryGetValue(monitoredItemIds[ii], out node))
                    {
                        monitoredItems.Add(null);
                        errors.Add(StatusCodes.BadMonitoredItemIdInvalid);

                        // update diagnostics.
                        if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                        {
                            DiagnosticInfo diagnosticInfo = ServerUtils.CreateDiagnosticInfo(m_server, context, errors[ii]);
                            diagnosticsExist = true;
                            diagnosticInfos.Add(diagnosticInfo);
                        }

                        continue;
                    }
                    
                    IMonitoredItem monitoredItem = node.Value;
                    monitoredItems.Add(monitoredItem);
                    originalMonitoringModes[ii] = monitoredItem.MonitoringMode;

                    errors.Add(null);
                    validItems = true;

                    // update diagnostics.
                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        diagnosticInfos.Add(null);
                    }
                }
            }

            // update items.
            if (validItems)
            {
                m_server.NodeManager.SetMonitoringMode(
                    context,
                    monitoringMode,
                    monitoredItems,
                    errors);
            }
                
            lock (m_lock)
            {
                // update diagnostics.
                for (int ii = 0; ii < errors.Count; ii++)
                {
                    ServiceResult error = errors[ii];

                    if (error == null)
                    {
                        results.Add(StatusCodes.Good);
                    }
                    else
                    {
                        results.Add(error.StatusCode);
                    }
                    
                    // update diagnostics.
                    if (ServiceResult.IsGood(error))
                    {
                        ModifyItemMonitoringMode(monitoredItems[ii].SamplingInterval, originalMonitoringModes[ii], monitoringMode);
                    }

                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        if (error != null && error.Code != StatusCodes.Good)
                        {
                            diagnosticInfos[ii] = ServerUtils.CreateDiagnosticInfo(m_server, context, error);
                            diagnosticsExist = true;
                        }
                    }
                }

                // clear diagnostics if not required.
                if (!diagnosticsExist && diagnosticInfos != null)
                {
                    diagnosticInfos.Clear();
                }

                // update diagnostics.
                lock (m_diagnostics)
                {
                    m_diagnostics.MonitoredItemCount = 0;
                    m_diagnostics.DisabledMonitoredItemCount = 0;
                }

                if (monitoringMode == MonitoringMode.Disabled)
                {
                    // TraceState("ITEMS DISABLED");
                }
                else if (monitoringMode == MonitoringMode.Reporting)
                {
                    // TraceState("ITEMS REPORTING ENABLED");
                }
                else
                {
                    // TraceState("ITEMS SAMPLING ENABLED");
                }
            }
        }
Exemplo n.º 47
0
        /// <summary>
        /// Changes the monitoring mode for a set of monitored items.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="monitoringMode">The monitoring mode.</param>
        /// <param name="monitoredItems">The set of monitoring items to update.</param>
        /// <param name="processedItems">Flags indicating which items have been processed.</param>
        /// <param name="errors">Any errors.</param>
        public virtual void SetMonitoringMode(
            OperationContext      context, 
            MonitoringMode        monitoringMode, 
            IList<IMonitoredItem> monitoredItems, 
            IList<bool>           processedItems, 
            IList<ServiceResult>  errors)
        {
            ServerSystemContext systemContext = m_systemContext.Copy(context);
            List<IMonitoredItem> changedItems = new List<IMonitoredItem>();

            lock (Lock)
            {
                for (int ii = 0; ii < monitoredItems.Count; ii++)
                {
                    // skip items that have already been processed.
                    if (processedItems[ii] || monitoredItems[ii] == null)
                    {
                        continue;
                    }

                    // check handle.
                    NodeHandle handle = IsHandleInNamespace(monitoredItems[ii].ManagerHandle);

                    if (handle == null)
                    {
                        continue;
                    }

                    // indicate whether it was processed or not.
                    processedItems[ii] = true;

                    // update monitoring mode.
                    errors[ii] = SetMonitoringMode(
                        systemContext,
                        monitoredItems[ii],
                        monitoringMode,
                        handle);

                    // save the modified item.
                    if (ServiceResult.IsGood(errors[ii]))
                    {
                        changedItems.Add(monitoredItems[ii]);
                    }
                }
            }

            // do any post processing.
            OnSetMonitoringModeComplete(systemContext, changedItems);
        }
		/// <summary>
		/// Changes the monitoring mode for the item.
		/// </summary>
        void ISampledDataChangeMonitoredItem.SetMonitoringMode(MonitoringMode monitoringMode)
        {
            SetMonitoringMode(monitoringMode);            
        }
Exemplo n.º 49
0
        /// <summary>
        /// Changes the monitoring mode for an item.
        /// </summary>
        protected virtual ServiceResult SetMonitoringMode(
            ServerSystemContext context,
            IMonitoredItem monitoredItem,
            MonitoringMode monitoringMode,
            NodeHandle handle)
        {
            // check for valid monitored item.
            MonitoredItem datachangeItem = monitoredItem as MonitoredItem;

            // update monitoring mode.
            MonitoringMode previousMode = datachangeItem.SetMonitoringMode(monitoringMode);

            // must send the latest value after enabling a disabled item.
            if (monitoringMode == MonitoringMode.Reporting && previousMode == MonitoringMode.Disabled)
            {
                handle.MonitoredNode.QueueValue(context, handle.Node, datachangeItem);
            }

            // report change.
            if (previousMode != monitoringMode)
            {
                OnMonitoringModeChanged(
                    context,
                    handle,
                    datachangeItem,
                    previousMode,
                    monitoringMode);
            }
            
            return ServiceResult.Good;
        }
		/// <summary>
		/// Changes the monitoring mode for the item.
		/// </summary>
        public MonitoringMode SetMonitoringMode(MonitoringMode monitoringMode)
        {
            lock (m_lock)
			{
                MonitoringMode previousMode = m_monitoringMode;

                if (previousMode == monitoringMode)
                {
                    return previousMode;
                }

                Utils.Trace("MONITORING MODE[{0}] {1} -> {2}", m_id, m_monitoringMode, monitoringMode);

                if (previousMode == MonitoringMode.Disabled)
                {
                    m_nextSamplingTime = DateTime.UtcNow.Ticks;
                    m_lastError = null;
                    m_lastValue = null;
                }

                m_monitoringMode = monitoringMode;
                
                if (monitoringMode == MonitoringMode.Disabled)
                {
                    m_readyToPublish = false;
                    m_readyToTrigger = false;
                    m_triggered = false;
                }

                // report change to item state.
                ServerUtils.ReportModifyMonitoredItem(
                    m_nodeId,
                    m_id,
                    m_samplingInterval,
                    m_queueSize,
                    m_discardOldest,
                    m_filterToUse,
                    m_monitoringMode);
                    
                InitializeQueue();

                return previousMode;
            }
        }
Exemplo n.º 51
0
 /// <summary>
 /// Called after changing the MonitoringMode for a MonitoredItem.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="handle">The handle for the node.</param>
 /// <param name="monitoredItem">The monitored item.</param>
 /// <param name="previousMode">The previous monitoring mode.</param>
 /// <param name="monitoringMode">The current monitoring mode.</param>
 protected virtual void OnMonitoringModeChanged(
     ServerSystemContext context,
     NodeHandle handle,
     MonitoredItem monitoredItem,
     MonitoringMode previousMode,
     MonitoringMode monitoringMode)
 {
     // overridden by the sub-class.
 }