Browse Source

临时提交

陈子杰 3 months ago
parent
commit
87a3171c0f

BIN
Lib/DagaSensorLib.dll


BIN
Lib/HidSharp.dll


+ 46 - 0
SCADA_DAQ/Customer/CustomerEnv.cs

@@ -19,5 +19,51 @@ namespace SCADA_DAQ.Customer
 
         public static DaqSettingModel DaqSettingValue { get => DaqSettingModel.Value; }
 
+        public static TempOffsetSettingModel TempSettingModelValue { get => TempSettingModel.Value; }
+
+        public static AutoSaveParameterItem<TempOffsetSettingModel> TempSettingModel = AutoSaveParameterItem.Create("Temp_Setting", new TempOffsetSettingModel
+        {
+            Temp1Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp2Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp3Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp4Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp5Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp6Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp7Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+            Temp8Setting = new GainOffsetModel
+            {
+                Gain = 1,
+                Offset = 0,
+            },
+
+        });
     }
 }

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

@@ -0,0 +1,227 @@
+using SCADA.CommonLib;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SCADA_DAQ.Customer.Models
+{
+    public class TempOffsetSettingModel : ObservableObject
+    {
+
+        /// <summary>
+        /// 温度通道1参数
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道1参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp1Setting
+        {
+            get { return _Temp1Setting; }
+            set
+            {
+                if (value != _Temp1Setting)
+                {
+                    _Temp1Setting = value;
+                    OnPropertyChanged(nameof(Temp1Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp1Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道2参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp2Setting
+        {
+            get { return _Temp2Setting; }
+            set
+            {
+                if (value != _Temp2Setting)
+                {
+                    _Temp2Setting = value;
+                    OnPropertyChanged(nameof(Temp2Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp2Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道3参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp3Setting
+        {
+            get { return _Temp3Setting; }
+            set
+            {
+                if (value != _Temp3Setting)
+                {
+                    _Temp3Setting = value;
+                    OnPropertyChanged(nameof(Temp3Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp3Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道4参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp4Setting
+        {
+            get { return _Temp4Setting; }
+            set
+            {
+                if (value != _Temp4Setting)
+                {
+                    _Temp4Setting = value;
+                    OnPropertyChanged(nameof(Temp4Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp4Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道5参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp5Setting
+        {
+            get { return _Temp5Setting; }
+            set
+            {
+                if (value != _Temp5Setting)
+                {
+                    _Temp5Setting = value;
+                    OnPropertyChanged(nameof(Temp5Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp5Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道6参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp6Setting
+        {
+            get { return _Temp6Setting; }
+            set
+            {
+                if (value != _Temp6Setting)
+                {
+                    _Temp6Setting = value;
+                    OnPropertyChanged(nameof(Temp6Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp6Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道7参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp7Setting
+        {
+            get { return _Temp7Setting; }
+            set
+            {
+                if (value != _Temp7Setting)
+                {
+                    _Temp7Setting = value;
+                    OnPropertyChanged(nameof(Temp7Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp7Setting;
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// 
+        [AutoViewProperty("温度通道8参数", Icon = "Arch")]
+
+        public GainOffsetModel Temp8Setting
+        {
+            get { return _Temp8Setting; }
+            set
+            {
+                if (value != _Temp8Setting)
+                {
+                    _Temp8Setting = value;
+                    OnPropertyChanged(nameof(Temp8Setting));
+                }
+            }
+        }
+        private GainOffsetModel _Temp8Setting;
+
+    }
+
+    public class GainOffsetModel : ObservableObject
+    {
+
+        /// <summary>
+        /// 增益
+        /// </summary>
+        /// 
+        [AutoViewProperty("增益",Icon = "Arch")]
+        public decimal Gain
+        {
+            get { return _Gain; }
+            set
+            {
+                if (value != _Gain)
+                {
+                    _Gain = value;
+                    OnPropertyChanged(nameof(Gain));
+                }
+            }
+        }
+        private decimal _Gain;
+
+
+        /// <summary>
+        /// 偏置
+        /// </summary>
+        /// 
+        [AutoViewProperty("偏置", Icon = "Arch")]
+
+        public decimal Offset
+        {
+            get { return _Offset; }
+            set
+            {
+                if (value != _Offset)
+                {
+                    _Offset = value;
+                    OnPropertyChanged(nameof(Offset));
+                }
+            }
+        }
+        private decimal _Offset;
+
+
+    }
+}

+ 104 - 7
SCADA_DAQ/Customer/Service/CustomerService.cs

@@ -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();
         }
     }

+ 4 - 3
SCADA_DAQ/Customer/UctFrmMain.xaml.cs

@@ -303,13 +303,14 @@ namespace SCADA_DAQ.Customer
                     }
                     else
                     {
-                        if (i < 8)
+                        if (i < 9)
                         {
-                            value = plc1.GetListenReg($"40000{i}").ScaleValue.Value;
+                            //value = plc1.GetListenReg($"40000{i}").ScaleValue.Value;
+                            value = CustomerService.Temps[i-1];
                         }
                         else
                         {
-                            value = plc2.GetListenReg($"40000{i - 6}").ScaleValue.Value;
+                            value = plc2.GetListenReg($"40000{i - 8}").ScaleValue.Value;
                         }
 
                         

+ 2 - 1
SCADA_DAQ/Customer/UctFrmParameterSet.xaml

@@ -9,6 +9,7 @@
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <Grid>
-            
+        <GroupBox Header="温度参数设置" x:Name="TempSetting"/>
+
     </Grid>
 </wpfcontrol:BaseUctFrm>

+ 1 - 0
SCADA_DAQ/Customer/UctFrmParameterSet.xaml.cs

@@ -28,6 +28,7 @@ namespace SCADA_DAQ.Customer
         public UctFrmParameterSet()
         {
             InitializeComponent();
+            TempSetting.Content = new AutoView(CustomerEnv.TempSettingModelValue,2) { MaxTitleWidth = 300 };
         }
     }
 }

+ 10 - 1
SCADA_DAQ/Customer/Views/Uct/UctDaqInfo.xaml.cs

@@ -94,7 +94,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
             //Grid.SetColumn(uctRegView, colunm);
             //Grid.SetRow(uctRegView, row);
             UserPlcValue.Children.Add(uctRegView);
-            plc1.BaseDevice.ScanCompleted += BaseDevice_ScanCompleted; ;
+            //plc1.BaseDevice.ScanCompleted += BaseDevice_ScanCompleted; ;
             plc2.BaseDevice.ScanCompleted += BaseDevice_ScanCompleted1;
             plc3.BaseDevice.ScanCompleted += BaseDevice_ScanCompleted2;
 
@@ -112,6 +112,15 @@ namespace SCADA_DAQ.Customer.Views.Uct
             {
                 TempPressureFlow.Flow = Math.Round(reg.ScaleValue.Value, 1).ToString();
             }
+            TempPressureFlow.Temp1 = CustomerService.Instance.TempStrs[0];
+            TempPressureFlow.Temp2 = CustomerService.Instance.TempStrs[1];
+            TempPressureFlow.Temp3 = CustomerService.Instance.TempStrs[2];
+            TempPressureFlow.Temp4 = CustomerService.Instance.TempStrs[3];
+            TempPressureFlow.Temp5 = CustomerService.Instance.TempStrs[4];
+            TempPressureFlow.Temp6 = CustomerService.Instance.TempStrs[5];
+            TempPressureFlow.Temp7 = CustomerService.Instance.TempStrs[6];
+            TempPressureFlow.Temp8 = CustomerService.Instance.TempStrs[7];
+
         }
 
         private void BaseDevice_ScanCompleted1(object sender, EventArgs e)

+ 8 - 0
SCADA_DAQ/SCADA_DAQ.csproj

@@ -68,6 +68,14 @@
       <HintPath>..\Lib\ControlzEx.dll</HintPath>
       <Private>False</Private>
     </Reference>
+    <Reference Include="DagaSensorLib">
+      <HintPath>..\Lib\DagaSensorLib.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="HidSharp">
+      <HintPath>..\Lib\HidSharp.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="ICSharpCode.SharpZipLib">
       <HintPath>..\Lib\ICSharpCode.SharpZipLib.dll</HintPath>
       <Private>False</Private>