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.TestResult/DataTable.xaml.cs |  207 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 146 insertions(+), 61 deletions(-)

diff --git a/Plugin.TestResult/DataTable.xaml.cs b/Plugin.TestResult/DataTable.xaml.cs
index 1ac79ce..bcff8ec 100644
--- a/Plugin.TestResult/DataTable.xaml.cs
+++ b/Plugin.TestResult/DataTable.xaml.cs
@@ -1,10 +1,13 @@
-锘縰sing HMI.Core.Setting;
+锘縰sing HMI.Base;
+using HMI.Core.Setting;
 using HMI.Core.Util;
+using HMI.LogUtil;
 using HMI.UI.Util;
 using HMI.Util;
 using Plugin.TestResult;
 using Plugin.TestResult.Util;
 using Plugin.TestResult_WPF.Model;
+using Plugin.TsSupport;
 using SuperSocket.SocketBase.Config;
 using SuperSocket.SocketBase.Protocol;
 using System;
@@ -15,6 +18,7 @@
 using System.Timers;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Markup;
 
 namespace Plugin.TestResult_WPF
 {
@@ -88,9 +92,9 @@
             set { RaiseAndSetIfchanged(ref tcpServerInfo, value); }
         }
         public int index { get; private set; }
-        private readonly int cellCount;
+        public readonly int cellCount;
         private readonly string chartTitle;
-        private readonly TestResultView parent;
+        public readonly TestResultView parent;
 
         private BaseConfig config;
         private LiveChart chart;
@@ -137,7 +141,7 @@
             {
                 var cellRow = (i / config.PositionColumn) + 1;
                 var cellCol = (i % config.PositionColumn) + 1;
-                var cellTitle = $"{title}-{cellRow}-{cellCol}";                
+                var cellTitle = $"{title}-{cellRow}-{cellCol}";
 
                 var cell = new SingleCell(this, cellTitle, i, config.CellListMaxSize, countIniPath);
                 mainGrid.Children.Add(cell);
@@ -152,6 +156,7 @@
             testTimeTimer.AutoReset = true;
             testTimeTimer.Elapsed += TestTimeTimer_Elapsed;
             if (!ParamSetting.ShowCoolerSetting) coolerSetting.Visibility = Visibility.Collapsed;
+            if (!ParamSetting.ShowBurnInAbort) abortBtn.Visibility = Visibility.Collapsed;
         }
 
         private void TestTimeTimer_Elapsed(object sender, ElapsedEventArgs e)
@@ -306,13 +311,42 @@
             {
                 if (MsgBoxHelper2.WarnChoose(this.lang("Tr.MakeSureStopOvenTest", title)) == MessageBoxResult.OK)
                 {
+                    LogHelper.Info("UI", $"鑰佸寲鐐塠{title}]鍋滄鎸夐挳鎸変笅", out _);
+                    ViewControl.Logger.Info($"鑰佸寲鐐塠{title}]鍋滄鎸夐挳鎸変笅");
                     parent.SetStartFlag(this.index, false);
                 }
             }
             else
             {
-                ClearChartData();
-                parent.SetStartFlag(this.index, true);
+                /// 妫�鏌ユ槸鍚﹀叧闂�
+                if (!GetDoorClose(parent.executionWrapper))
+                {
+                    /// 娌″叧闂ㄤ笉鍏佽鍚姩
+                    MsgBoxHelper2.Warn("璇峰厛鍏抽棴鑸遍棬锛�");
+                    return;
+                }
+
+                /// 妫�鏌ユ槸鍚︽湁鏉$爜
+                bool flag = false;
+                foreach (var cell in cells)
+                {
+                    if (!string.IsNullOrEmpty(cell.sn))
+                    {
+                        flag = true;
+                        break;
+                    }
+                }
+                if (flag)
+                {
+                    LogHelper.Info("UI", $"鑰佸寲鐐塠{title}]鍚姩鎸夐挳鎸変笅", out _);
+                    ViewControl.Logger.Info($"鑰佸寲鐐塠{title}]鍚姩鎸夐挳鎸変笅");
+                    ClearChartData();
+                    parent.SetStartFlag(this.index, true);
+                }
+                else
+                {
+                    MsgBoxHelper2.Warn("璇峰厛瀹屾垚鎵爜锛�");
+                }
             }
         }
 
