@@ -47,7 +47,7 @@ namespace BPASmartClient.Academy | |||
Environment.Exit(0); | |||
} | |||
base.OnStartup(e); | |||
SystemHelper.GetInstance.CreateDesktopShortcut(); | |||
//SystemHelper.GetInstance.CreateDesktopShortcut(); | |||
DataInit(); | |||
MenuInit(); | |||
MainView mv = new MainView(); | |||
@@ -22,6 +22,7 @@ | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Communication" Version="1.0.183" /> | |||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" /> | |||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" /> | |||
<PackageReference Include="OxyPlot.Wpf" Version="2.1.2" /> | |||
</ItemGroup> | |||
@@ -0,0 +1,91 @@ | |||
<Window | |||
x:Class="BPASmartClient.Academy.View.DeviceControlView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:cs="clr-namespace:BPASmartClient.CustomResource;assembly=BPASmartClient.CustomResource" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:BPASmartClient.Academy.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmartClient.Academy.ViewModel" Width="400" Height="250" | |||
d:Visibility="Visible" AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="True" Visibility="Collapsed" WindowStartupLocation="CenterScreen" WindowStyle="None" | |||
mc:Ignorable="d"> | |||
<Window.Resources> | |||
<ResourceDictionary> | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" /> | |||
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Recdictionarys/GlobalStyle.xaml" /> | |||
</ResourceDictionary.MergedDictionaries> | |||
</ResourceDictionary> | |||
</Window.Resources> | |||
<!--<UserControl.DataContext> | |||
<vm:DeviceControlViewModel /> | |||
</UserControl.DataContext>--> | |||
<Border | |||
Name="br" Background="#FF0B2F5F" BorderBrush="#0CADF5" BorderThickness="0"> | |||
<Grid> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="auto" /> | |||
<RowDefinition Height="auto" /> | |||
<RowDefinition Height="1*" /> | |||
<RowDefinition Height="1*" /> | |||
<RowDefinition Height="auto" /> | |||
</Grid.RowDefinitions> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="1*" /> | |||
<ColumnDefinition Width="1*" /> | |||
</Grid.ColumnDefinitions> | |||
<!--#region 窗体标题--> | |||
<TextBlock | |||
Grid.Row="0" Grid.Column="0" FontSize="28" Text="阀门/电机控制" /> | |||
<Button | |||
Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" | |||
Click="Button_Click" Content="关闭窗体" FontSize="28" | |||
Style="{StaticResource ControlButtonStyle}" /> | |||
<!--#endregion--> | |||
<!--#region 阀门名称--> | |||
<TextBlock | |||
Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" | |||
d:Text="反应釜旁通阀控制" FontSize="32" | |||
Text="{Binding ValveName}" | |||
TextAlignment="Center" /> | |||
<!--#endregion--> | |||
<!--#region 指令状态显示--> | |||
<TextBlock | |||
Grid.Row="2" Grid.Column="0" FontSize="28" Text="当前指令状态:" /> | |||
<TextBlock | |||
Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" | |||
d:Text="打开" FontSize="28" | |||
Text="{Binding CommandState}" /> | |||
<!--#endregion--> | |||
<!--#region 设备状态显示--> | |||
<TextBlock | |||
Grid.Row="3" Grid.Column="0" FontSize="28" Text="当前设备状态:" /> | |||
<TextBlock | |||
Grid.Row="3" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" | |||
d:Text="关闭" FontSize="28" | |||
Text="{Binding DeviceState}" /> | |||
<!--#endregion--> | |||
<!--#region 按钮--> | |||
<Button | |||
Grid.Row="4" | |||
Command="{Binding OpenCommand}" | |||
Content="打开" FontSize="32" | |||
Style="{StaticResource OKImageButtonStyle}" /> | |||
<Button | |||
Grid.Row="4" Grid.Column="1" | |||
Command="{Binding CloseCommand}" | |||
Content="关闭" FontSize="32" | |||
Style="{StaticResource CancelImageButtonStyle}" /> | |||
<!--#endregion--> | |||
</Grid> | |||
</Border> | |||
</Window> |
@@ -0,0 +1,133 @@ | |||
using Opc.Ua; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.ComponentModel; | |||
using System.Linq; | |||
using System.Runtime.CompilerServices; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows; | |||
using System.Windows.Controls; | |||
using System.Windows.Data; | |||
using System.Windows.Documents; | |||
using System.Windows.Input; | |||
using System.Windows.Media; | |||
using System.Windows.Media.Imaging; | |||
using System.Windows.Navigation; | |||
using System.Windows.Shapes; | |||
namespace BPASmartClient.Academy.View | |||
{ | |||
/// <summary> | |||
/// DeviceControlView.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class DeviceControlView : Window,INotifyPropertyChanged | |||
{ | |||
private volatile static DeviceControlView _Instance; | |||
private static DeviceControlView GetInstance => _Instance ?? (_Instance = new DeviceControlView()); | |||
private DeviceControlView() | |||
{ | |||
InitializeComponent(); | |||
this.DataContext = this; | |||
//this.ValveName = valveName; | |||
//this.CommandState = commandState; | |||
//this.DeviceState = deviceState; | |||
//this.OpenHandler = openHandler; | |||
//this.CloseHandler = closeHandler; | |||
OpenCommand = new BPARelayCommand(() => | |||
{ | |||
OpenHandler?.Invoke(); | |||
this.Visibility = Visibility.Hidden; | |||
}); | |||
CloseCommand = new(() => | |||
{ | |||
CloseHandler?.Invoke(); | |||
this.Visibility = Visibility.Hidden; | |||
}); | |||
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); }; | |||
} | |||
#region 属性变更通知 | |||
public event PropertyChangedEventHandler? PropertyChanged; | |||
private void OnPropertyChanged([CallerMemberName] string paraName = "") | |||
{ | |||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(paraName)); | |||
} | |||
#endregion | |||
#region Properties | |||
/// <summary> | |||
/// 界面标题 | |||
/// </summary> | |||
public string ValveName { get { return _valveName; } set { _valveName = value; OnPropertyChanged(); } } | |||
private string _valveName; | |||
/// <summary> | |||
/// 命令状态 | |||
/// </summary> | |||
public string CommandState { get { return _commandState; } set { _commandState = value; OnPropertyChanged(); } } | |||
private string _commandState; | |||
/// <summary> | |||
/// 设备状态 | |||
/// </summary> | |||
public string DeviceState { get { return _deviceState; } set { _deviceState = value; OnPropertyChanged(); } } | |||
private string _deviceState; | |||
/// <summary> | |||
/// 点击打开时的动作 | |||
/// </summary> | |||
public Action OpenHandler { get; set; } | |||
/// <summary> | |||
/// 点击关闭时的动作 | |||
/// </summary> | |||
public Action CloseHandler { get; set; } | |||
#endregion | |||
#region Commands | |||
public BPARelayCommand OpenCommand { get; set; } | |||
public BPARelayCommand CloseCommand { get; set; } | |||
#endregion | |||
/// <summary> | |||
/// 打开对话框前事件处理 | |||
/// </summary> | |||
public Action<DeviceControlView> BeforeOpenHandler; | |||
/// <summary> | |||
/// 打开对话框后事件处理 | |||
/// </summary> | |||
public Action<DeviceControlView, object> AfterCloseHandler; | |||
#region Events | |||
#endregion | |||
private void Button_Click(object sender, RoutedEventArgs e) | |||
{ | |||
//this.Close(); | |||
this.Visibility = Visibility.Hidden; | |||
} | |||
public static void Show(string valveName, string commandState, string deviceState, Action openHandler, Action closeHandler) | |||
{ | |||
DeviceControlView view = GetInstance; | |||
view.ValveName = valveName; | |||
view.CommandState = commandState; | |||
view.DeviceState = deviceState; | |||
view.OpenHandler = openHandler; | |||
view.CloseHandler = closeHandler; | |||
view.Visibility=Visibility.Visible; | |||
//view.ShowDialog(); | |||
} | |||
} | |||
} |
@@ -4,6 +4,7 @@ | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:bpa="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" | |||
xmlns:local="clr-namespace:BPASmartClient.Academy.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmartClient.Academy.ViewModel" | |||
@@ -292,7 +293,8 @@ | |||
</StackPanel> | |||
<Viewbox | |||
Grid.Row="1" Margin="10" Stretch="Uniform"> | |||
<Canvas Width="1200" Height="490"> | |||
<Canvas | |||
Width="1200" Height="490" MouseLeftButtonDown="Canvas_MouseDown"> | |||
<!--#region 开关控制按钮--> | |||
<!--#region 压缩空气进气阀--> | |||
<bpa:PipeLineTL | |||
@@ -382,12 +384,12 @@ | |||
Panel.ZIndex="99" Orientation="Vertical"> | |||
<RadioButton | |||
Width="70" Height="20" Margin="0,0,0,2" BorderThickness="0" | |||
Click="open_Click" Content="负压风机:开" FontSize="8" Foreground="White" | |||
Click="open_Click" Content="真空泵:开" FontSize="8" Foreground="White" | |||
Style="{StaticResource radiobutton}" | |||
Tag="负压风机" /> | |||
<RadioButton | |||
Width="70" Height="20" BorderThickness="0" Click="close_Click" | |||
Content="负压风机:关" FontSize="8" Foreground="White" IsChecked="True" | |||
Content="真空泵:关" FontSize="8" Foreground="White" IsChecked="True" | |||
Style="{StaticResource radiobutton}" | |||
Tag="负压风机" /> | |||
</StackPanel> | |||
@@ -478,15 +480,12 @@ | |||
<StackPanel | |||
Canvas.Left="921.095" Canvas.Top="264.326" HorizontalAlignment="Left" VerticalAlignment="Top" | |||
Panel.ZIndex="99" Orientation="Vertical"> | |||
<RadioButton | |||
Width="70" Height="20" Margin="0,0,0,2" BorderThickness="0" | |||
Click="open_Click" Content="旋转电机点动:开" FontSize="8" Foreground="White" | |||
Style="{StaticResource radiobutton}" | |||
Tag="反应釜旋转电机点动" /> | |||
<RadioButton | |||
Width="70" Height="20" BorderThickness="0" Click="close_Click" | |||
Content="旋转电机点动:关" FontSize="8" Foreground="White" IsChecked="True" | |||
Style="{StaticResource radiobutton}" | |||
<Button | |||
Width="70" Height="20" Margin="0,0,0,2" VerticalContentAlignment="Center" | |||
BorderThickness="0" Content="旋转电机点动" FontSize="8" Foreground="White" | |||
PreviewMouseLeftButtonDown="Button_PreviewMouseLeftButtonDown" | |||
PreviewMouseLeftButtonUp="Button_PreviewMouseLeftButtonUp" | |||
Style="{StaticResource ButtonStyle}" | |||
Tag="反应釜旋转电机点动" /> | |||
</StackPanel> | |||
<StackPanel | |||
@@ -863,7 +862,8 @@ | |||
Canvas.Left="603" Canvas.Top="114" Canvas.Right="380.8" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ColdWaterTankInAirValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankInAirValve}"> | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankInAirValve}" | |||
Tag="冷凝水进气阀"> | |||
<bpa:HandValve.RenderTransform> | |||
<RotateTransform Angle="90" /> | |||
</bpa:HandValve.RenderTransform> | |||
@@ -885,7 +885,8 @@ | |||
Canvas.Left="662" Canvas.Top="207" Canvas.Right="343.4" Width="16" | |||
Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
EdgeColor="{Binding DeviceStatus.HotGasEmptyValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.HotGasEmptyValve}" /> | |||
OpenEnable="{Binding DeviceStatus.HotGasEmptyValve}" | |||
Tag="热气排空阀" /> | |||
<TextBlock | |||
Canvas.Left="639" Canvas.Top="192" Canvas.Right="312.8" HorizontalAlignment="Left" | |||
VerticalAlignment="Center" FontSize="12" Foreground="White" Text="热气排空阀" | |||
@@ -913,7 +914,8 @@ | |||
Canvas.Left="635.883" Canvas.Top="288.036" Canvas.Right="380.8" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ReactOutHotGasValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactOutHotGasValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactOutHotGasValve}" | |||
Tag="抽真空阀" /> | |||
<!-- 之前抽真空阀叫排热空气阀,后面改了 --> | |||
<TextBlock | |||
Canvas.Left="618" Canvas.Top="272" Canvas.Right="384.8" HorizontalAlignment="Left" | |||
@@ -942,7 +944,8 @@ | |||
Canvas.Left="514" Canvas.Top="310" Canvas.Right="339" Width="16" | |||
Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
EdgeColor="{Binding DeviceStatus.ReactDrainValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactDrainValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactDrainValve}" | |||
Tag="反应釜排水阀" /> | |||
<TextBlock | |||
Canvas.Left="484" Canvas.Top="297" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
FontSize="12" Foreground="White" Text="反应釜排水阀" TextAlignment="Center" /> | |||
@@ -969,7 +972,8 @@ | |||
Canvas.Left="406" Canvas.Top="345" Canvas.Right="360" Width="16" | |||
Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
EdgeColor="{Binding DeviceStatus.ReactOutColdValve, ConverterParameter=6, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactOutColdValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactOutColdValve}" | |||
Tag="反应釜出冷却水阀" /> | |||
<TextBlock | |||
Canvas.Left="378" Canvas.Top="330" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
FontSize="12" Foreground="White" Text="冷却水、疏水" TextAlignment="Center" /> | |||
@@ -1003,7 +1007,8 @@ | |||
Canvas.Left="644" Canvas.Top="382" Canvas.Right="384" Width="16" | |||
Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" | |||
EdgeColor="{Binding DeviceStatus.ReactInCleanWaterValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactInCleanWaterValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactInCleanWaterValve}" | |||
Tag="反应釜进清水阀" /> | |||
<TextBlock | |||
Canvas.Left="628" Canvas.Top="362" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
FontSize="12" Foreground="White" Text="进清水阀" TextAlignment="Center" /> | |||
@@ -1054,7 +1059,8 @@ | |||
Canvas.Left="383.99" Canvas.Top="407.437" Canvas.Right="400" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ReactPressureAirInValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactPressureAirInValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactPressureAirInValve}" | |||
Tag="反应釜压缩空气进气阀" /> | |||
<TextBlock | |||
Canvas.Left="350" Canvas.Top="423" HorizontalAlignment="Left" VerticalAlignment="Top" | |||
FontSize="12" Foreground="White" Text="压缩空气进气阀" TextAlignment="Center" /> | |||
@@ -1139,12 +1145,13 @@ | |||
TextAlignment="Center" /> | |||
<TextBlock | |||
Canvas.Left="38" Canvas.Top="138" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
Foreground="White" Text="风机" /> | |||
Foreground="White" Text="真空泵" /> | |||
<bpa:HandValve | |||
Canvas.Left="121.876" Canvas.Top="61.412" Canvas.Right="343.4" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ColdWaterTankVacuumValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankVacuumValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankVacuumValve}" | |||
Tag="冷凝水罐真空阀" /> | |||
<TextBlock | |||
Canvas.Left="88" Canvas.Top="77" HorizontalAlignment="Left" VerticalAlignment="Top" | |||
FontSize="12" Foreground="White" Text="冷凝水管负压阀" TextAlignment="Center" /> | |||
@@ -1202,7 +1209,8 @@ | |||
Canvas.Left="234" Canvas.Top="175" Canvas.Right="343.4" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ColdWaterTankInWaterValve, ConverterParameter=6, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankInWaterValve}"> | |||
OpenEnable="{Binding DeviceStatus.ColdWaterTankInWaterValve}" | |||
Tag="冷凝水罐进水阀"> | |||
<bpa:HandValve.RenderTransform> | |||
<RotateTransform Angle="270" /> | |||
</bpa:HandValve.RenderTransform> | |||
@@ -1222,7 +1230,10 @@ | |||
Canvas.Left="590.8" Canvas.Top="430.945" Canvas.Right="253.9" Width="16" | |||
Height="16" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
EdgeColor="{Binding DeviceStatus.ReactInBrineWaterValve, ConverterParameter=2, Converter={StaticResource deviceConvert}}" | |||
OpenEnable="{Binding DeviceStatus.ReactInBrineWaterValve}" /> | |||
OpenEnable="{Binding DeviceStatus.ReactInBrineWaterValve}" | |||
Tag="反应釜进卤水阀"> | |||
</bpa:HandValve> | |||
<TextBlock | |||
Canvas.Left="85" Canvas.Top="410" HorizontalAlignment="Center" VerticalAlignment="Top" | |||
FontSize="12" Foreground="White" Text="卤水配制罐" /> | |||
@@ -1521,8 +1532,8 @@ | |||
Foreground="{Binding DeviceStatus.IsSetReactReverse, Converter={StaticResource BoolToColorConverter}}" | |||
Text="⬛" TextAlignment="Center" /> | |||
<TextBlock | |||
Canvas.Left="996" Canvas.Top="274" Canvas.Right="384.8" Height="20" | |||
HorizontalAlignment="Left" VerticalAlignment="Top" d:Foreground="Red" FontSize="16" | |||
Canvas.Left="996" Canvas.Top="264" Canvas.Right="384.8" Height="20" | |||
HorizontalAlignment="Center" VerticalAlignment="Top" d:Foreground="Red" FontSize="16" | |||
Foreground="{Binding DeviceStatus.IsSetReactTurnMotorJogging, Converter={StaticResource BoolToColorConverter}}" | |||
Text="⬛" TextAlignment="Center" /> | |||
<TextBlock | |||
@@ -40,16 +40,18 @@ namespace BPASmartClient.Academy.View | |||
if (PlcControl.GetInstance.IsConnect) | |||
{ | |||
var tag = button.Tag.ToString().Trim(); | |||
BoolAddEnum addr=(BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag); | |||
var result= PlcControl.GetInstance.Write(addr, true); | |||
if (result !=null && result.IsSuccess) | |||
{ | |||
Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:True"); | |||
} | |||
else | |||
{ | |||
Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:True\n{result.Message}"); | |||
} | |||
//BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag); | |||
//var result = PlcControl.GetInstance.Write(addr, true); | |||
//if (result != null && result.IsSuccess) | |||
//{ | |||
// Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:True"); | |||
//} | |||
//else | |||
//{ | |||
// Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:True\n{result.Message}"); | |||
//} | |||
WriteBooleanAddr(tag,true); | |||
} | |||
else | |||
{ | |||
@@ -65,16 +67,17 @@ namespace BPASmartClient.Academy.View | |||
if (PlcControl.GetInstance.IsConnect) | |||
{ | |||
var tag = button.Tag.ToString().Trim(); | |||
BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag); | |||
var result = PlcControl.GetInstance.Write(addr, false); | |||
if (result != null && result.IsSuccess) | |||
{ | |||
Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:False"); | |||
} | |||
else | |||
{ | |||
Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:False\n{result.Message}"); | |||
} | |||
//BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag); | |||
//var result = PlcControl.GetInstance.Write(addr, false); | |||
//if (result != null && result.IsSuccess) | |||
//{ | |||
// Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:False"); | |||
//} | |||
//else | |||
//{ | |||
// Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:False\n{result.Message}"); | |||
//} | |||
WriteBooleanAddr(tag, false); | |||
} | |||
else | |||
{ | |||
@@ -265,5 +268,78 @@ namespace BPASmartClient.Academy.View | |||
Notify(EnumPromptType.Error, "写入失败", "设备未连接"); | |||
} | |||
} | |||
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e) | |||
{ | |||
if (e.Source is HandValve valve) | |||
{ | |||
if (PlcControl.GetInstance.IsConnect && valve.Tag != null && !string.IsNullOrWhiteSpace(valve.Tag.ToString().Trim())) | |||
{ | |||
var tag = valve.Tag.ToString().Trim(); | |||
BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag); | |||
DeviceControlView.Show(tag, "未知", valve.OpenEnable ? "打开" : "关闭", new Action(() => | |||
{ | |||
var result = PlcControl.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 = PlcControl.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, "失败", "设备未连接,不可进行控制。"); | |||
} | |||
} | |||
} | |||
private void WriteBooleanAddr(string tagName,bool value) | |||
{ | |||
BoolAddEnum addr = BoolAddEnum.反应釜旋转电机; | |||
try | |||
{ | |||
addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tagName); | |||
} | |||
catch (Exception) | |||
{ | |||
Notify(EnumPromptType.Error, "失败", $"未找到该地址[{tagName}]。"); | |||
return; | |||
} | |||
var result = PlcControl.GetInstance.Write(addr, value); | |||
if (result != null && result.IsSuccess) | |||
{ | |||
Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tagName}:{value}"); | |||
} | |||
else | |||
{ | |||
Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tagName}:{value}\n{result.Message}"); | |||
} | |||
} | |||
private void Button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) | |||
{ | |||
open_Click(sender,e); | |||
} | |||
private void Button_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) | |||
{ | |||
close_Click(sender,e); | |||
} | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.Academy.ViewModel | |||
{ | |||
public class DeviceControlViewModel:NotifyBase | |||
{ | |||
public DeviceControlViewModel() | |||
{ | |||
} | |||
} | |||
} |