public IList <MetricValue> Read() { if (l_metricCollection.Count <= 0) { return(null); } List <MetricValue> metricList = new List <MetricValue>(); while (l_metricCollection.Count > 0) { OpcMetric data = null; try { data = l_metricCollection.Take(); } catch (InvalidOperationException) { } if (data != null) { MetricValue metricValue = new MetricValue() { TypeName = "gauge", TypeInstanceName = "gauge", //Interval = data.Measurement.mo HostName = "localhost", PluginInstanceName = "OpcUaPluginInstance", PluginName = "OpcUaPlugin", Extension = data.JsonString() }; metricList.Add(metricValue); } } l_logger.DebugFormat("Read {0} items.", metricList.Count); return(metricList); }
void ReadMeasurement(PolledMeasurement measurement) { OpcMetric metric = new OpcMetric(); metric.Measurement = (MeasurementDto)measurement; if (!l_session.Connected) { l_logger.ErrorFormat(string.Format("Server not connected. Cannot read path {0}.", measurement.Name)); throw new Exception(string.Format("Server not connected. Cannot read path {0}.", measurement.Name)); } var nodesToRead = OpcUaHelper.GetReadValueIdCollection(measurement.Path, l_session); DataValueCollection results; DiagnosticInfoCollection diag; l_session.Read( requestHeader: null, maxAge: 0, timestampsToReturn: TimestampsToReturn.Neither, nodesToRead: nodesToRead, results: out results, diagnosticInfos: out diag); var val = results[0]; metric.OpcValue = val.Value; metric.Opcstatus = val.StatusCode.ToString(); if (OpcHelper.QualifyMetric(ref metric, l_cache)) { l_cache[metric.Measurement.Name] = metric.OpcValue; l_metricCollection.Add(metric); } }
void MonitorData(MonitoredMeasurement measurement, DataValue NewValue) { OpcMetric metric = new OpcMetric(); metric.Timestamp = NewValue.SourceTimestamp; metric.OpcValue = NewValue.WrappedValue.Value; metric.Opcstatus = NewValue.StatusCode.ToString(); metric.Measurement = (MeasurementDto)measurement; l_metricCollection.Add(metric); }
private void MonitorData(MonitoredMeasurement measurement, OpcDa.ItemValueResult p) { OpcMetric metric = new OpcMetric() { Timestamp = p.Timestamp, OpcValue = p.Value, Opcstatus = p.ResultID.ToString(), Measurement = (MeasurementDto)measurement }; l_metricCollection.Add(metric); }
void ReadMeasurement(PolledMeasurement measurement) { var item = new OpcDa.Item { ItemName = measurement.Path }; if (l_server == null || l_server.GetStatus().ServerState != OpcDa.serverState.running) { l_logger.ErrorFormat(string.Format("Server not connected. Cannot read path {0}.", measurement.Name)); throw new Exception(string.Format("Server not connected. Cannot read path {0}.", measurement.Name)); } var result = l_server.Read(new[] { item })[0]; if (result == null) { l_logger.Error("the server replied with an empty response!!!"); throw new Exception("the server replied with an empty response");//if any item cannot read, throw exeption } if (result.ResultID.ToString() != "S_OK") { l_logger.ErrorFormat(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, measurement.Path)); throw new Exception(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, measurement.Path)); } OpcMetric metric = new OpcMetric() { Measurement = measurement, Opcstatus = result.ResultID.ToString(), OpcValue = result.Value, Timestamp = result.Timestamp }; if (OpcHelper.QualifyMetric(ref metric, l_cache)) { l_cache[metric.Measurement.Name] = metric.OpcValue; l_metricCollection.Add(metric); } }