From 559890c482f5973f06aafdfec9550fee5ba3c7f2 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 09 十一月 2026 17:02:15 +0800
Subject: [PATCH] feat: CAN 模拟器 TCP 化 + 多设备并发调试 + 后台生命周期管理

---
 Plugin.TsExecution/TsExecution.xaml.cs |  100 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 82 insertions(+), 18 deletions(-)

diff --git a/Plugin.TsExecution/TsExecution.xaml.cs b/Plugin.TsExecution/TsExecution.xaml.cs
index 9575fb8..06b9d39 100644
--- a/Plugin.TsExecution/TsExecution.xaml.cs
+++ b/Plugin.TsExecution/TsExecution.xaml.cs
@@ -13,6 +13,7 @@
 using NationalInstruments.TestStand.Interop.API;
 using NPOI.HSSF.UserModel;
 using NPOI.SS.UserModel;
+using OpenTap;
 using Plugin.TsSupport;
 using ScottPlot;
 using ScottPlot.Plottables;
@@ -24,7 +25,6 @@
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Forms.DataVisualization.Charting;
 
 namespace Plugin.TsExecution
 {
@@ -57,7 +57,7 @@
         #endregion
 
         public static ILog logger { get; private set; }
-        private List<SingleControl> tsSockets = new List<SingleControl>();
+        public List<SingleControl> tsSockets { get; private set; } = new List<SingleControl>();
         /// <summary>
         /// 鏍蜂欢妯″紡鐘舵��
         /// </summary>
@@ -298,7 +298,22 @@
             }
         }
 
-        private string tsModelPath;
+        private bool enableManualDebug;
+        public bool EnableManualDebug
+        {
+            get => enableManualDebug;
+            set
+            {
+                if (IsTesting)
+                {
+                    MsgBoxHelper2.Warn("璇峰厛缁撴潫鑷姩娴嬭瘯");
+                    return;
+                }
+                Set(ref enableManualDebug, value);
+            }
+        }
+
+        public string tsModelPath { get; private set; }
         private string dataLogPath;
         private SqliteHelper sqliteHelper;
 
@@ -309,9 +324,7 @@
         {
             DataContext = this;
             InitializeComponent();
-
             InitChart();
-            InitTsEngine();
         }
 
         public override void SetBaseFolder(string folder)
@@ -363,6 +376,7 @@
 
         public override void InitFinish()
         {
+            InitTsEngine();
             this.ReadCount(out int pass, out int fail);
             this.DisplayCount(pass, fail);
             ReadConfig();
@@ -388,6 +402,33 @@
             catch (Exception ex)
             {
                 log.Warn("Get Login User Failed.", ex);
+            }
+            RefreshUIConfig();
+        }
+
+        /// <summary>
+        /// 鍒锋柊UI閰嶇疆
+        /// </summary>
+        private void RefreshUIConfig()
+        {
+            try
+            {
+                bool enableManualDebug = ParameterManager.GetCommonParameterByName("EnableManualDebug", false);
+                if (enableManualDebug)
+                {
+                    Cb_ManualDebug.Visibility = Visibility.Visible;
+                    EnableManualDebug = false;
+                }
+                else
+                {
+                    Cb_ManualDebug.Visibility = Visibility.Collapsed;
+                    EnableManualDebug = false;
+                }
+
+            }
+            catch (Exception ex)
+            {
+                log.Error("RefreshUIConfig Error.", ex);
             }
         }
 
@@ -498,7 +539,10 @@
         {
             if (ParamSetting.EngineType == "Tap")
             {
-                testExecutionWrapper = new TapWrapper();
+                var wrapper = new TapWrapper();
+                wrapper.RegisteUserInput(this);
+                log.Debug($"Wrapper UI is {wrapper.ui}");
+                testExecutionWrapper = wrapper;
             }
             else
             {
@@ -657,6 +701,7 @@
                 {
                     SocketName = name
                 };
+                control.parent = this;
                 panel.Children.Add(control);
                 tsSockets.Add(control);
 
@@ -874,7 +919,7 @@
             {
 
                 value = ParameterManager.GetCommonParameterByName("TestReportFolder");
-                csvDir = value.Value;
+                csvDir = value?.Value ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestReport");
                 if (!Directory.Exists(csvDir))
                 {
                     Directory.CreateDirectory(csvDir);
@@ -889,7 +934,7 @@
             {
 
                 value = ParameterManager.GetCommonParameterByName("IsOptRequirePassword");
-                IsOptRequirePassword = bool.Parse(value.Value);
+                IsOptRequirePassword = value == null ? false : bool.Parse(value.Value);
             }
             catch
             {
@@ -1218,9 +1263,12 @@
 
         public void UpdatePositionStatus(int index, string status)
         {
-            this.tsSockets[index].UpdateStatus(status);
-            OnStatusPublished(index, status);
-            this.UpdateTestCounter();
+            Dispatcher.Invoke(() =>
+            {
+                this.tsSockets[index].UpdateStatus(status);
+                OnStatusPublished(index, status);
+                this.UpdateTestCounter();
+            });
         }
 
         private void OnStatusPublished(int index, string status)
@@ -1531,17 +1579,26 @@
                     break;
 
                 case 10006://鍙戦�佷骇鍝佹潯鐮�
-                    SetPositionBarcode(index, strData);
+                    Dispatcher.Invoke(() =>
+                    {
+                        SetPositionBarcode(index, strData);
+                    });
                     break;
 
                 case 10007://寮�濮嬫祴璇曡鏃�
-                    tsSockets[index].ElapseTime = "Start Timing";
-                    BtnStopSeq.IsEnabled = false;
+                    Dispatcher.Invoke(() =>
+                    {
+                        tsSockets[index].ElapseTime = "Start Timing";
+                        BtnStopSeq.IsEnabled = false;
+                    });
                     break;
 
                 case 10008://鍋滄娴嬭瘯璁℃椂
-                    tsSockets[index].ElapseTime = "Stop Timing";
-                    BtnStopSeq.IsEnabled = true;
+                    Dispatcher.Invoke(() =>
+                    {
+                        tsSockets[index].ElapseTime = "Stop Timing";
+                        BtnStopSeq.IsEnabled = true;
+                    });
                     break;
 
                 case 10009:
@@ -1582,7 +1639,10 @@
 
                     break;
                 case 10017://鏇存柊娴嬭瘯璁℃椂锛岄拡瀵归儴鍒嗚鏃舵湁PLC瀹屾垚鐨勯」鐩�
-                    this.tsSockets[index].ElapseTime = strData;
+                    Dispatcher.Invoke(() =>
+                    {
+                        this.tsSockets[index].ElapseTime = strData;
+                    });
                     break;
                 case (int)UIMessageCodes.UIMsg_EndExecution://鎵ц缁撴潫
                     //IsTesting = false;
@@ -1590,7 +1650,10 @@
                     break;
                 case 10030://鏄剧ず娴嬭瘯杩涘害
                     int ProcessVal = Convert.ToInt32(strData);
-                    this.tsSockets[index].SetTestProcess(ProcessVal);
+                    Dispatcher.Invoke(() =>
+                    {
+                        this.tsSockets[index].SetTestProcess(ProcessVal);
+                    });
                     break;
                 case 10031://瀵煎嚭CSV
 
@@ -1806,6 +1869,7 @@
 
         public override void DoClose(object sender, EventArgs e)
         {
+            testExecutionWrapper?.Dispose();
             base.DoClose(sender, e);
         }
 

--
Gitblit v1.9.1