@@ -346,8 +380,9 @@
         private void Scanner_ComplateClick(object sender, RoutedEventArgs e)
         {
             string paramName = $"StationState.Scanner[{index}]";
-            parent.engine.Globals.SetValBoolean(paramName, 1, true);
-            //parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+
+            parent.executionWrapper.SetStationGlobalValue<bool>(paramName, 1, true);
+            //parent.engine.Globals.SetValBoolean(paramName, 1, true);
         }
 
         private void Scanner_Closed(object sender, EventArgs e)
@@ -355,35 +390,61 @@
             scanner = null;
         }
 
+        public bool GetDoorClose(ITestExecutionWrapper wrapper)
+        {
+            return wrapper?.GetStationGlobalValue<bool>($"StationState.DoorClose[{this.index}]", 0) == true;
+        }
+
         private void Scanner_FinishBarcode(object sender, BarcodeEventArg e)
         {
-            if (parent.SequenceContext == null) return;
+            if (parent.executionWrapper == null) return;
+            //if (parent.SequenceContext == null) return;
 
             int rows = (config.CellCount / config.PositionColumn) + 1;
             CellInfo cellInfo = ScannerParser.GetCellInfoByCode(CbProduct.SelectedItem?.ToString(), mainGrid.Columns, rows, e.positionCode);
             string positionCode = e.positionCode, snrCode = e.snrCode;
 
-            //灏嗚鍒扮殑鏉$爜鍐欏叆鍒癝N涓�
-            int dutNo = this.index * this.cellCount + cellInfo.Index;
+            //if (cellInfo.OvenName != this.title)
+            //{
+            //    MsgBoxHelper2.Warn($"璇峰垏鎹㈣嚦 [{cellInfo.OvenName}] 鍖烘壂鐮侊紝褰撳墠涓� [{this.title}] 鍖猴紒");
+            //    return;
+            //}
 
+
+            var targetTable = TestResultView.nameTables[cellInfo.OvenName];
+
+            //灏嗚鍒扮殑鏉$爜鍐欏叆鍒癝N涓�
+            int dutNo = targetTable.index * targetTable.cellCount + cellInfo.Index;
             string LookupStr = $"StationState.SN[{dutNo}]";
             cellInfo.LookUpStr = LookupStr;
 
-            ViewControl.Logger.Debug($"PositionCode: [{e.positionCode}], SNR: [{e.snrCode}], LookUpStr: [{LookupStr}]");
-            ViewControl.Logger.Debug($"OvenName: [{cellInfo.OvenName}], CellIndex: [{cellInfo.Index}]");
-            var cell = TestResultView.nameTables[cellInfo.OvenName].GetSingleCell(cellInfo.Index);
+            ViewControl.Logger.Info($"PositionCode: [{e.positionCode}], SNR: [{e.snrCode}], LookUpStr: [{LookupStr}]");
+            ViewControl.Logger.Info($"OvenName: [{cellInfo.OvenName}], CellIndex: [{cellInfo.Index}]");
+            var cell = targetTable.GetSingleCell(cellInfo.Index);
+
+            if (targetTable.GetDoorClose(parent.executionWrapper))
+            {
+                /// 鍏抽棬浜嗗氨涓嶅厑璁告竻鏉$爜
+                MsgBoxHelper2.Warn($"{targetTable.title}鐐夌敓浜т腑锛屼笉鍏佽鎿嶄綔鏉$爜");
+                //MsgBoxHelper2.Warn(this.lang("Tr.CantClearSNR"));
+                return;
+            }
+
             if (snrCode == null)
             {
                 var oldCellInfo = e.lastInfo;
-                var oldCell = TestResultView.nameTables[oldCellInfo.OvenName].GetSingleCell(oldCellInfo.Index);
+                var oldTable = TestResultView.nameTables[oldCellInfo.OvenName];
+                var oldCell = oldTable.GetSingleCell(oldCellInfo.Index);
                 if (oldCell.status != "hadCode")
                 {
                     throw new Exception(this.lang("Tr.PositionCantClearSNR", oldCellInfo.OriginCode));
                 }
                 // 绉婚櫎鏉$爜
-                parent.engine.Globals.SetValString(oldCellInfo.LookUpStr, 1, "");
-                parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+                parent.executionWrapper.SetStationGlobalValue<string>(oldCellInfo.LookUpStr, 1, "");
+                parent.executionWrapper.CommitToDisk(false);
 
+                //parent.engine.Globals.SetValString(oldCellInfo.LookUpStr, 1, "");
+                //parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
                 oldCell.SetStatus("waiting");
                 oldCell.ClearSN();
                 return;
@@ -397,21 +458,16 @@
             }
 
             // 鍐欏叆鏉$爜
-            parent.engine.Globals.SetValString(LookupStr, 1, snrCode);
-            parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+            parent.executionWrapper.SetStationGlobalValue<string>(LookupStr, 1, snrCode);
+            parent.executionWrapper.CommitToDisk(false);
 
-            TestResultView.nameTables[cellInfo.OvenName].GetSingleCell(cellInfo.Index).SetStatus("hadCode");
-            TestResultView.nameTables[cellInfo.OvenName].GetSingleCell(cellInfo.Index).sn = snrCode;
+            //parent.engine.Globals.SetValString(LookupStr, 1, snrCode);
+            //parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+
+            cell.SetStatus("hadCode");
+            cell.sn = snrCode;
             Scanner.InsertNewCode(snrCode, cellInfo);
-            var light = $"Oven{this.index + 1}_Cell{cell.index + 1}_Light_OK";
-            if (cell.LightGreen(true, out string msg))
-            {
-                ViewControl.Logger.Debug($"Open Light [{light}] ON.");
-            }
-            else
-            {
-                ViewControl.Logger.Debug($"Open Light [{light}] Error.{msg}");
-            }
+            cell.LightGreen(true, out string msg);            
         }
 
 
