/// <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, Opc.Ua.Range range, bool alwaysReportUpdates) { _source = source; Id = id; AttributeId = attributeId; IndexRange = indexRange; DataEncoding = dataEncoding; _timestampsToReturn = timestampsToReturn; _diagnosticsMasks = diagnosticsMasks; MonitoringMode = monitoringMode; ClientHandle = clientHandle; _samplingInterval = samplingInterval; _nextSampleTime = DateTime.UtcNow.Ticks; _readyToPublish = false; _readyToTrigger = false; _queue = null; DataChangeFilter = filter; _range = 0; AlwaysReportUpdates = alwaysReportUpdates; if (range != null) { _range = range.High - range.Low; } if (queueSize > 1) { _queue = new MonitoredItemQueue(); _queue.SetQueueSize(queueSize, discardOldest, diagnosticsMasks); _queue.SetSamplingInterval(samplingInterval); } }
/// <summary> /// Modifies the monitored item parameters, /// </summary> public ServiceResult Modify( DiagnosticsMasks diagnosticsMasks, TimestampsToReturn timestampsToReturn, uint clientHandle, double samplingInterval, uint queueSize, bool discardOldest, DataChangeFilter filter, Opc.Ua.Range range) { lock (_lock) { _diagnosticsMasks = diagnosticsMasks; _timestampsToReturn = timestampsToReturn; ClientHandle = clientHandle; // subtract the previous sampling interval. var oldSamplingInterval = (long)(_samplingInterval * TimeSpan.TicksPerMillisecond); if (oldSamplingInterval < _nextSampleTime) { _nextSampleTime -= oldSamplingInterval; } _samplingInterval = samplingInterval; // calculate the next sampling interval. var newSamplingInterval = (long)(_samplingInterval * TimeSpan.TicksPerMillisecond); if (_samplingInterval > 0) { _nextSampleTime += newSamplingInterval; } else { _nextSampleTime = 0; } // update the filter and the range. DataChangeFilter = filter; _range = 0; if (range != null) { _range = range.High - range.Low; } // update the queue size. if (queueSize > 1) { if (_queue == null) { _queue = new MonitoredItemQueue(); } _queue.SetQueueSize(queueSize, discardOldest, diagnosticsMasks); _queue.SetSamplingInterval(samplingInterval); } else { _queue = null; } return(ServiceResult.Good); } }