private void ReadValueFromDevice() { if (IsCalibrationFetched == false) { return; } LastValue2 result = null; try { result = channel.GetLastValue(this.Id); } catch (System.Exception ex) { logger.LogException(LogLevel.Info, string.Format("MonitoringAIO.ReadValueFromDevice.{0}", this.Id), ex); return; } if (result == null) { return; } if (result.HasError) { return; } var temp = result.Value; if (temp == null) { return; } if (this.Calibration != 0) { if (this.CalibrationOperation == CalibrationOperation.Jam) { temp += this.Calibration; } else if (this.CalibrationOperation == CalibrationOperation.Zarb) { temp *= this.Calibration; } } this.Value = (double)temp; this.PersianDateString = string.Format("تاریخ : {0}", result.PersianDateString); Dispatcher.BeginInvoke(new Action(SetValueOnUI)); }
public LastValue2 GetLastValue(int id) { Entities = new MonitoringEntities(); LastValue lastValue = Entities.LastValues.FirstOrDefault(x => x.Id == id); LastValue2 result = new LastValue2(); if (lastValue != null) { result.Id = id; result.Date = lastValue.Date; if (lastValue.Date != null) { result.PersianDateString = ((DateTime)lastValue.Date).ToPersianString(); } result.Value = lastValue.Value; result.HasError = false; } return(result); }