@@ -531,18 +587,18 @@
 
             string strs = datas_10015[2];
             string[] values = strs.Split(',');
-
-            //string step = datas_10015[2];
-            //string result = datas_10015[3];
-            GetSingleCell(cellIndex).SetInfos(new Info
+            Dispatcher.Invoke(() =>
             {
-                step = values[0],
-                value = values[1],
-                limitUp = values[2],
-                limitDown = values[3],
-                unit = values[4],
-                result = values[5],
-                updateTime = values[6]
+                GetSingleCell(cellIndex).SetInfos(new Info
+                {
+                    step = values[0],
+                    value = values[1],
+                    limitUp = values[2],
+                    limitDown = values[3],
+                    unit = values[4],
+                    result = values[5],
+                    updateTime = values[6]
+                });
             });
             //session.Send("1");
         }
@@ -551,17 +607,18 @@
         {
             infoTable.UpdateNumber(infoTable.okCount + ok, infoTable.ngCount + ng);
 
-            if (ParamSetting.ProbeByModel)
-            {
+            //if (ParamSetting.ProbeByModel)
+            //{
 
-            }
-            else
-            {
-                IniFileHelper.WriteIniData($"Oven_{index}", "Pass", infoTable.okCount.ToString(),
-                   this.CountIniPath);
-                IniFileHelper.WriteIniData($"Oven_{index}", "Fail", infoTable.ngCount.ToString(),
-                    this.CountIniPath);
-            }
+            //}
+            //else
+            //{
+
+            //}
+            IniFileHelper.WriteIniData($"Oven_{index}", "Pass", infoTable.okCount.ToString(),
+                  this.CountIniPath);
+            IniFileHelper.WriteIniData($"Oven_{index}", "Fail", infoTable.ngCount.ToString(),
+                this.CountIniPath);
         }
 
         /// <summary>
