From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
Plugin.DeviceDebug/Panels/PlcDebugPanel.xaml.cs | 197 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 197 insertions(+), 0 deletions(-)
diff --git a/Plugin.DeviceDebug/Panels/PlcDebugPanel.xaml.cs b/Plugin.DeviceDebug/Panels/PlcDebugPanel.xaml.cs
new file mode 100644
index 0000000..00b58b0
--- /dev/null
+++ b/Plugin.DeviceDebug/Panels/PlcDebugPanel.xaml.cs
@@ -0,0 +1,197 @@
+using log4net;
+using Plugin.DeviceDebug.Entity;
+using System;
+using System.Collections.ObjectModel;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace Plugin.DeviceDebug.Panels
+{
+ /// <summary>
+ /// IO 鐐逛綅鐘舵�佹樉绀烘ā鍨�
+ /// </summary>
+ public class IoPointStatus
+ {
+ public string Address { get; set; }
+ public bool Value { get; set; }
+ public DateTime LastUpdate { get; set; }
+ }
+
+ /// <summary>
+ /// 浜掗攣鐘舵�佹樉绀烘ā鍨�
+ /// </summary>
+ public class InterlockStatus
+ {
+ public string Name { get; set; }
+ public string Status { get; set; } // "婊¤冻" / "涓嶆弧瓒�"
+ }
+
+ /// <summary>
+ /// PlcDebugPanel.xaml 鐨勪氦浜掗�昏緫
+ /// </summary>
+ public partial class PlcDebugPanel : UserControl
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(PlcDebugPanel));
+
+ /// <summary>
+ /// 鏄惁涓虹淮鎶ゆā寮忥紙鎺у埗杈撳叆鍙敤鎬э級
+ /// </summary>
+ public static readonly DependencyProperty IsMaintenanceModeProperty =
+ DependencyProperty.Register(nameof(IsMaintenanceMode), typeof(bool), typeof(PlcDebugPanel),
+ new PropertyMetadata(false));
+
+ public bool IsMaintenanceMode
+ {
+ get => (bool)GetValue(IsMaintenanceModeProperty);
+ set => SetValue(IsMaintenanceModeProperty, value);
+ }
+
+ /// <summary>
+ /// 鍛戒护鎵ц浜嬩欢
+ /// </summary>
+ public event EventHandler<DebugCommand> OnCommandExecute;
+
+ /// <summary>
+ /// IO 鐐逛綅鐘舵�佸垪琛�
+ /// </summary>
+ public ObservableCollection<IoPointStatus> IoStatuses { get; } = new();
+
+ /// <summary>
+ /// 浜掗攣鐘舵�佸垪琛�
+ /// </summary>
+ public ObservableCollection<InterlockStatus> Interlocks { get; } = new();
+
+ public PlcDebugPanel()
+ {
+ InitializeComponent();
+ ioStatusList.ItemsSource = IoStatuses;
+ interlockList.ItemsSource = Interlocks;
+
+ // 鍒濆鍖栫ず渚嬫暟鎹�
+ InitSampleData();
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栫ず渚嬫暟鎹紙瀹為檯搴斾粠 PLC 璇诲彇锛�
+ /// </summary>
+ private void InitSampleData()
+ {
+ try
+ {
+ // 娣诲姞绀轰緥 IO 鐐逛綅
+ IoStatuses.Add(new IoPointStatus { Address = "M0.0", Value = false, LastUpdate = DateTime.Now });
+ IoStatuses.Add(new IoPointStatus { Address = "M0.1", Value = true, LastUpdate = DateTime.Now });
+ IoStatuses.Add(new IoPointStatus { Address = "M0.2", Value = false, LastUpdate = DateTime.Now });
+ IoStatuses.Add(new IoPointStatus { Address = "I0.0", Value = true, LastUpdate = DateTime.Now });
+ IoStatuses.Add(new IoPointStatus { Address = "Q0.0", Value = false, LastUpdate = DateTime.Now });
+
+ // 娣诲姞绀轰緥浜掗攣
+ Interlocks.Add(new InterlockStatus { Name = "瀹夊叏闂ㄥ叧闂�", Status = "婊¤冻" });
+ Interlocks.Add(new InterlockStatus { Name = "鎬ュ仠鏈Е鍙�", Status = "婊¤冻" });
+ Interlocks.Add(new InterlockStatus { Name = "姘斿帇姝e父", Status = "涓嶆弧瓒�" });
+ Interlocks.Add(new InterlockStatus { Name = "娓╁害姝e父", Status = "婊¤冻" });
+ }
+ catch (Exception ex)
+ {
+ log.Error("鍒濆鍖栫ず渚嬫暟鎹け璐�", ex);
+ }
+ }
+
+ /// <summary>
+ /// 鏇存柊 IO 鐐逛綅鐘舵��
+ /// </summary>
+ public void UpdateIoStatus(string address, bool value)
+ {
+ try
+ {
+ var existing = IoStatuses.FirstOrDefault(s => s.Address == address);
+ if (existing != null)
+ {
+ existing.Value = value;
+ existing.LastUpdate = DateTime.Now;
+ }
+ else
+ {
+ IoStatuses.Add(new IoPointStatus
+ {
+ Address = address,
+ Value = value,
+ LastUpdate = DateTime.Now
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ log.Error($"鏇存柊 IO 鐘舵�佸け璐�: {address}", ex);
+ }
+ }
+
+ /// <summary>
+ /// 鏇存柊浜掗攣鐘舵��
+ /// </summary>
+ public void UpdateInterlock(string name, bool satisfied)
+ {
+ try
+ {
+ var existing = Interlocks.FirstOrDefault(i => i.Name == name);
+ if (existing != null)
+ {
+ existing.Status = satisfied ? "婊¤冻" : "涓嶆弧瓒�";
+ }
+ else
+ {
+ Interlocks.Add(new InterlockStatus
+ {
+ Name = name,
+ Status = satisfied ? "婊¤冻" : "涓嶆弧瓒�"
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ log.Error($"鏇存柊浜掗攣鐘舵�佸け璐�: {name}", ex);
+ }
+ }
+
+ private void WriteBtn_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ if (!IsMaintenanceMode)
+ {
+ MessageBox.Show("褰撳墠涓哄彧璇绘ā寮忥紝鏃犳硶鎵ц鍐欏叆鎿嶄綔", "鎻愮ず", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ string address = addressInput.Text.Trim();
+ if (string.IsNullOrEmpty(address))
+ {
+ MessageBox.Show("璇疯緭鍏� IO 鍦板潃", "閿欒", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
+
+ bool value = (valueSelect.SelectedItem as ComboBoxItem)?.Content?.ToString() == "True";
+
+ // 鍒涘缓鍛戒护
+ var command = new PlcWriteCommand
+ {
+ IoAddress = address,
+ Value = value
+ };
+
+ // 瑙﹀彂鍛戒护鎵ц浜嬩欢
+ OnCommandExecute?.Invoke(this, command);
+
+ // 鏇存柊鏈湴鏄剧ず
+ UpdateIoStatus(address, value);
+
+ log.Info($"鍐欏叆 PLC IO: {address} = {value}");
+ }
+ catch (Exception ex)
+ {
+ log.Error("鍐欏叆 PLC IO 澶辫触", ex);
+ MessageBox.Show($"鍐欏叆澶辫触: {ex.Message}", "閿欒", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+}
--
Gitblit v1.9.1