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 作为历史根节点

---
 Util.ManualDebug/OldManualDebug.xaml.cs |  368 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 368 insertions(+), 0 deletions(-)

diff --git a/Util.ManualDebug/OldManualDebug.xaml.cs b/Util.ManualDebug/OldManualDebug.xaml.cs
new file mode 100644
index 0000000..2fc4f5c
--- /dev/null
+++ b/Util.ManualDebug/OldManualDebug.xaml.cs
@@ -0,0 +1,368 @@
+using Plugin.TsSupport;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Media;
+
+namespace Util.ManualDebug
+{
+    public partial class OldManualDebug : UserControl
+    {
+        public static readonly DependencyProperty OvenNameProperty = DependencyProperty.Register(
+                            "OvenName",
+                            typeof(string),
+                            typeof(OldManualDebug),
+                            new PropertyMetadata(""));
+
+        public static readonly DependencyProperty CellNameProperty = DependencyProperty.Register(
+                            "CellName",
+                            typeof(string),
+                            typeof(OldManualDebug),
+                            new PropertyMetadata(""));
+
+        public static readonly DependencyProperty OvenIndexProperty = DependencyProperty.Register(
+                            "OvenIndex",
+                            typeof(int),
+                            typeof(OldManualDebug),
+                            new PropertyMetadata(0));
+
+        public static readonly DependencyProperty CellIndexProperty = DependencyProperty.Register(
+                            "CellIndex",
+                            typeof(int),
+                            typeof(OldManualDebug),
+                            new PropertyMetadata(0));
+
+        public string OvenName
+        {
+            get { return (string)GetValue(OvenNameProperty); }
+            set
+            {
+                SetValue(OvenNameProperty, value);
+            }
+        }
+
+        public string CellName
+        {
+            get { return (string)GetValue(CellNameProperty); }
+            set { SetValue(CellNameProperty, value); }
+        }
+
+        public int OvenIndex
+        {
+            get { return (int)GetValue(OvenIndexProperty); }
+            set { SetValue(OvenIndexProperty, value); }
+        }
+
+        public int CellIndex
+        {
+            get { return (int)GetValue(CellIndexProperty); }
+            set { SetValue(CellIndexProperty, value); }
+        }
+
+        public ObservableCollection<TestDataItem> TestData { get; private set; } = new ObservableCollection<TestDataItem>();
+
+        private Dictionary<string, StatusBtn> btnCache = new Dictionary<string, StatusBtn>();
+
+        // 日志级别颜色
+        private readonly SolidColorBrush _debugBrush;
+        private readonly SolidColorBrush _infoBrush;
+        private readonly SolidColorBrush _warnBrush;
+        private readonly SolidColorBrush _errorBrush;
+
+        private ITestExecutionWrapper executionWrapper;
+
+        public string seqPath { get; set; }
+        public string modelPath { get; set; } = "C:\\Program Files\\National Instruments\\TestStand 2020\\Components\\Models\\TestStandModels\\ParallelModel.seq";
+
+        public OldManualDebug()
+        {
+            _debugBrush = new SolidColorBrush(Color.FromRgb(0x71, 0x80, 0x8A)); // 灰色
+            _infoBrush = new SolidColorBrush(Colors.Black);
+            _warnBrush = new SolidColorBrush(Color.FromRgb(0xD6, 0x9E, 0x2E));  // 橙黄色
+            _errorBrush = new SolidColorBrush(Color.FromRgb(0xC5, 0x30, 0x30));   // 红色
+            this.Loaded += ManualDebug_Loaded;
+            InitializeComponent();
+            RefreshButtons(null);
+        }
+
+        private void ManualDebug_Loaded(object sender, RoutedEventArgs e)
+        {
+            Task.Run(() =>
+            {
+                System.Threading.Thread.Sleep(500);
+                Dispatcher.BeginInvoke(() =>
+                {
+                    InitWrapper();
+                    StartSeq();
+                    mask.Visibility = Visibility.Collapsed;
+                });
+            });
+        }
+
+        public void RefreshButtons(List<BtnConfig> settings)
+        {
+            if (settings == null) return;
+
+            for (int i = 0; i < settings.Count; i++)
+            {
+                var setting = settings[i];
+
+                var margin = new Thickness(0, 0, 20, 0);
+                if (i == settings.Count - 1)
+                {
+                    margin = new Thickness(0);
+                }
+
+                var btn = new StatusBtn
+                {
+                    Title = setting.Title,
+                    Tag = setting,
+                    Margin = margin
+                };
+                btn.BtnClick += Btn_BtnClick;
+                btnCache[setting.Name] = btn;
+                btnPanel.Children.Add(btn);
+            }
+        }
+
+        public void StartSeq()
+        {
+            try
+            {
+                executionWrapper?.StartSequence(seqPath, modelPath);
+            }
+            catch (Exception ex)
+            {
+                AppendLog(LogLevel.Error, $"启动测试序列失败 {ex.Message} {ex.StackTrace}");
+            }
+        }
+
+        private void InitWrapper()
+        {
+            try
+            {
+                var wrapper = new TeststandWrapper();
+                var AxApplicationMgr = wrapper.AxApplicationMgr;
+                ((System.ComponentModel.ISupportInitialize)(AxApplicationMgr)).BeginInit();
+                host.Child = AxApplicationMgr;
+                ((System.ComponentModel.ISupportInitialize)(AxApplicationMgr)).EndInit();
+                wrapper.Init();
+                executionWrapper = wrapper;
+
+                wrapper.UIMessageEvent += Wrapper_UIMessageEvent;
+            }
+            catch (Exception ex)
+            {
+                AppendLog(LogLevel.Error, $"初始化Teststand {ex.Message} {ex.StackTrace}");
+            }
+        }
+
+        private void Wrapper_UIMessageEvent(object sender, UIMessageEvent e)
+        {
+            try
+            {
+                if (e.EventCode == 10000)
+                {
+                    executionWrapper?.SetContext(e.Data);
+
+                    string key = $"Running.OvenName";
+                    executionWrapper?.SetFileGlobalValue(key, 1, OvenName);
+
+                    key = $"Running.CellName";
+                    executionWrapper?.SetFileGlobalValue(key, 1, CellName);
+
+                    key = $"Running.OvenIndex";
+                    executionWrapper?.SetFileGlobalValue(key, 1, OvenIndex);
+
+                    key = $"Running.CellIndex";
+                    executionWrapper?.SetFileGlobalValue(key, 1, CellIndex);
+
+                    return;
+                }
+                if (e.EventCode == 10001)
+                {
+                    string[] arr = e.StrData.Split(',');
+                    Dispatcher.BeginInvoke(() =>
+                    {
+                        AddTestData(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7]);
+                    });
+                    return;
+                }
+                if (e.EventCode == 10002)
+                {
+                    string[] arr = e.StrData.Split(',');
+                    LogLevel level = (LogLevel)int.Parse(arr[0]);
+                    Dispatcher.BeginInvoke(() =>
+                    {
+                        AppendLog(level, arr[1]);
+                    });
+                    return;
+                }
+                if (e.EventCode == 10003)
+                {
+                    string[] arr = e.StrData.Split(',');
+                    DebugStatus status = (DebugStatus)int.Parse(arr[1]);
+                    Dispatcher.BeginInvoke(() =>
+                    {
+                        SetStatus(arr[0], status);
+                    });
+                    return;
+                }
+            }
+            catch (Exception ex)
+            {
+                AppendLog(LogLevel.Error, $"处理UI信息失败 {ex.Message} {ex.StackTrace}");
+            }
+        }
+
+
+
+        private void Btn_BtnClick(object sender, RoutedEventArgs e)
+        {
+            var btn = (StatusBtn)sender;
+            BtnConfig config = (BtnConfig)btn.Tag;
+            StartSingleTest(config.Name);
+        }
+
+        private void StartSingleTest(string name)
+        {
+            try
+            {
+                string key = $"Running.ActionName";
+                executionWrapper?.SetFileGlobalValue(key, 1, name);
+            }
+            catch (Exception ex)
+            {
+                AppendLog(LogLevel.Error, $"启动功能失败 {ex.Message} {ex.StackTrace}");
+            }
+        }
+
+        // 设置状态显示
+        private void SetStatus(string labelName, DebugStatus status)
+        {
+            if (btnCache.ContainsKey(labelName))
+            {
+                var btn = btnCache[labelName];
+                btn.Status = status;
+            }
+        }
+
+        // 重置状态显示
+        private void ResetStatus(string labelName)
+        {
+            SetStatus(labelName, DebugStatus.Idle);
+        }
+
+        // 设置测试中状态并禁用按钮
+        private void SetTestingStatus(string labelName, Button button)
+        {
+            SetStatus(labelName, DebugStatus.Testing);
+            button.IsEnabled = false;
+        }
+
+        private void OnClearClick(object sender, RoutedEventArgs e)
+        {
+            TestData.Clear();
+        }
+
+        private void OnClearLogClick(object sender, RoutedEventArgs e)
+        {
+            LogRichTextBox.Document.Blocks.Clear();
+        }
+
+        private void AddTestData(string name, string send, string receive, string unit, string upper, string lower, string result, string time)
+        {
+            TestData.Add(new TestDataItem
+            {
+                Name = name,
+                Send = send,
+                Receive = receive,
+                Unit = unit,
+                UpperLimit = upper,
+                LowerLimit = lower,
+                Result = result,
+                Time = time
+            });
+
+            if (DataGridComm.Items.Count > 0)
+            {
+                DataGridComm.ScrollIntoView(DataGridComm.Items[DataGridComm.Items.Count - 1]);
+            }
+        }
+
+        // 获取日志级别对应的颜色
+        private Brush GetLogLevelBrush(LogLevel level)
+        {
+            switch (level)
+            {
+                case LogLevel.Debug:
+                    return _debugBrush;
+                case LogLevel.Info:
+                    return _infoBrush;
+                case LogLevel.Warn:
+                    return _warnBrush;
+                case LogLevel.Error:
+                    return _errorBrush;
+                default:
+                    return _infoBrush;
+            }
+        }
+
+        // 添加带级别的日志
+        private void AppendLog(LogLevel level, string message)
+        {
+            Dispatcher.BeginInvoke(() =>
+            {
+                string timestamp = DateTime.Now.ToString("HH:mm:ss.fff");
+                string levelStr = level.ToString().ToUpper();
+
+                Paragraph? paragraph = LogRichTextBox.Document.Blocks.LastBlock as Paragraph;
+                if (paragraph == null)
+                {
+                    paragraph = new Paragraph();
+                    LogRichTextBox.Document.Blocks.Add(paragraph);
+                }
+
+                // 时间戳(灰色)
+                Run timestampRun = new Run("[" + timestamp + "] ") { Foreground = _debugBrush };
+                paragraph.Inlines.Add(timestampRun);
+
+                // 级别标签
+                Brush levelBrush = GetLogLevelBrush(level);
+                Run levelRun = new Run("[" + levelStr + "] ") { Foreground = levelBrush, FontWeight = FontWeights.SemiBold };
+                paragraph.Inlines.Add(levelRun);
+
+                // 消息内容
+                Run messageRun = new Run(message + "\n") { Foreground = levelBrush };
+                paragraph.Inlines.Add(messageRun);
+
+                LogRichTextBox.ScrollToEnd();
+            });
+        }
+
+        // 兼容旧调用方式,默认 Info 级别
+        private void AppendLog(string message)
+        {
+            AppendLog(LogLevel.Info, message);
+        }
+
+        public void Stop()
+        {
+            try
+            {
+                executionWrapper?.SetFileGlobalValue("Running.StopTest", 1, true);
+                executionWrapper?.WaitForExit();
+                executionWrapper?.Dispose();
+            }
+            catch (Exception ex)
+            {
+
+            }
+        }
+    }
+
+}

--
Gitblit v1.9.1