Esempio n. 1
0
 private static Dictionary <int, decimal> ShellTempDic(FrequencyMessage message, int length)
 {
     try
     {
         var tempCache = new ShellTemperatureCache();
         Dictionary <int, decimal> shellTempDic = new Dictionary <int, decimal>(); // 各通道的管壳温度
         for (var i = 0; i < length; i++)
         {
             var shellTemp = QuantityValuePair.CalcShellTemperature(message.Channels[i].ShellTemperature);
             tempCache.Push(i, shellTemp);
             shellTempDic.Add(i, tempCache.AverageTemperature(i));
         }
         return(shellTempDic);
     }
     catch (Exception ex)
     {
         throw new BoundaryException("设备通道数与实际采集数据不一致,请检查!", ex);
     }
 }
Esempio n. 2
0
 public static PhysicalQuantity LoadFrom(FrequencyMessage message, IPhysicalCalculator calc, DateTime recTime)
 {
     try
     {
         var instance = new PhysicalQuantity();
         instance.CurrentTime = recTime;
         //计算各通道的管壳温度
         var shellTempDic = ShellTempDic(message, instance.ChannelValues.Length);
         //预先计算温补通道的物理量
         var tempExValuePairs = TempExValuePairs(message, calc, shellTempDic);
         // 计算各传感器的物理量
         CalcPhysical(message, calc, instance, tempExValuePairs, shellTempDic);
         return(instance);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 3
0
        private static Dictionary <int, QuantityValuePair> TempExValuePairs(FrequencyMessage message, IPhysicalCalculator calc,
                                                                            Dictionary <int, decimal> shellTempDic)
        {
            var tempExConfigs = SensorConfigManager.GetAllIncludedTempExSensor();
            Dictionary <int, QuantityValuePair> tempExValuePairs = new Dictionary <int, QuantityValuePair>();

            foreach (var config in tempExConfigs)
            {
                var i = config.ChannelIndex - 1;
                var j = config.SensorIndex - 1;
                QuantityValuePair pair = new QuantityValuePair();
                pair.Orignal    = QuantityValuePair.CalculateFrequency(message.Channels[i].Gratings[j]);
                pair.WaveLength = QuantityValuePair.FrequencyToWavelength(pair.Orignal);
                var wave = pair.WaveLengthExtension = QuantityValuePair.CalcFrequencyExtension(
                    pair.WaveLength, shellTempDic[i]);
                var current = SensorConfigManager.GetConfigBy(i + 1, j + 1);
                //var extension = SensorConfigManager.GetTemperatureExtensionConfig(current);
                pair.PhysicalValue = QuantityValuePair.CalcPhysicalValue(current, wave, calc); // 温补通道
                tempExValuePairs.Add(config.SensorId, pair);
            }
            return(tempExValuePairs);
        }
        public async Task <List <PhysicalQuantity> > ReadLoop(IPhysicalCalculator calc)
        {
            try
            {
                var list       = new List <PhysicalQuantity>();
                var breakCount = GlobalSetting.Instance.GatherDataFilter;
                var i          = 0;
                while (i < breakCount)
                {
                    var result = await Communication.ReceiveDataAsync();

                    if (result.Length < 530)
                    {
                        continue;
                    }
                    if (i == breakCount - 1)
                    {
                        var recTime = DateTime.Now;

                        var message = new FrequencyMessage();
                        message.Parse(result);

                        var quantity = PhysicalQuantity.LoadFrom(message, calc, recTime);
                        list.Add(quantity);
                    }
                    i++;
                }
                return(list);
            }
            catch (BoundaryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new BoundaryException(ex);
            }
        }
Esempio n. 5
0
        private static void CalcPhysical(FrequencyMessage message, IPhysicalCalculator calc, PhysicalQuantity instance,
                                         Dictionary <int, QuantityValuePair> tempExValuePairs, Dictionary <int, decimal> shellTempDic)
        {
            for (var i = 0; i < instance.ChannelValues.Length; i++)
            {
                for (var j = 0; j < instance.ChannelValues[i].GratingValues.Length; j++)
                {
                    var current = SensorConfigManager.GetConfigBy(i + 1, j + 1);

                    if (current != null && tempExValuePairs.ContainsKey(current.SensorId))
                    {
                        instance.ChannelValues[i].GratingValues[j] = tempExValuePairs[current.SensorId];
                    }
                    else
                    {
                        instance.ChannelValues[i].GratingValues[j].Orignal =
                            QuantityValuePair.CalculateFrequency(message.Channels[i].Gratings[j]);
                        instance.ChannelValues[i].GratingValues[j].WaveLength =
                            QuantityValuePair.FrequencyToWavelength(instance.ChannelValues[i].GratingValues[j].Orignal);
                        var wave =
                            instance.ChannelValues[i].GratingValues[j].WaveLengthExtension =
                                QuantityValuePair.CalcFrequencyExtension(
                                    instance.ChannelValues[i].GratingValues[j].WaveLength, shellTempDic[i]);

                        var     extension = SensorConfigManager.GetTemperatureExtensionConfig(current);
                        decimal?exWave    = null;
                        if (extension != null && tempExValuePairs.ContainsKey(extension.SensorId))
                        {
                            exWave = tempExValuePairs[extension.SensorId].WaveLengthExtension;
                        }
                        instance.ChannelValues[i].GratingValues[j].PhysicalValue =
                            QuantityValuePair.CalcPhysicalValue(current, wave, calc, extension, exWave);
                    }
                }
            }
        }