Browse Source

增加温度过滤

陈子杰 2 months ago
parent
commit
bce6d54a60

+ 22 - 0
SCADA_DAQ/Customer/Models/TempOffsetSettingModel.cs

@@ -177,6 +177,28 @@ namespace SCADA_DAQ.Customer.Models
         }
         private GainOffsetModel _Temp8Setting;
 
+
+        /// <summary>
+        /// 温度最大斜率设置
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度斜率最大设置", Icon = "Arch")]
+
+        public double Rate
+        {
+            get { return _Rate; }
+            set
+            {
+                if (value != _Rate)
+                {
+                    _Rate = value;
+                    OnPropertyChanged(nameof(Rate));
+                }
+            }
+        }
+        private double _Rate;
+
+
     }
 
     public class GainOffsetModel : ObservableObject

+ 36 - 20
SCADA_DAQ/Customer/Service/CustomerService.cs

@@ -47,8 +47,13 @@ namespace SCADA_DAQ.Customer.Service
 
         private bool PowerStartScan { get; set; } = true;
 
+        private bool FirstScan { get; set; }
+
         public double[] Temps = new double[8];
 
+        public double[] OldTemps = new double[8];
+
+
         public string[] TempStrs = new string[8];
 
         public bool[] Result = new bool[8];
@@ -69,7 +74,7 @@ namespace SCADA_DAQ.Customer.Service
 
         CancellationTokenSource cts = new CancellationTokenSource();
 
-        CancellationToken token ;
+        CancellationToken token;
 
 
 
@@ -98,18 +103,19 @@ namespace SCADA_DAQ.Customer.Service
                 {
                     if (!cts.IsCancellationRequested)
                     {
-                            if (pM9805 != null)
-                            {
-                                PowerMeter.Power = ((PoweMeterReuslt)pM9805.ReadResult()).Power;
-                            }
-                            if (!tcmnUModbusV2.Connected)
-                            {
-                                ScanTempDevice();
-                            }
+                        if (pM9805 != null)
+                        {
+                            PowerMeter.Power = ((PoweMeterReuslt)pM9805.ReadResult()).Power;
+                        }
+                        if (!tcmnUModbusV2.Connected)
+                        {
+                            FirstScan = false;
+                            ScanTempDevice();
+                        }
                     }
                     Thread.Sleep(200);
                 }
-            },token);
+            }, token);
             tcmnUModbusV2.DataArrivedAction = DataArrived;
             return base.Start();
         }
@@ -122,9 +128,17 @@ namespace SCADA_DAQ.Customer.Service
                 var tempModel = CustomerEnv.TempSettingModelValue;
                 for (int i = 0; i < 8; i++)
                 {
-                    var gain = (GainOffsetModel)tempModel.GetType().GetProperty($"Temp{i+1}Setting").GetValue(tempModel, null);
-
-                    Temps[i] = TempTransfer(data.temperature[i].TcTempString,out Result[i]) * (double)gain.Gain + (double)gain.Offset;
+                    var gain = (GainOffsetModel)tempModel.GetType().GetProperty($"Temp{i + 1}Setting").GetValue(tempModel, null);
+                    var currentTemp = TempTransfer(data.temperature[i].TcTempString, out Result[i]) * (double)gain.Gain + (double)gain.Offset;
+                    if (FirstScan)
+                    {
+                        Temps[i] = Math.Abs( currentTemp - OldTemps[i]) / 5 < CustomerEnv.TempSettingModelValue.Rate ? currentTemp : OldTemps[i];
+                    }
+                    else
+                    {
+                        Temps[i] = currentTemp;                 
+                    }
+                    OldTemps[i] = Temps[i];
                     if (Result[i])
                     {
                         TempStrs[i] = Temps[i].ToString();
@@ -138,21 +152,23 @@ namespace SCADA_DAQ.Customer.Service
             });
             //Log.Info("收到温度数据");
             action.Invoke(tcmnUModbusV2.sensorData);
+            FirstScan = true;
+
         }
 
-        
-        public double TempTransfer(string str,out bool TransferResult)
+
+        public double TempTransfer(string str, out bool TransferResult)
         {
-            double temp = 0;
-            var res = double.TryParse(str.Replace("℃",""), out temp);
+            //double temp = 0;
+            var res = double.TryParse(str.Replace("℃", ""), out double temp);
+
             if (res)
             {
                 TransferResult = true;
-
             }
             else
             {
-                TransferResult=false;
+                TransferResult = false;
             }
             return temp;
         }
@@ -206,7 +222,7 @@ namespace SCADA_DAQ.Customer.Service
                     // "Unsuccessfully open device, please check your device."
                     return;
                 }
-                
+
             }
         }
 

+ 1 - 1
SCADA_DAQ/Customer/Views/Uct/UctMsChart.xaml.cs

@@ -199,7 +199,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
                 //曲线范围,与上述ca一致
                 line.ChartArea = "ChartArea1";
                 //设置图标类型,曲线、柱状、点 等
-                line.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+                line.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                 //图例是否显示
                 line.IsVisibleInLegend = true;
                 //选择哪个图例

+ 1 - 1
SCADA_DAQ/Customer/Views/Uct/UctMsChart1.xaml.cs

@@ -198,7 +198,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
                 //曲线范围,与上述ca一致
                 line.ChartArea = "ChartArea1";
                 //设置图标类型,曲线、柱状、点 等
-                line.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+                line.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
                 //图例是否显示
                 line.IsVisibleInLegend = true;
                 //选择哪个图例