|
@@ -1,9 +1,13 @@
|
|
|
-using SCADA.Comm;
|
|
|
+using DagaSensorLib;
|
|
|
+using HidSharp;
|
|
|
+using SCADA.Comm;
|
|
|
using SCADA.CommonLib;
|
|
|
using SCADA.CommonLib.CommonModel;
|
|
|
+using SCADA.CommonLib.Helper;
|
|
|
using SCADA.CommonLib.Service;
|
|
|
using SCADA.Instrument.InstrumentType.Power;
|
|
|
using SCADA.Instrument.NaPui;
|
|
|
+using SCADA_DAQ.Customer.Models;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
@@ -12,6 +16,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows.Interop;
|
|
|
|
|
|
namespace SCADA_DAQ.Customer.Service
|
|
|
{
|
|
@@ -37,8 +42,18 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
private PM9805 pM9805 = new PM9805(
|
|
|
new SerialComm(new SerialPort("Com1", 9600, Parity.None, 8, StopBits.One)), 01);
|
|
|
|
|
|
+ public TCMN_UModbus_V2 tcmnUModbusV2 = new TCMN_UModbus_V2();
|
|
|
+
|
|
|
+
|
|
|
private bool PowerStartScan { get; set; } = true;
|
|
|
-
|
|
|
+
|
|
|
+ public double[] Temps = new double[8];
|
|
|
+
|
|
|
+ public string[] TempStrs = new string[8];
|
|
|
+
|
|
|
+ public bool[] Result = new bool[8];
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -52,6 +67,11 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
/// </summary>
|
|
|
public override Type ConfigType => typeof(CustomerServiceConfig);
|
|
|
|
|
|
+ CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
+
|
|
|
+ CancellationToken token ;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private CustomerService()
|
|
|
{
|
|
@@ -70,21 +90,73 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
{
|
|
|
if (IsRunning) { return false; }
|
|
|
RpcService.GetInstance().Regiseter(this); //将服务中方法注册到RPC服务器,可以给WebApi调用
|
|
|
-
|
|
|
- Task.Run(() =>
|
|
|
+ tcmnUModbusV2.Init(null);
|
|
|
+ token = cts.Token;
|
|
|
+ Task task = Task.Run(() =>
|
|
|
{
|
|
|
while (PowerStartScan)
|
|
|
{
|
|
|
- if (pM9805 != null)
|
|
|
+ if (!cts.IsCancellationRequested)
|
|
|
{
|
|
|
- PowerMeter.Power = ((PoweMeterReuslt)pM9805.ReadResult()).Power;
|
|
|
+ if (pM9805 != null)
|
|
|
+ {
|
|
|
+ PowerMeter.Power = ((PoweMeterReuslt)pM9805.ReadResult()).Power;
|
|
|
+ }
|
|
|
+ if (!tcmnUModbusV2.Connected)
|
|
|
+ {
|
|
|
+ ScanTempDevice();
|
|
|
+ }
|
|
|
}
|
|
|
Thread.Sleep(200);
|
|
|
}
|
|
|
- });
|
|
|
+ },token);
|
|
|
+ tcmnUModbusV2.DataArrivedAction = DataArrived;
|
|
|
return base.Start();
|
|
|
}
|
|
|
|
|
|
+ public void DataArrived()
|
|
|
+ {
|
|
|
+ var action = new Action<TCMNSensorData>((data) =>
|
|
|
+ {
|
|
|
+ //var temp = data.temperature[0].TcTempString;
|
|
|
+ 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;
|
|
|
+ if (Result[i])
|
|
|
+ {
|
|
|
+ TempStrs[i] = Temps[i].ToString();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TempStrs[i] = "---";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //Log.Info("收到温度数据");
|
|
|
+ action.Invoke(tcmnUModbusV2.sensorData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public double TempTransfer(string str,out bool TransferResult)
|
|
|
+ {
|
|
|
+ double temp = 0;
|
|
|
+ var res = double.TryParse(str.Replace("℃",""), out temp);
|
|
|
+ if (res)
|
|
|
+ {
|
|
|
+ TransferResult = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TransferResult=false;
|
|
|
+ }
|
|
|
+ return temp;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -119,10 +191,35 @@ namespace SCADA_DAQ.Customer.Service
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public void ScanTempDevice()
|
|
|
+ {
|
|
|
+ var msg = "";
|
|
|
+ var devList = tcmnUModbusV2.LoadDevices(ref msg);
|
|
|
+ if (devList.Count > 0)
|
|
|
+ {
|
|
|
+ //tcmnUModbusV2.Close();
|
|
|
+ bool b = tcmnUModbusV2.Open(devList[0].UsbDevice, "temperature.csv", 500);
|
|
|
+ //bool b = tcmnUModbusV2.Open(devList[0].UsbDevice, "temperature.csv", 500);
|
|
|
+
|
|
|
+ if (!b)
|
|
|
+ {
|
|
|
+ // "Unsuccessfully open device, please check your device."
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public override bool Stop()
|
|
|
{
|
|
|
+ cts.Cancel();
|
|
|
PowerStartScan = false;
|
|
|
pM9805.Dispose();
|
|
|
+ if (tcmnUModbusV2.Connected)
|
|
|
+ {
|
|
|
+ tcmnUModbusV2.Close();
|
|
|
+ }
|
|
|
+ tcmnUModbusV2 = null;
|
|
|
return base.Stop();
|
|
|
}
|
|
|
}
|