@@ -747,10 +804,10 @@
 
         private void ClearAllSnr_Click(object sender, RoutedEventArgs e)
         {
-            var str = $"StationState.DoorClose[{index}]";
-            if (parent.engine.Globals.GetValBoolean(str, 0) == true)
+            if (GetDoorClose(parent.executionWrapper))
             {
-                MsgBoxHelper.Error(Window.GetWindow(this), this.lang("Tr.CantClearSNR"));
+                /// 鍏抽棬浜嗗氨涓嶅厑璁告竻鏉$爜
+                MsgBoxHelper2.Warn(this.lang("Tr.CantClearSNR"));
                 return;
             }
 
@@ -779,8 +836,7 @@
 
         public void TryClearCellSN(int cellIndex)
         {
-            var str = $"StationState.DoorClose[{this.index}]";
-            if (parent.engine.Globals.GetValBoolean(str, 0) == true)
+            if (GetDoorClose(parent.executionWrapper))
             {
                 MsgBoxHelper.Error(Window.GetWindow(this), this.lang("Tr.CantClearSNR"));
                 return;
@@ -795,18 +851,47 @@
             string LookupStr = $"StationState.SN[{dutNo}]";
             var lastSN = cell.sn;
             cell.SetStatus("waiting");
-            parent.engine.Globals.SetValString(LookupStr, 1, "");
-            parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+
+            parent.executionWrapper.SetStationGlobalValue<string>(LookupStr, 1, "");
+            parent.executionWrapper.CommitToDisk(false);
+
+            //parent.engine.Globals.SetValString(LookupStr, 1, "");
+            //parent.engine.CommitGlobalsToDisk(promptOnSaveConflicts: false);
             if (!string.IsNullOrEmpty(lastSN)) Scanner.RemoveSNR(lastSN);
             cell.ClearSN();
         }
 
-        private void Button_Click_2(object sender, RoutedEventArgs e)
+        private void Abort_Click(object sender, RoutedEventArgs e)
         {
-            if (MsgBoxHelper.WarnMessage(Window.GetWindow(this), this.lang("Tr.MakeSureStopOvenTest", title)) == MessageBoxResult.OK)
+            if (!parent.IsRunning)
             {
-                parent.SetStartFlag(this.index, false);
+                MsgBoxHelper.WarnMessage(this, this.lang("Tr.StartSeqFirst"), null, MessageBoxButton.OK);
+                return;
             }
+
+            //string key = $"StationState.Start[{this.index}]";
+            //if (parent.executionWrapper?.GetStationGlobalValue<bool>(key, 0) == true)
+            //{
+            //    MsgBoxHelper2.Warn("娴嬭瘯鍚姩涓紝涓嶅厑璁窤bort");
+            //    return;
+            //}
+            var win = new RequirePasswordByUser("admin")
+            {
+                Owner = Window.GetWindow(this)
+            };
+            if (win.ShowDialog() != true)
+            {
+                return;
+            }
+
+            if (MsgBoxHelper2.WarnChoose("璇风‘璁よ�佸寲浠撳湪瀹夊叏娓╁害锛屾按鍐锋満鍚规按瀹屾垚锛屽崟鍑籓K鎸夐挳浠撲綅鍥炲埌鍒濆鍖栫姸鎬�") != MessageBoxResult.OK)
+            {
+                return;
+            }
+            LogHelper.Info("UI", $"{title} Abort鎸夐挳鎸変笅", out _);
+            ViewControl.Logger.Info($"{title} Abort鎸夐挳鎸変笅");
+            string key = $"StationState.Abort[{this.index}]";
+            parent.executionWrapper?.SetStationGlobalValue(key, 0, true);
         }
     }
 }

--
Gitblit v1.9.1