@@ -0,0 +1,23 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace HBLConsole.Attributes | |||
{ | |||
public class VariableMonitorAttribute : Attribute | |||
{ | |||
public VariableMonitorAttribute(string Notes, string PLCAddress = "", string ModbusTcpAddress = "") | |||
{ | |||
this.PLCAddress = PLCAddress; | |||
this.ModbusTcpAddress = ModbusTcpAddress; | |||
this.Notes = Notes; | |||
} | |||
public string PLCAddress { get; set; } | |||
public string ModbusTcpAddress { get; set; } | |||
public string Notes { get; set; } | |||
} | |||
} |
@@ -134,6 +134,7 @@ namespace HBLConsole.MORKD | |||
/// ModbusTcp --> 1120 | |||
/// </summary> | |||
[Circuit(new string[] { "允许运行", "转台控制" }, "初始化完成")] | |||
[VariableMonitor("初始化完成", "M100.0", "1120")] | |||
public bool InitComplete { get; set; } | |||
/// <summary> | |||
@@ -142,6 +143,7 @@ namespace HBLConsole.MORKD | |||
/// ModbusTcp --> 1121 | |||
/// </summary> | |||
[Circuit("取面任务", "转台到位检测")] | |||
[VariableMonitor("转台到位", "M100.1", "1121")] | |||
public bool TurntableInPlace { get; set; } | |||
/// <summary> | |||
@@ -149,6 +151,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M100.2 | |||
/// ModbusTcp --> 1122 | |||
/// </summary> | |||
[VariableMonitor("机器人取面完成", "M100.2", "1122")] | |||
public bool RBTakeNoodleComplete { get; set; } | |||
/// <summary> | |||
@@ -156,6 +159,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M100.3 -- M100.04 | |||
/// ModbusTcp --> 1123 -- 1124 | |||
/// </summary> | |||
[VariableMonitor("轴空闲", "M100.3", "1123")] | |||
public bool[] AxisIdle { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -163,6 +167,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M100.5 -- M100.06 | |||
/// ModbusTcp --> 1125 -- 1126 | |||
/// </summary> | |||
[VariableMonitor("轴允许倒面", "M100.5", "1125")] | |||
public bool[] AxisAllowInvertedNoodle { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -170,6 +175,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M100.7 -- M101.00 | |||
/// ModbusTcp --> 1127 -- 1128 | |||
/// </summary> | |||
[VariableMonitor("轴允许倒浇头", "M100.7", "1127")] | |||
public bool[] AxisAllowInvertedSoup { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -177,6 +183,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M101.1 -- M101.02 | |||
/// ModbusTcp --> 1129 -- 1130 | |||
/// </summary> | |||
[VariableMonitor("浇头加热完成", "M101.1", "1129")] | |||
public bool[] SoupHeatComplete { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -184,6 +191,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M101.3 -- M102.0 | |||
/// ModbusTcp --> 1131 -- 1136 | |||
/// </summary> | |||
[VariableMonitor("煮面篮空闲", "M101.3", "1131")] | |||
public bool[] CookNoodleBasketIdle { get; set; } = new bool[6] { false, false, false, false, false, false }; | |||
/// <summary> | |||
@@ -191,6 +199,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M102.1 -- M102.6 | |||
/// ModbusTcp --> 1137 -- 1142 | |||
/// </summary> | |||
[VariableMonitor("煮面完成", "M102.1", "1137")] | |||
public bool[] CookNoodleComplete { get; set; } = new bool[6] { false, false, false, false, false, false }; | |||
/// <summary> | |||
@@ -199,6 +208,7 @@ namespace HBLConsole.MORKD | |||
/// ModbusTcp --> 1143 | |||
/// </summary> | |||
[Circuit(new string[] { "取面任务", "出餐控制" }, "取面机器人空闲")] | |||
[VariableMonitor("取面机器人空闲状态", "M102.7", "1143")] | |||
public bool TakeNoodleRobotIdle { get; set; } | |||
/// <summary> | |||
@@ -207,6 +217,7 @@ namespace HBLConsole.MORKD | |||
/// ModbusTcp --> 1144 | |||
/// </summary> | |||
[Circuit(new string[] { "取浇头控制", "出浇头控制" }, "取浇头机器人空闲状态")] | |||
[VariableMonitor("取浇头机器人空闲状态", "M103.0", "1144")] | |||
public bool TakeSoupRobotIdle { get; set; } | |||
/// <summary> | |||
@@ -214,6 +225,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M103.1 -- M103.02 | |||
/// ModbusTcp --> 1145 -- 1146 | |||
/// </summary> | |||
[VariableMonitor("破口机构空闲", "M103.1", "1145")] | |||
public bool[] BreakMechanismIdle { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -221,6 +233,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M103.3 | |||
/// ModbusTcp --> 1147 | |||
/// </summary> | |||
[VariableMonitor("取浇头完成", "M103.3", "1147")] | |||
public bool TakeSoupComplete { get; set; } | |||
/// <summary> | |||
@@ -228,6 +241,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M103.4 | |||
/// ModbusTcp --> 1148 | |||
/// </summary> | |||
[VariableMonitor("放面至取餐口完成", "M103.4", "1148")] | |||
public bool PutNoodleTakeMealComplete { get; set; } | |||
/// <summary> | |||
@@ -235,6 +249,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M103.5 | |||
/// ModbusTcp --> 1149 | |||
/// </summary> | |||
[VariableMonitor("设备初始化中", "M103.5", "1149")] | |||
public bool Initing { get; set; } | |||
/// <summary> | |||
@@ -242,6 +257,7 @@ namespace HBLConsole.MORKD | |||
/// PLC -> VW372 | |||
/// ModbusTcp -> 286 | |||
/// </summary> | |||
[VariableMonitor("设备初始化中", "VW372", "286")] | |||
public ushort TurntableFeedbackloc { get; set; } | |||
#endregion | |||
@@ -251,6 +267,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M120.0 | |||
/// ModbusTcp --> 1200 | |||
/// </summary> | |||
[VariableMonitor("转台下限位", "M120.0", "1200")] | |||
public bool TurntableLowerLimit { get; set; } | |||
/// <summary> | |||
@@ -258,6 +275,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M120.1 | |||
/// ModbusTcp --> 1201 | |||
/// </summary> | |||
[VariableMonitor("转台上限位", "M120.1", "1201")] | |||
public bool TurntableUpLimit { get; set; } | |||
/// <summary> | |||
@@ -265,6 +283,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M120.2 -- M120.6 | |||
/// ModbusTcp --> 1202 -- 1206 | |||
/// </summary> | |||
[VariableMonitor("浇头缺料", "M120.2", "1202")] | |||
public bool[] SoupMaterialShortage { get; set; } = new bool[5] { false, false, false, false, false }; | |||
/// <summary> | |||
@@ -272,6 +291,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M120.7 -- M121.1 | |||
/// ModbusTcp --> 1207 -- 1209 | |||
/// </summary> | |||
[VariableMonitor("出餐口检测", "M120.7", "1207")] | |||
public bool[] OutMealDetect { get; set; } = new bool[3] { false, false, false }; | |||
/// <summary> | |||
@@ -279,6 +299,7 @@ namespace HBLConsole.MORKD | |||
/// PLC --> M121.2 | |||
/// ModbusTcp --> 1210 | |||
/// </summary> | |||
[VariableMonitor("温度到达", "M121.2", "1210")] | |||
public bool TemperatureReached { get; set; } | |||
#endregion | |||
@@ -288,71 +309,84 @@ namespace HBLConsole.MORKD | |||
/// 允许倒浇头 | |||
/// </summary> | |||
[Circuit(new string[] { "出浇头控制" }, "允许倒浇头", new bool[] { true })] | |||
[VariableMonitor("允许倒浇头")] | |||
public bool AllowPutSoup { get; set; } | |||
/// <summary> | |||
/// 允许取浇头 | |||
/// </summary> | |||
[Circuit(new string[] { "取浇头控制", "出浇头控制" }, "允许取浇头", new bool[] { true, true })] | |||
[VariableMonitor("允许取浇头")] | |||
public bool AllowTakeSoup { get; set; } | |||
/// <summary> | |||
/// 放面位置 | |||
/// </summary> | |||
[VariableMonitor("放面位置")] | |||
public int PutNoodleLoc { get; set; } | |||
/// <summary> | |||
/// 轴空闲位置 | |||
/// </summary> | |||
[VariableMonitor("轴空闲位置")] | |||
public int AxisIdleIndex { get; set; } | |||
/// <summary> | |||
/// 轴空闲互锁位置 | |||
/// </summary> | |||
[VariableMonitor("轴空闲互锁位置")] | |||
public int AxisIdleLockIndex { get; set; } | |||
/// <summary> | |||
/// 转台位置 | |||
/// </summary> | |||
[VariableMonitor("转台位置")] | |||
public ushort TurntableLoc { get; set; } | |||
/// <summary> | |||
/// 机器人任务互锁信号 | |||
/// </summary> | |||
[Circuit(new string[] { "取面任务", "出餐控制" }, "机器人任务互锁", new bool[] { true, false })] | |||
[VariableMonitor("机器人任务互锁信号")] | |||
public bool RobotTaskInterlock { get; set; } | |||
/// <summary> | |||
/// 取碗互锁信号 | |||
/// </summary> | |||
[VariableMonitor("取碗互锁信号")] | |||
public bool TakeBowlInterlock { get; set; } | |||
/// <summary> | |||
/// 取面互锁信号 | |||
/// </summary> | |||
[Circuit(new string[] { "出餐控制" }, "取面互锁信号", new bool[] { true })] | |||
[VariableMonitor("取面互锁信号")] | |||
public bool TakeNoodleInterlock { get; set; } | |||
/// <summary> | |||
/// 出面中 | |||
/// </summary> | |||
[Circuit(new string[] { "取面任务" }, "出面中", new bool[] { true })] | |||
[VariableMonitor("出面中")] | |||
public bool OutNoodleing { get; set; } | |||
/// <summary> | |||
/// 允许取面 | |||
/// </summary> | |||
[Circuit(new string[] { "转台控制", "取面任务" }, "允许取面", new bool[] { true, false })] | |||
[VariableMonitor("允许取面")] | |||
public bool AllowTakeNoodle { get; set; } | |||
/// <summary> | |||
/// 转台互锁信号 | |||
/// </summary> | |||
[Circuit(new string[] { "转台控制" }, "转台互锁信号", new bool[] { true })] | |||
[VariableMonitor("转台互锁信号")] | |||
public bool TurntableInterlock { get; set; } | |||
/// <summary> | |||
/// 轴空闲互锁 | |||
/// </summary> | |||
[VariableMonitor("轴空闲互锁")] | |||
public bool[] AxisIdleLock { get; set; } = new bool[2] { false, false }; | |||
/// <summary> | |||
@@ -364,6 +398,7 @@ namespace HBLConsole.MORKD | |||
/// 允许运行 | |||
/// </summary> | |||
[Circuit(new string[] { "取面任务", "取浇头控制" }, "允许运行")] | |||
[VariableMonitor("允许运行")] | |||
public bool AllowRun { get; set; } | |||
/// <summary> | |||
@@ -0,0 +1,38 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
namespace HBLConsole.Model | |||
{ | |||
public class VariableMonitor : ObservableObject | |||
{ | |||
public int Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } } | |||
private int _mId; | |||
public string VarName { get { return _mVarName; } set { _mVarName = value; OnPropertyChanged(); } } | |||
private string _mVarName; | |||
public string PLCAddress { get { return _mPLCAddress; } set { _mPLCAddress = value; OnPropertyChanged(); } } | |||
private string _mPLCAddress; | |||
public string Notes { get { return _mNotes; } set { _mNotes = value; OnPropertyChanged(); } } | |||
private string _mNotes; | |||
public string ModbusTcpAddress { get { return _mModbusTcpAddress; } set { _mModbusTcpAddress = value; OnPropertyChanged(); } } | |||
private string _mModbusTcpAddress; | |||
public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } } | |||
private string _mCurrentValue; | |||
} | |||
} |
@@ -43,14 +43,11 @@ namespace HBLConsole | |||
/// </summary> | |||
private void NoCompleteOrderInit() | |||
{ | |||
//if (Json<KeepDataBase>.Data.orderLists.ContainsKey(GeneralConfig.DeviceType.ToString())) | |||
//{ | |||
if (Json<KeepDataBase>.Data.orderLists.Count > 0) | |||
{ | |||
listDialogView = new ListDialogView(); | |||
listDialogView.ShowDialog(); | |||
} | |||
//} | |||
} | |||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) | |||
@@ -13,7 +13,7 @@ | |||
Height="850" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="False" | |||
Topmost="True" | |||
WindowStartupLocation="CenterScreen" | |||
WindowStyle="None" | |||
mc:Ignorable="d"> | |||
@@ -297,6 +297,13 @@ | |||
Content="变量管理" | |||
Style="{StaticResource ParallelogramRadioButtonStyle}" /> | |||
<RadioButton | |||
Margin="-10,0,0,0" | |||
Command="{Binding NavChangedCommand}" | |||
CommandParameter="VariableMonitorView" | |||
Content="变量监控" | |||
Style="{StaticResource ParallelogramRadioButtonStyle}" /> | |||
<RadioButton | |||
Margin="-10,0,0,0" | |||
@@ -0,0 +1,249 @@ | |||
<UserControl | |||
x:Class="HBLConsole.View.VariableMonitorView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:convert="clr-namespace:HBLConsole.Converter" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:local="clr-namespace:HBLConsole.View" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:pry="clr-namespace:HBLConsole.PryUserControl;assembly=HBLConsole.PryUserControl" | |||
xmlns:vm="clr-namespace:HBLConsole.ViewModel" | |||
d:DesignHeight="450" | |||
d:DesignWidth="1000" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<vm:VariableMonitorViewModel /> | |||
</UserControl.DataContext> | |||
<UserControl.Resources> | |||
<ResourceDictionary Source="../Resources/ResourceDictionarys/BasicStyle.xaml"> | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary> | |||
<convert:TextDisplayConvert x:Key="textDisplayConvert" /> | |||
<convert:IsEnableConvert x:Key="isEnableConvert" /> | |||
<convert:AnalogAlarmConvert x:Key="analogAlarmConvert" /> | |||
<convert:DiscreteAlarmConvert x:Key="discreteAlarmConvert" /> | |||
<convert:AlarmTypeTextConvert x:Key="alarmTypeTextConvert" /> | |||
<SolidColorBrush x:Key="BorderSolid" Color="#5523CACA" /> | |||
<SolidColorBrush x:Key="FontColor" Color="#FF2AB2E7" /> | |||
<SolidColorBrush x:Key="TitleFontColor" Color="#ddd" /> | |||
<SolidColorBrush x:Key="CursorColor" Color="Aqua" /> | |||
<SolidColorBrush x:Key="TitleBorderColor" Color="#FF2AB2E7" /> | |||
<Style x:Key="TextBlockStyle" TargetType="TextBlock"> | |||
<Setter Property="FontFamily" Value="楷体" /> | |||
<Setter Property="FontSize" Value="18" /> | |||
<Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" /> | |||
<Setter Property="VerticalAlignment" Value="Center" /> | |||
<Setter Property="HorizontalAlignment" Value="Center" /> | |||
</Style> | |||
<Style x:Key="TextBoxStyle" TargetType="TextBox"> | |||
<Setter Property="FontFamily" Value="楷体" /> | |||
<Setter Property="FontSize" Value="22" /> | |||
<Setter Property="Background" Value="Transparent" /> | |||
<Setter Property="Foreground" Value="{StaticResource TextBlockForeground}" /> | |||
<Setter Property="BorderBrush" Value="#FF23CACA" /> | |||
<Setter Property="CaretBrush" Value="Aqua" /> | |||
<Setter Property="VerticalAlignment" Value="Center" /> | |||
</Style> | |||
</ResourceDictionary> | |||
</ResourceDictionary.MergedDictionaries> | |||
</ResourceDictionary> | |||
</UserControl.Resources> | |||
<Grid Margin="10"> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="30" /> | |||
<RowDefinition Height="30" /> | |||
<RowDefinition /> | |||
</Grid.RowDefinitions> | |||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> | |||
<!--<Button | |||
Margin="20,0,20,0" | |||
Command="{Binding GenerateData}" | |||
Content="添加数据" /> | |||
<Button | |||
Margin="20,0,20,0" | |||
Command="{Binding SaveData}" | |||
Content="保存数据" />--> | |||
</StackPanel> | |||
<!--#region 表格标题栏设置--> | |||
<Grid Grid.Row="1" Background="#dd2AB2E7"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="0.3*" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<!--<ColumnDefinition Width="0.5*" />--> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="ID" /> | |||
<Grid Grid.Column="1"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="变量名" /> | |||
<Border | |||
BorderBrush="{StaticResource TitleBorderColor}" | |||
BorderThickness="1,0,1,0" | |||
Cursor="SizeWE" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="2" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="PLC 地址" /> | |||
<Grid Grid.Column="3"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="注释" /> | |||
<Border | |||
BorderBrush="{StaticResource TitleBorderColor}" | |||
BorderThickness="1,0,0,0" | |||
Cursor="SizeWE" /> | |||
</Grid> | |||
<Grid Grid.Column="4"> | |||
<TextBlock | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="Modbus TCP 地址" /> | |||
<Border | |||
BorderBrush="{StaticResource TitleBorderColor}" | |||
BorderThickness="1,0,1,0" | |||
Cursor="SizeWE" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="5" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
FontSize="16" | |||
Foreground="{StaticResource TitleFontColor}" | |||
Text="当前值" /> | |||
</Grid> | |||
<!--#endregion--> | |||
<!--#region 表格数据显示--> | |||
<ScrollViewer | |||
Grid.Row="2" | |||
HorizontalScrollBarVisibility="Hidden" | |||
VerticalScrollBarVisibility="Hidden"> | |||
<ItemsControl ItemsSource="{Binding VariableMonitors}"> | |||
<ItemsControl.ItemTemplate> | |||
<DataTemplate> | |||
<Grid x:Name="gr" Height="30"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="0.3*" /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<ColumnDefinition Width="0.7*" /> | |||
<!--<ColumnDefinition Width="0.5*" />--> | |||
</Grid.ColumnDefinitions> | |||
<TextBlock | |||
Grid.Column="0" | |||
HorizontalAlignment="Center" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding Id}" /> | |||
<Grid Grid.Column="1"> | |||
<TextBlock | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding VarName}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="2" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding PLCAddress}" /> | |||
<Grid Grid.Column="3"> | |||
<TextBlock | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding Notes}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,0,0" /> | |||
</Grid> | |||
<Grid Grid.Column="4"> | |||
<TextBlock | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding ModbusTcpAddress}" /> | |||
<Border BorderBrush="{StaticResource BorderSolid}" BorderThickness="1,0,1,0" /> | |||
</Grid> | |||
<TextBlock | |||
Grid.Column="5" | |||
VerticalAlignment="Center" | |||
Background="Transparent" | |||
FontSize="14" | |||
Foreground="{StaticResource FontColor}" | |||
Text="{Binding CurrentValue}" /> | |||
<Border | |||
Grid.ColumnSpan="8" | |||
BorderBrush="{StaticResource BorderSolid}" | |||
BorderThickness="1" /> | |||
</Grid> | |||
<DataTemplate.Triggers> | |||
<Trigger Property="IsMouseOver" Value="true"> | |||
<Setter TargetName="gr" Property="Background" Value="#112AB2E7" /> | |||
</Trigger> | |||
</DataTemplate.Triggers> | |||
</DataTemplate> | |||
</ItemsControl.ItemTemplate> | |||
</ItemsControl> | |||
</ScrollViewer> | |||
<!--#endregion--> | |||
</Grid> | |||
</UserControl> |
@@ -0,0 +1,28 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
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 HBLConsole.View | |||
{ | |||
/// <summary> | |||
/// VariableMonitorView.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class VariableMonitorView : UserControl | |||
{ | |||
public VariableMonitorView() | |||
{ | |||
InitializeComponent(); | |||
} | |||
} | |||
} |
@@ -17,36 +17,15 @@ namespace HBLConsole.ViewModel | |||
{ | |||
public class ProcessMonitoringViewModel : ViewModelBase | |||
{ | |||
//static Type type; | |||
//static IGvl InterfaceGVL; | |||
public ProcessMonitoringViewModel() | |||
{ | |||
WindowName = "流程监控"; | |||
//if (type == null) | |||
//{ | |||
// InterfaceGVL = SimpleFactory.GetInstance.GVL; | |||
// type = InterfaceGVL?.GetType(); | |||
// if (ProcessData.GetInstance.Conditions?.Count <= 0) | |||
// { | |||
// if (InterfaceGVL != null && type != null) | |||
// { | |||
// GetProcessInfo(); | |||
// UpdateProcess(); | |||
// } | |||
// } | |||
//} | |||
} | |||
static ProcessMonitoringViewModel() | |||
{ | |||
//InterfaceGVL = SimpleFactory.GetInstance.GVL; | |||
//type = InterfaceGVL?.GetType(); | |||
GetProcessInfo(); | |||
UpdateProcess(); | |||
} | |||
/// <summary> | |||
@@ -54,6 +33,7 @@ namespace HBLConsole.ViewModel | |||
/// </summary> | |||
private static void GetProcessInfo() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
//添加流程监控信息 | |||
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) | |||
{ | |||
@@ -102,6 +82,7 @@ namespace HBLConsole.ViewModel | |||
/// </summary> | |||
private static void UpdateProcess() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
ThreadOperate.GetInstance.StartLong(new Action(() => | |||
{ | |||
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) | |||
@@ -0,0 +1,142 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Collections.ObjectModel; | |||
using HBLConsole.Model; | |||
using HBLConsole.Factory; | |||
using HBLConsole.Attributes; | |||
using System.Reflection; | |||
namespace HBLConsole.ViewModel | |||
{ | |||
public class VariableMonitorViewModel : ViewModelBase | |||
{ | |||
public VariableMonitorViewModel() | |||
{ | |||
WindowName = "变量监控"; | |||
} | |||
static VariableMonitorViewModel() | |||
{ | |||
AddMonitorData(); | |||
UpdateValue(); | |||
} | |||
private static void AddMonitorData() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) | |||
{ | |||
if (item.CustomAttributes.Count() > 0) | |||
{ | |||
var plcadd = item.GetCustomAttribute<VariableMonitorAttribute>()?.PLCAddress; | |||
var modadd = item.GetCustomAttribute<VariableMonitorAttribute>()?.ModbusTcpAddress; | |||
var notes = item.GetCustomAttribute<VariableMonitorAttribute>()?.Notes; | |||
if (item.PropertyType?.BaseType?.Name == "Array" && plcadd?.Length > 0) | |||
{ | |||
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL, null); | |||
if (arrayRes != null && arrayRes is Array arr) | |||
{ | |||
for (int i = 0; i < arr.Length; i++) | |||
{ | |||
var res = VariableMonitors.FirstOrDefault(p => p.VarName == $"{item.Name}_{i + 1}"); | |||
if (res == null) | |||
{ | |||
string[] plc = plcadd?.Substring(1).Split('.'); | |||
string TempPlcAddress = string.Empty; | |||
if (plc?.Length == 2) | |||
{ | |||
int add = int.Parse(plc[1]); | |||
int firstAdd = int.Parse(plc[0]); | |||
if (add >= 0 && add < 7) | |||
{ | |||
add += i; | |||
} | |||
else if (add >= 7) | |||
{ | |||
add = 0; | |||
firstAdd++; | |||
} | |||
plc[0] = firstAdd.ToString(); | |||
plc[1] = add.ToString(); | |||
TempPlcAddress = $"M{plc[0]}.{plc[1]}"; | |||
} | |||
VariableMonitors.Add(new VariableMonitor() | |||
{ | |||
Id = VariableMonitors.Count, | |||
VarName = $"{item.Name}_{i + 1}", | |||
Notes = $"{notes}_{i + 1}", | |||
ModbusTcpAddress = $"{int.Parse(modadd) + i}", | |||
PLCAddress = TempPlcAddress, | |||
}); | |||
} | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
var res = VariableMonitors.FirstOrDefault(p => p.VarName == item.Name); | |||
if (res == null) | |||
{ | |||
VariableMonitors.Add(new VariableMonitor() | |||
{ | |||
Id = VariableMonitors.Count, | |||
VarName = item.Name, | |||
Notes = notes, | |||
ModbusTcpAddress = modadd, | |||
PLCAddress = plcadd, | |||
}); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
private static void UpdateValue() | |||
{ | |||
if (SimpleFactory.GetInstance.GVL == null) return; | |||
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) | |||
{ | |||
if (item.CustomAttributes.Count() > 0) | |||
{ | |||
if (item.PropertyType?.BaseType?.Name == "Array") | |||
{ | |||
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL); | |||
if (arrayRes != null && arrayRes is Array arr) | |||
{ | |||
for (int i = 0; i < arr.Length; i++) | |||
{ | |||
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == $"{item.Name}_{i + 1}"); | |||
if (index >= 0 && index < VariableMonitors.Count) | |||
{ | |||
VariableMonitors.ElementAt(index).CurrentValue = arr.GetValue(i)?.ToString(); | |||
} | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == item.Name); | |||
if (index >= 0 && index < VariableMonitors.Count) | |||
{ | |||
VariableMonitors.ElementAt(index).CurrentValue = item.GetValue(SimpleFactory.GetInstance.GVL)?.ToString(); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
public static ObservableCollection<VariableMonitor> VariableMonitors { get; set; } = new ObservableCollection<VariableMonitor>(); | |||
} | |||
} |