From 3a7e4a20810469206d6d8a3c87bc1e209cd982ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 16 Aug 2024 13:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.Academy.csproj | 2 +- BPASmartClient.Academy/GlobalUsing.cs | 1 + BPASmartClient.Academy/Model/Simens_PLC.cs | 86 ++++++++++--------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/BPASmartClient.Academy/BPASmartClient.Academy.csproj b/BPASmartClient.Academy/BPASmartClient.Academy.csproj index 98cd23cd..24ded65f 100644 --- a/BPASmartClient.Academy/BPASmartClient.Academy.csproj +++ b/BPASmartClient.Academy/BPASmartClient.Academy.csproj @@ -17,13 +17,13 @@ + - diff --git a/BPASmartClient.Academy/GlobalUsing.cs b/BPASmartClient.Academy/GlobalUsing.cs index 5d2e495b..fa834826 100644 --- a/BPASmartClient.Academy/GlobalUsing.cs +++ b/BPASmartClient.Academy/GlobalUsing.cs @@ -14,3 +14,4 @@ global using BPASmartClient.CustomResource.Pages.ViewModel; global using BPASmartClient.CustomResource.Pages.View; global using BPASmartClient.CustomResource.Pages.Model; global using BPASmartClient.CustomResource.Pages.Enums; +global using BPA.Communication; diff --git a/BPASmartClient.Academy/Model/Simens_PLC.cs b/BPASmartClient.Academy/Model/Simens_PLC.cs index 387b3525..d203cc80 100644 --- a/BPASmartClient.Academy/Model/Simens_PLC.cs +++ b/BPASmartClient.Academy/Model/Simens_PLC.cs @@ -1,5 +1,4 @@ using BPA.Helper; -using BPASmartClient.S7Net; using LiveCharts; using Microsoft.Windows.Input; using Newtonsoft.Json.Linq; @@ -21,27 +20,32 @@ namespace BPASmartClient.Academy.Model private Simens_PLC() { } public DataFeedback dataFeedback { get; set; } = new DataFeedback(); public string id { get; set; } = ""; - public SiemensHelper siemens { get; set; } = new SiemensHelper(); - public DeviceCtrl deviceCtrl { get; set; }= new DeviceCtrl(); - public bool IsConnected { get; set; }=false; - bool heart=false; - public void Connect() + //public SiemensHelper siemens { get; set; } = new SiemensHelper(); + public ICommSiemens siemens { get; set; } = CommHelper.Siemens; + public DeviceCtrl deviceCtrl { get; set; } = new DeviceCtrl(); + public bool IsConnected { get; set; } = false; + bool heart = false; + public void Connect() { Task.Factory.StartNew(() => { var x = (NameValueCollection)ConfigurationManager.GetSection("FlexBatchSystem/PLCInfo"); if (x != null) { - siemens.Connect(S7.Net.CpuType.S7200Smart, x.Get("IpAddress"), Convert.ToInt32(x.Get("Port"))); + //siemens.Connect(S7.Net.CpuType.S7200Smart, x.Get("IpAddress"), Convert.ToInt32(x.Get("Port"))); + CommHelper.CreateSiemens(CpuType.S7200Smart, x.Get("IpAddress")); } }); + + + } - public void Init() + public void Init() { - ThreadManage.GetInstance.StartLong(() => + ThreadManage.GetInstance.StartLong(() => { ReadStatus(); - },"状态读取"); + }, "状态读取"); ThreadManage.GetInstance.StartLong(() => { Heartbeat(); @@ -51,45 +55,45 @@ namespace BPASmartClient.Academy.Model ChartDataRead(); }, "曲线数据"); } - public void ReadStatus() + public void ReadStatus() { if (IsConnected) { - deviceCtrl.M101 = siemens.Read("V2000.0"); - deviceCtrl.M102 = siemens.Read("V2000.1"); - deviceCtrl.M103 = siemens.Read("V2000.2"); - deviceCtrl.VX100 = siemens.Read("V2000.3"); - deviceCtrl.VX101 = siemens.Read("V2000.4"); - deviceCtrl.VX102 = siemens.Read("V2000.5"); - deviceCtrl.VX103 = siemens.Read("V2000.6"); - deviceCtrl.VX104 = siemens.Read("V2000.7"); - deviceCtrl.VX105 = siemens.Read("V2001.0"); - heart = siemens.Read("V1003.7"); + deviceCtrl.M101 = siemens.Read("V2000.0").Content; + deviceCtrl.M102 = siemens.Read("V2000.1").Content; + deviceCtrl.M103 = siemens.Read("V2000.2").Content; + deviceCtrl.VX100 = siemens.Read("V2000.3").Content; + deviceCtrl.VX101 = siemens.Read("V2000.4").Content; + deviceCtrl.VX102 = siemens.Read("V2000.5").Content; + deviceCtrl.VX103 = siemens.Read("V2000.6").Content; + deviceCtrl.VX104 = siemens.Read("V2000.7").Content; + deviceCtrl.VX105 = siemens.Read("V2001.0").Content; + heart = siemens.Read("V1003.7").Content; Thread.Sleep(100); } } - public void ChartDataRead() + public void ChartDataRead() { - if (id!="") + if (id != "") { SaveData saveData = new SaveData() { Id = id, Name = dataFeedback.Name, Date = DateTime.Now, - M101_Speed = siemens.Read("VD2006"), - M102_Speed = siemens.Read("VD2010"), - M103_Speed = siemens.Read("VD2014"), - OpenValve = siemens.Read("VD2018"), - TempWok = siemens.Read("VD2022"), - TempMaterial = siemens.Read("VD2026"), - TempVent = siemens.Read("VD2030"), - PressureWok = siemens.Read("VD2034"), - WeightWok = siemens.Read("VD2038"), + M101_Speed = siemens.Read("VD2006").Content, + M102_Speed = siemens.Read("VD2010").Content, + M103_Speed = siemens.Read("VD2014").Content, + OpenValve = siemens.Read("VD2018").Content, + TempWok = siemens.Read("VD2022").Content, + TempMaterial = siemens.Read("VD2026").Content, + TempVent = siemens.Read("VD2030").Content, + PressureWok = siemens.Read("VD2034").Content, + WeightWok = siemens.Read("VD2038").Content, }; - DataView(dataFeedback.M101_Speed, new DataValue() { DateTime = saveData.Date,Value = saveData.M101_Speed}); + DataView(dataFeedback.M101_Speed, new DataValue() { DateTime = saveData.Date, Value = saveData.M101_Speed }); DataView(dataFeedback.M102_Speed, new DataValue() { DateTime = saveData.Date, Value = saveData.M102_Speed }); DataView(dataFeedback.M103_Speed, new DataValue() { DateTime = saveData.Date, Value = saveData.M103_Speed }); DataView(dataFeedback.OpenValve, new DataValue() { DateTime = saveData.Date, Value = saveData.OpenValve }); @@ -119,10 +123,10 @@ namespace BPASmartClient.Academy.Model WeightWok = random.Next(0, 50), }; Sqlite.GetInstance.saveDatas.Add(saveData); - DataView(dataFeedback.M101_Speed, new DataValue() { DateTime = date, Value =saveData.M101_Speed }); + DataView(dataFeedback.M101_Speed, new DataValue() { DateTime = date, Value = saveData.M101_Speed }); DataView(dataFeedback.M102_Speed, new DataValue() { DateTime = date, Value = saveData.M102_Speed }); - DataView(dataFeedback.M103_Speed, new DataValue() { DateTime = date, Value = saveData.M103_Speed}); - DataView(dataFeedback.TempWok, new DataValue() { DateTime = date, Value =saveData.TempWok}); + DataView(dataFeedback.M103_Speed, new DataValue() { DateTime = date, Value = saveData.M103_Speed }); + DataView(dataFeedback.TempWok, new DataValue() { DateTime = date, Value = saveData.TempWok }); DataView(dataFeedback.TempMaterial, new DataValue() { DateTime = date, Value = saveData.TempMaterial }); DataView(dataFeedback.TempVent, new DataValue() { DateTime = date, Value = saveData.TempVent }); DataView(dataFeedback.OpenValve, new DataValue() { DateTime = date, Value = saveData.OpenValve }); @@ -130,13 +134,13 @@ namespace BPASmartClient.Academy.Model DataView(dataFeedback.WeightWok, new DataValue() { DateTime = date, Value = saveData.WeightWok }); - + } Thread.Sleep(1000); } - public void DataView(ChartValues values,T value) + public void DataView(ChartValues values, T value) { - if (values.Count>=100) + if (values.Count >= 100) { values.RemoveAt(0); values.Add(value); @@ -146,7 +150,7 @@ namespace BPASmartClient.Academy.Model values.Add(value); } } - public void Heartbeat() + public void Heartbeat() { if (!heart) { @@ -158,7 +162,7 @@ namespace BPASmartClient.Academy.Model GetInstance.Connect(); } - if (deviceCtrl.M101) + if (deviceCtrl.M101) { deviceCtrl.M101 = false; }