Пример #1
0
        public HistoricalDataForLastRecord GetLastRecord(int id)
        {
            var lastRecordQuery = from data in Entities.HistoricalDatas
                                  where data.IdId.Equals(id)
                                  orderby data.Date descending
                                  select data;

            HistoricalData lastRecordTemp = lastRecordQuery.FirstOrDefault();

            if (lastRecordTemp != null)
            {
                HistoricalDataForLastRecord lastRecord = new HistoricalDataForLastRecord(lastRecordTemp.HistocalDataId, lastRecordTemp.Value, lastRecordTemp.Date);

                return(lastRecord);
            }

            return(null);
        }
Пример #2
0
        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();
            }
        }