public void CheckDeviceStatus() { SharedLibraryMonitoringDevice.DeviceStatusCache result = null; try { //result = channel.GetDeviceStatus(IPAddress); if (Appl18 != null) { result = Appl18.GetDeviceStatus(); } else if (Appl19 != null) { result = Appl19.GetDeviceStatus(); } } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); return; } if (result == null) { return; } DeviceStatusHistory lastRecord = null; try { lastRecord = channel.GetLastDeviceStatusHistory(IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); //return; } if (lastRecord == null) { try { channel.AddNewDeviceStatusHistory(result.Id, IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); } SaveValueInDeviceStatusLastRecord(result.Id); return; } //TimeSpan timeSpanDiff = DateTime.Now - lastRecord.Date; //if (timeSpanDiff > MaxTimeInterval) //{ // try // { // channel.AddNewDeviceStatusHistory(result.Id, IPAddress); // } // catch (System.Exception ex) // { // //TODO Exception // } // SaveValueInDeviceStatusLastRecord(result.Id); // return; //} if (result.Id != lastRecord.StatusId) { try { channel.AddNewDeviceStatusHistory(result.Id, IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); } SaveValueInDeviceStatusLastRecord(result.Id); return; } SaveValueInDeviceStatusLastRecord(result.Id); }
private void ReadValueFromDevice() { if (IsCalibrationFetched == false) { return; } ProcessDataResult processDataResult = null; #if RELEASE if (Appl18 != null) { processDataResult = Appl18.GetInputValue(this.Id); } else if (Appl19 != null) { processDataResult = Appl19.GetInputValue(this.Id); } #endif #if DEBUG processDataResult = ProcessData.GetData(IPAddress, ILModuleNumber, PDInWord); #endif if (processDataResult.HasError) { return; } double temp = (float)processDataResult.Value; if (this.Calibration != 0) { if (this.CalibrationOperation == CalibrationOperation.Jam) { temp += this.Calibration; } else if (this.CalibrationOperation == CalibrationOperation.Zarb) { temp *= this.Calibration; } } this.Value = temp; try { channel.AddNewLastValue(this.Id, this.Value); } catch (System.Exception ex) { logger.LogException(LogLevel.Info, string.Format("MonitoringAIOServer.ReadValueFromDevice.{0}", this.Id), ex); return; } HistoricalDataForLastRecord lastRecord = null; try { lastRecord = channel.GetLastRecord(this.Id); } catch (System.Exception ex) { logger.LogException(LogLevel.Info, string.Format("MonitoringAIOServer.ReadValueFromDevice.{0}", this.Id), ex); return; } if (lastRecord == null) { SaveValueInDatabase(); } else { TimeSpan timeSpanDiff = DateTime.Now - lastRecord.Date; if (timeSpanDiff > MaxTimeInterval) { SaveValueInDatabase(); return; } double lastRecordvalue = lastRecord.Value; var diff = Math.Abs(lastRecordvalue - this.Value); if (diff < this.DifferenceBetweenCurrentAndLastRecord) { return; } SaveValueInDatabase(); } }