|
@@ -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;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|