From f2e0ad4fd12f2f67fc403709cc0b94d01dbdd237 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: Wed, 25 Sep 2024 12:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=AE=BE=E5=A4=87PLC=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Academy/50L/AddAttribute.cs | 18 + BPASmartClient.Academy/50L/AddData.cs | 46 + BPASmartClient.Academy/50L/BoolAddEnum.cs | 38 + BPASmartClient.Academy/50L/FeedbackData.cs | 71 + BPASmartClient.Academy/50L/FloatAddEnum.cs | 26 + BPASmartClient.Academy/50L/PlcControl.cs | 50 + BPASmartClient.Academy/App.xaml.cs | 4 +- .../View/ReactionKettle500LView.xaml | 1775 +++++++++++++++++ .../View/ReactionKettle500LView.xaml.cs | 357 ++++ .../ViewModel/ReactionKettle500LViewModel.cs | 16 + 10 files changed, 2400 insertions(+), 1 deletion(-) create mode 100644 BPASmartClient.Academy/50L/AddAttribute.cs create mode 100644 BPASmartClient.Academy/50L/AddData.cs create mode 100644 BPASmartClient.Academy/50L/BoolAddEnum.cs create mode 100644 BPASmartClient.Academy/50L/FeedbackData.cs create mode 100644 BPASmartClient.Academy/50L/FloatAddEnum.cs create mode 100644 BPASmartClient.Academy/50L/PlcControl.cs create mode 100644 BPASmartClient.Academy/View/ReactionKettle500LView.xaml create mode 100644 BPASmartClient.Academy/View/ReactionKettle500LView.xaml.cs create mode 100644 BPASmartClient.Academy/ViewModel/ReactionKettle500LViewModel.cs diff --git a/BPASmartClient.Academy/50L/AddAttribute.cs b/BPASmartClient.Academy/50L/AddAttribute.cs new file mode 100644 index 00000000..884b42cc --- /dev/null +++ b/BPASmartClient.Academy/50L/AddAttribute.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public class AddAttribute : Attribute + { + public AddAttribute(string add) + { + Add = add; + } + + public string Add { get; set; } + } +} diff --git a/BPASmartClient.Academy/50L/AddData.cs b/BPASmartClient.Academy/50L/AddData.cs new file mode 100644 index 00000000..86777a36 --- /dev/null +++ b/BPASmartClient.Academy/50L/AddData.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public class AddData + { + protected Dictionary boolAdds { get; set; } = new Dictionary(); + protected Dictionary floatAdds { get; set; } = new Dictionary(); + + protected Dictionary GetAdd() where T : Enum + { + Dictionary result = new Dictionary(); + Type type = typeof(T); + Enum.GetNames(typeof(T)).ToList().ForEach(x => + { + MemberInfo[] memberInfo = type.GetMember(x); + if (memberInfo != null && memberInfo.Length > 0) + { + var attribute = memberInfo[0].GetCustomAttribute(); + if (attribute != null) + { + if (x.TryToEnum(out T eu)) + { + if (!result.ContainsKey(eu)) + { + result.Add(eu, attribute.Add); + } + } + } + } + }); + return result; + } + + public AddData() + { + boolAdds = GetAdd(); + floatAdds = GetAdd(); + } + } +} diff --git a/BPASmartClient.Academy/50L/BoolAddEnum.cs b/BPASmartClient.Academy/50L/BoolAddEnum.cs new file mode 100644 index 00000000..a1e8e541 --- /dev/null +++ b/BPASmartClient.Academy/50L/BoolAddEnum.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public enum BoolAddEnum + { + [Add("DB1.DBX1000.0")] + 反应釜旋转电机, + [Add("DB1.DBX1000.1")] + 负压风机, + [Add("DB1.DBX1000.2")] + 反应釜回原点, + [Add("DB1.DBX1000.3")] + 反应釜压缩空气进气阀, + [Add("DB1.DBX1000.4")] + 反应釜排热空气阀, + [Add("DB1.DBX1000.5")] + 反应釜泄压阀, + [Add("DB1.DBX1000.6")] + 称重水罐负压阀, + [Add("DB1.DBX1000.7")] + 称重水罐重量清零, + [Add("DB1.DBX1001.0")] + 反应釜升温, + [Add("DB1.DBX1001.1")] + 反应釜降温, + [Add("DB1.DBX1000.2")] + 冷凝水罐降温, + [Add("DB1.DBX1002.0")] + 系统启动, + [Add("DB1.DBX1003.7")] + 心跳, + } +} diff --git a/BPASmartClient.Academy/50L/FeedbackData.cs b/BPASmartClient.Academy/50L/FeedbackData.cs new file mode 100644 index 00000000..acf8cc5c --- /dev/null +++ b/BPASmartClient.Academy/50L/FeedbackData.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public class FeedbackData + { + /// + /// 旋转电机启停反馈 + /// + public bool RotatingMachines { get; set; } + + /// + /// 负压风机启动反馈 + /// + public string MachineName { get; set; } + + /// + /// 压缩空气进气阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 排热空气阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 泄压阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 进冷却水阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 出冷却水阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 蒸汽梳水阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 冷凝水罐进水阀反馈 + /// + public string MachineName { get; set; } + + /// + /// 称重水罐负压阀 + /// + public string MachineName { get; set; } + + /// + /// 反应釜原点位置反馈 + /// + public string MachineName { get; set; } + + /// + /// 心跳 + /// + public string MachineName { get; set; } + } +} diff --git a/BPASmartClient.Academy/50L/FloatAddEnum.cs b/BPASmartClient.Academy/50L/FloatAddEnum.cs new file mode 100644 index 00000000..a8abc4f3 --- /dev/null +++ b/BPASmartClient.Academy/50L/FloatAddEnum.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public enum FloatAddEnum + { + [Add("DB1.DBD1004")] + 反应釜旋转电机速度, + [Add("DB1.DBD1008")] + 反应釜设定升温温度, + [Add("DB1.DBD1016")] + 反应釜设定降温温度, + [Add("DB1.DBD1020")] + 反应釜温度校准, + [Add("DB1.DBD1024")] + 冷凝水罐温度校准, + [Add("DB1.DBD1028")] + 蒸汽比例阀开度, + [Add("DB1.DBD1032")] + 反应釜蒸汽压力上限 + } +} diff --git a/BPASmartClient.Academy/50L/PlcControl.cs b/BPASmartClient.Academy/50L/PlcControl.cs new file mode 100644 index 00000000..308cdad2 --- /dev/null +++ b/BPASmartClient.Academy/50L/PlcControl.cs @@ -0,0 +1,50 @@ +using BPA.Communication.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy._50L +{ + public class PlcControl : AddData + { + private volatile static PlcControl _Instance; + public static PlcControl GetInstance => _Instance ?? (_Instance = new PlcControl()); + private PlcControl() { } + + private ICommSiemens comm = CommHelper.Siemens; + + public void Init() + { + CommHelper.CreateSiemens(CpuType.S71200, Json.Data.IpAddress).OnSuccess(s => + { + comm = s.Content; + }); + } + + private void Read() + { + + + } + + public void Write(BoolAddEnum add, bool value) + { + if (boolAdds.ContainsKey(add)) + { + comm.Write(boolAdds[add], value); + } + } + + public void Write(FloatAddEnum add, float value) + { + if (floatAdds.ContainsKey(add)) + { + comm.Write(floatAdds[add], value); + } + } + + } +} diff --git a/BPASmartClient.Academy/App.xaml.cs b/BPASmartClient.Academy/App.xaml.cs index 286f6e1f..b870e459 100644 --- a/BPASmartClient.Academy/App.xaml.cs +++ b/BPASmartClient.Academy/App.xaml.cs @@ -1,4 +1,5 @@ -using BPASmartClient.CustomResource.UserControls; +using BPASmartClient.Academy._50L; +using BPASmartClient.CustomResource.UserControls; using LiveCharts; using System.Collections.Specialized; using System.Configuration; @@ -48,6 +49,7 @@ namespace BPASmartClient.Academy SystemHelper.GetInstance.CreateDesktopShortcut(); DataInit(); MenuInit(); + PlcControl.GetInstance.Init(); MainView mv = new MainView(); MessageNotify.GetInstance.window = mv; mv.TitleName = $"10L 反应釜焖制系统 V1.0.1"; diff --git a/BPASmartClient.Academy/View/ReactionKettle500LView.xaml b/BPASmartClient.Academy/View/ReactionKettle500LView.xaml new file mode 100644 index 00000000..3a2c72dc --- /dev/null +++ b/BPASmartClient.Academy/View/ReactionKettle500LView.xaml @@ -0,0 +1,1775 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +