diff --git a/BPASmartClient.Academy/50L/AddData.cs b/BPASmartClient.Academy/50L/AddData.cs index 449c70ab..d4042514 100644 --- a/BPASmartClient.Academy/50L/AddData.cs +++ b/BPASmartClient.Academy/50L/AddData.cs @@ -1,4 +1,6 @@ -using System; +using BPASmartClient.Academy.ShareModel; + +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/BPASmartClient.Academy/50L/BoolAddEnum.cs b/BPASmartClient.Academy/50L/BoolAddEnum.cs index cae9154a..f7a9d1de 100644 --- a/BPASmartClient.Academy/50L/BoolAddEnum.cs +++ b/BPASmartClient.Academy/50L/BoolAddEnum.cs @@ -1,4 +1,6 @@ -using System; +using BPASmartClient.Academy.ShareModel; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/BPASmartClient.Academy/50L/FloatAddEnum.cs b/BPASmartClient.Academy/50L/FloatAddEnum.cs index 2ab991a9..201c6041 100644 --- a/BPASmartClient.Academy/50L/FloatAddEnum.cs +++ b/BPASmartClient.Academy/50L/FloatAddEnum.cs @@ -1,4 +1,6 @@ -using System; +using BPASmartClient.Academy.ShareModel; + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/BPASmartClient.Academy/Model/Enum_10L/BoolAddr_10L.cs b/BPASmartClient.Academy/Model/Enum_10L/BoolAddr_10L.cs new file mode 100644 index 00000000..2c6a89b0 --- /dev/null +++ b/BPASmartClient.Academy/Model/Enum_10L/BoolAddr_10L.cs @@ -0,0 +1,88 @@ +using BPASmartClient.Academy.ShareModel; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Academy.Model.Enums_10L +{ + public enum BoolAddr_10L + { + [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.DBX1001.2")] + 配料釜蒸汽阀, + [Add("DB1.DBX1001.3")] + 反应釜蒸汽阀, + [Add("DB1.DBX1001.4")] + 反应釜蒸汽疏水阀, + [Add("DB1.DBX1001.5")] + 反应釜冷却水阀, + [Add("DB1.DBX1001.6")] + 配料罐自动升温, + [Add("DB1.DBX1001.7")] + 反应釜自动升温, + [Add("DB1.DBX1002.0")] + 系统启动, + [Add("DB1.DBX1002.1")] + 手自动, + [Add("DB1.DBX1002.2")] + 反应釜冷却水排水阀, + [Add("DB1.DBX1002.3")] + 分馏真空阀, + [Add("DB1.DBX1002.4")] + 蒸馏真空阀, + [Add("DB1.DBX1002.5")] + 空压机启动, + [Add("DB1.DBX1002.6")] + 备用_1, + [Add("DB1.DBX1002.7")] + 水罐重量清零, + [Add("DB1.DBX1003.0")] + 反应釜自动降温, + [Add("DB1.DBX1003.1")] + 反应釜出料阀, + [Add("DB1.DBX1003.2")] + 反应釜排空阀, + [Add("DB1.DBX1003.3")] + 配料釜蒸汽输水旁通阀, + [Add("DB1.DBX1003.4")] + 反应釜蒸汽输水旁通阀, + [Add("DB1.DBX1003.5")] + 备用_2, + [Add("DB1.DBX1003.6")] + 备用_3, + [Add("DB1.DBX1003.7")] + 心跳, + [Add("DB1.DBX3000.0")] + 闪蒸, + [Add("DB1.DBX3000.1")] + 真空蒸馏, + [Add("DB1.DBX3000.2")] + 真空下料, + [Add("DB1.DBX3000.3")] + 二次闪蒸, + [Add("DB1.DBX3000.4")] + 排空阀, + } +} diff --git a/BPASmartClient.Academy/Model/Simens_PLC.cs b/BPASmartClient.Academy/Model/Simens_PLC.cs index 380e8ef9..7ad23253 100644 --- a/BPASmartClient.Academy/Model/Simens_PLC.cs +++ b/BPASmartClient.Academy/Model/Simens_PLC.cs @@ -15,6 +15,10 @@ using System.Text; using System.Threading.Tasks; using static Org.BouncyCastle.Asn1.Cmp.Challenge; using Org.BouncyCastle.Asn1.Crmf; +using BPASmartClient.Academy.Model.Enums_10L; +using BPASmartClient.Academy.ShareModel; +using System.Reflection; +using BPA.Communication.Interfaces; namespace BPASmartClient.Academy.Model { @@ -23,7 +27,7 @@ namespace BPASmartClient.Academy.Model private static Simens_PLC _instance; public static Simens_PLC GetInstance { get; set; } = _instance ??= new Simens_PLC(); private Simens_PLC() { } - + protected Dictionary boolAdds { get;private set; } = new Dictionary(); public DataFeedback dataFeedback { get; set; } = new DataFeedback(); public PipeLineMode PipeLine { get; set; } = new PipeLineMode(); public string id { get; set; } = ""; @@ -69,6 +73,7 @@ namespace BPASmartClient.Academy.Model public void Init() { AlarmInfoGet(); + boolAdds = GetAdd(); } public void AlarmInfoGet() { @@ -474,6 +479,40 @@ namespace BPASmartClient.Academy.Model Thread.Sleep(3000); } - + public OperateResult Write(BoolAddr_10L add, bool value) + { + if (boolAdds.ContainsKey(add)) + { + return siemens.Write(boolAdds[add], value); + } + else + { + return OperateResult.Failed($"未查找到该地址{add.ToString()}"); + } + } + private 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; + } } } diff --git a/BPASmartClient.Academy/50L/AddAttribute.cs b/BPASmartClient.Academy/ShareModel/AddAttribute.cs similarity index 87% rename from BPASmartClient.Academy/50L/AddAttribute.cs rename to BPASmartClient.Academy/ShareModel/AddAttribute.cs index 884b42cc..a156bde6 100644 --- a/BPASmartClient.Academy/50L/AddAttribute.cs +++ b/BPASmartClient.Academy/ShareModel/AddAttribute.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BPASmartClient.Academy._50L +namespace BPASmartClient.Academy.ShareModel { public class AddAttribute : Attribute { diff --git a/BPASmartClient.Academy/View/DeviceMotion_2View.xaml b/BPASmartClient.Academy/View/DeviceMotion_2View.xaml index 08768ee9..195ba782 100644 --- a/BPASmartClient.Academy/View/DeviceMotion_2View.xaml +++ b/BPASmartClient.Academy/View/DeviceMotion_2View.xaml @@ -3,10 +3,11 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:bpa="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource" + xmlns:cc="clr-namespace:BPASmartClient.Academy.CustomControls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:helper="clr-namespace:BPASmartClient.Academy.Themes" xmlns:local="clr-namespace:BPASmartClient.Academy.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:helper="clr-namespace:BPASmartClient.Academy.Themes" xmlns:vm="clr-namespace:BPASmartClient.Academy.ViewModel" d:DesignHeight="950" d:DesignWidth="1735" mc:Ignorable="d"> @@ -79,7 +80,7 @@ - - + RenderTransformOrigin="0.5,0.5" Tag="进料阀"> + - - + + - + MouseLeftButtonDown="ValveWithCommandState_MouseLeftButtonDown" + OpenEnable="{Binding DeviceStatus.VX102}" + Tag="回油阀" /> - + MouseLeftButtonDown="ValveWithCommandState_MouseLeftButtonDown" + OpenEnable="{Binding DeviceStatus.VX103}" + Tag="回水阀" /> - - + RenderTransformOrigin="0.5,0.5" Tag="汇馏阀"> + - - + + @@ -309,24 +319,26 @@ Speed="10" Style="{StaticResource BasePipeLineHStyle}" /> - - + RenderTransformOrigin="0.5,0.5" Tag="蒸馏阀"> + - - + + - - + RenderTransformOrigin="0.5,0.5" Tag="排馏阀"> + - - + + + Text="冷凝器冷却阀" /> - + CommandColor="{Binding DeviceStatus.冷凝器冷却阀, Converter={StaticResource BoolToColorConverter}}" + EdgeColor="{Binding DeviceStatus.VX106, Converter={StaticResource deviceConvert}, ConverterParameter=2}" + MouseLeftButtonDown="ValveWithCommandState_MouseLeftButtonDown" + OpenEnable="{Binding DeviceStatus.VX106}" + Tag="冷凝器冷却阀" /> @@ -399,20 +417,23 @@ Fill="{Binding DeviceStatus.VX107, Converter={StaticResource deviceConvert}, ConverterParameter=2}" Speed="10" Style="{StaticResource BasePipeLineHStyle}" /> - + CommandColor="{Binding DeviceStatus.配料釜蒸汽阀, Converter={StaticResource BoolToColorConverter}}" + EdgeColor="{Binding DeviceStatus.VX107, Converter={StaticResource deviceConvert}, ConverterParameter=2}" + MouseLeftButtonDown="ValveWithCommandState_MouseLeftButtonDown" + OpenEnable="{Binding DeviceStatus.VX107}" + Tag="配料釜蒸汽阀" /> - - + RenderTransformOrigin="0.5,0.5" Tag="反应釜蒸汽阀"> + - - + + - - + RenderTransformOrigin="0.5,0.5" Tag="反应釜蒸汽疏水阀"> + - - + + - - + RenderTransformOrigin="0.5,0.5" Tag="反应釜冷却水阀"> + - - + + - - + RenderTransformOrigin="0.5,0.5" Tag="反应釜冷却水排水阀"> + - - + + @@ -583,21 +613,24 @@ Fill="{Binding DeviceStatus.VX112, Converter={StaticResource deviceConvert}, ConverterParameter=2}" Speed="10" Style="{StaticResource BasePipeLineVStyle}" /> - - + RenderTransformOrigin="0.5,0.5" Tag="分馏真空阀"> + - - + + @@ -616,13 +649,16 @@ LineWidth="20" Speed="2" Style="{StaticResource BasePipeLineBLStyle}" /> - + CommandColor="{Binding DeviceStatus.蒸馏真空阀, Converter={StaticResource BoolToColorConverter}}" + EdgeColor="{Binding DeviceStatus.VX113, Converter={StaticResource deviceConvert}, ConverterParameter=2}" + MouseLeftButtonDown="ValveWithCommandState_MouseLeftButtonDown" + OpenEnable="{Binding DeviceStatus.VX113}" + Tag="蒸馏真空阀" /> @@ -649,10 +685,9 @@ + Text="反应釜搅拌" VerticalAlignment="Top" /> @@ -673,23 +708,22 @@ Width="40" Height="30" Margin="0,0,0,-3" /> - - + RenderTransformOrigin="0.5,0.5" Tag="反应釜出料阀"> + - - - + - - + + @@ -718,7 +752,7 @@ @@ -795,279 +829,61 @@ - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1075,132 +891,25 @@ Width="55" Height="22" Margin="0,0,0,2" BorderThickness="0" Click="Open_Click" Content="真空泵:开" FontSize="8" Foreground="White" GroupName="21" + helper:RadioButtonHelper.ExecuteState="{Binding DeviceStatus.真空泵}" Style="{StaticResource radiobutton}" Tag="2" /> - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1213,48 +922,40 @@ - - @@ -1262,48 +963,40 @@ - - @@ -1319,24 +1012,20 @@ - - - - - - - - - + { + NoticeDemoViewModel.OpenMsg(promptType, App.Current.MainWindow, title, msg); + })); + MessageNotify.GetInstance.ShowRunLog($"人工介入:" + msg); + } + + private void ValveWithCommandState_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (e.Source is ValveWithCommandState valve) + { + if (Simens_PLC.GetInstance.IsConnected && valve.Tag != null && !string.IsNullOrWhiteSpace(valve.Tag.ToString().Trim())) + { + var tag = valve.Tag.ToString().Trim(); + BoolAddr_10L addr = (BoolAddr_10L)Enum.Parse(typeof(BoolAddr_10L), tag); + DeviceControlView.Show(tag, "未知", valve.OpenEnable ? "打开" : "关闭", new Action(() => + { + var result = Simens_PLC.GetInstance.Write(addr, true); + if (result != null && result.IsSuccess) + { + Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:True"); + } + else + { + Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:True\n{result.Message}"); + } + }), new Action(() => + { + var result = Simens_PLC.GetInstance.Write(addr, false); + if (result != null && result.IsSuccess) + { + Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:False"); + } + else + { + Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:False\n{result.Message}"); + } + })); + } + else + { + Notify(EnumPromptType.Error, "失败", "设备未连接,不可进行控制。"); + } + } + } } } diff --git a/BPASmartClient.Academy/View/ReactionKettle50LView.xaml b/BPASmartClient.Academy/View/ReactionKettle50LView.xaml index aab498f2..f359d098 100644 --- a/BPASmartClient.Academy/View/ReactionKettle50LView.xaml +++ b/BPASmartClient.Academy/View/ReactionKettle50LView.xaml @@ -170,7 +170,7 @@ + Storyboard.TargetProperty="Angle" From="360" To="0" Duration="0:0:0.6" /> @@ -303,9 +303,9 @@ + LineWidth="2" /> + LineWidth="2" Speed="0.23" /> @@ -749,7 +750,7 @@ Height="10" HorizontalAlignment="Center" VerticalAlignment="Top" d:Direction="2" Direction="{Binding DeviceStatus.ReactOutHotGasValve, ConverterParameter=5, Converter={StaticResource deviceConvert}}" Fill="{Binding DeviceStatus.ReactOutHotGasValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" - LineWidth="1" /> + LineWidth="2" /> + + LineWidth="2" Speed="2" /> + + + + + + + + + + + + + +