From fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 17:59:45 +0800
Subject: [PATCH] feat: 集成CAN驱动/模拟器 + 仪器仪表注册/硬件调试模块

---
 Plugin.TsSupport/TapWrapper.cs |  405 ++++++++++++++++++++++++++++-----------------------------
 1 files changed, 202 insertions(+), 203 deletions(-)

diff --git a/Plugin.TsSupport/TapWrapper.cs b/Plugin.TsSupport/TapWrapper.cs
index 23ef29a..c676291 100644
--- a/Plugin.TsSupport/TapWrapper.cs
+++ b/Plugin.TsSupport/TapWrapper.cs
@@ -1,39 +1,188 @@
-锘縰sing System;
-//using AddInPlugin;
-//using AddInPlugin.Util;
-//using Microsoft.Win32;
-//using OpenTap;
-//using OpenTap.Addin;
-//using OpenTap.Addin.Util;
-//using System.ComponentModel;
-//using System.IO;
+锘縰sing AddInPlugin;
+using AddInPlugin.Util;
+using Microsoft.Win32;
+using OpenTap;
+using OpenTap.Addin;
+using OpenTap.Addin.Listener;
+using OpenTap.Addin.Reader;
+using OpenTap.Addin.Util;
+using OpenTap.Plugins.BasicSteps;
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Windows;
+using System.Windows.Threading;
 
 namespace Plugin.TsSupport
 {
-
-    public class TapWrapper : ITestExecutionWrapper
+    public class Net47Getter : IRegGetter
     {
+        public string GetAppPath(string keyPath)
+        {
+            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath))
+            {
+                if (key == null)
+                {
+                    throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
+                }
+
+                string value = key.GetValue("Location")?.ToString();
+                if (string.IsNullOrEmpty(value))
+                {
+                    throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
+                }
+                return value;
+            }
+        }
+    }
+
+    public class TapWrapper : ITestExecutionWrapper, IResultListener, IUserInputInterface
+    {
+        TapThread testPlanThread;
+        TestPlan Plan;
+        TestPlanRun PlanRun;
+
+        public event PropertyChangedEventHandler PropertyChanged;
         public event EventHandler<UIMessageEvent> UIMessageEvent;
         public event EventHandler<ExecutionEndEvent> EndExecutionEvent;
 
-        public void CommitToDisk(bool option)
-        {
+        private PostUIMessageHandler uIMessageHandler;
 
-        }
+        public string Name { get; set; }
 
-        public T GetFileGlobalValue<T>(string key, int option)
-        {
-            return default(T);
-        }
+        public bool IsConnected => true;
 
-        public T GetStationGlobalValue<T>(string key, int option)
+        static TapWrapper()
         {
-            return default(T);
+            RegUtil.Register(new Net47Getter());
         }
 
         public object Init()
         {
+            StationGlobalsManager.Register(new DefaultStationGlobalsManager());
+            VariableResolverFactory.Register(new DefaultVariableResolverFactory());
+            ResultSettings.Current.Add(this);
+            UserInput.SetInterface(this);
+            LvlibpLoader.PreLoad();
+            PropertyInfoCache.Refresh(typeof(MethodVariable));
+            uIMessageHandler = PostUIMessageHandler.Get();
+            uIMessageHandler.OnPostUIMsg += PostUIMsgHandler_OnPostUIMsg;
             return null;
+        }
+
+        private void PostUIMsgHandler_OnPostUIMsg(object sender, PostUIMsg e)
+        {
+            UIMessageEvent?.Invoke(this, new UIMessageEvent()
+            {
+                Origin = e,
+                EventCode = e.EventCode,
+                BoolData = e.BoolData,
+                NumberData = e.NumberData,
+                StrData = e.StringData
+            });
+        }
+
+        public object StartSequence(string filePath, string modelPath)
+        {
+            Plan = TestPlanReader.ReadTestPlan(filePath);
+            //Plan = TestPlan.Load(filePath);
+            testPlanThread = TapThread.Start(() =>
+            {
+                var res = ResultSettings.Current;
+                res.Add(uIMessageHandler);
+                Plan.Execute(ResultSettings.Current);
+            });
+            return Plan;
+        }
+
+
+        public T GetFileGlobalValue<T>(string key, int option)
+        {
+            return PlanRun.Resolve<T>(null, $"FileGlobals.{key}");
+        }
+
+        public T GetStationGlobalValue<T>(string key, int option)
+        {
+            if (PlanRun == null)
+            {
+                return StationGlobalsManager.GetValue<T>(key);
+            }
+            return PlanRun.Resolve<T>(null, $"StationGlobals.{key}");
+        }
+
+        public T GetValue<T>(string key, int option)
+        {
+            return default(T);
+        }
+
+        public void SetValue<T>(string key, T value, int option)
+        {
+
+        }
+
+        public void SetFileGlobalValue<T>(string key, int option, T value)
+        {
+            PlanRun.Update(null, $"FileGlobals.{key}", value);
+        }
+
+        public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
+        {
+            if (PlanRun == null)
+            {
+                StationGlobalsManager.SetValue(key, value);
+            }
+            else
+            {
+                PlanRun.Update(null, $"StationGlobals.{key}", value);
+            }
+        }
+
+        public void CommitToDisk(bool option)
+        {
+            StationGlobalsManager.WriteToLocal(null);
+        }
+
+        public void OnTestPlanRunStart(TestPlanRun planRun)
+        {
+            PlanRun = planRun;
+        }
+
+        public void OnTestPlanRunCompleted(TestPlanRun planRun, Stream logStream)
+        {
+            PlanRun = null;
+        }
+
+        public void OnTestStepRunStart(TestStepRun stepRun)
+        {
+
+        }
+
+        public void OnTestStepRunCompleted(TestStepRun stepRun)
+        {
+
+        }
+
+        public void OnResultPublished(Guid stepRunID, ResultTable result)
+        {
+
+        }
+
+        public void Open()
+        {
+
+        }
+
+        public void Close()
+        {
+            EndExecutionEvent?.Invoke(this, new ExecutionEndEvent());
+            Plan = null;
+            PlanRun = null;
+            testPlanThread = null;
+        }
+
+        public bool WaitForExit()
+        {
+            return true;
         }
 
         public bool ReleaseSeqFile()
@@ -41,198 +190,48 @@
             return true;
         }
 
+        public void Dispose()
+        {
+        }
+
         public void SetContext(object context)
         {
 
         }
 
-        public void SetFileGlobalValue<T>(string key, int option, T value)
-        {
+        public DispatcherObject ui { get; private set; }
 
+        public void RegisteUserInput(DispatcherObject ui)
+        {
+            this.ui = ui;
         }
 
-        public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
+        public void RequestUserInput(object dataObject, TimeSpan Timeout, bool modal)
         {
-
-        }
-
-        public object StartSequence(string filePath, string modelPath)
-        {
-            return null;
-        }
-
-        public bool WaitForExit()
-        {
-            return true;
+            if (dataObject is DialogRequest req)
+            {
+                this.ui?.Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    if (req.Buttons == InputButtons.OkCancel)
+                    {
+                        var res = MessageBox.Show(req.Message, req.Name, MessageBoxButton.OKCancel);
+                        req.Input2 = res == MessageBoxResult.OK ? WaitForInputResult2.Ok : WaitForInputResult2.Cancel;
+                    }
+                    else
+                    {
+                        var res = MessageBox.Show(req.Message, req.Name, MessageBoxButton.YesNo);
+                        req.Input1 = res == MessageBoxResult.Yes ? WaitForInputResult1.Yes : WaitForInputResult1.No;
+                    }
+                })).Wait();
+            }
+            else if (dataObject is OpenTap.TestPlan.PlanLoadError err)
+            {
+                this.ui?.Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    var res = MessageBox.Show(err.Message, err.Name, MessageBoxButton.OKCancel);
+                    err.Response = res == MessageBoxResult.OK ? TestPlan.PlanLoadErrorResponse.Ignore : TestPlan.PlanLoadErrorResponse.Abort;
+                })).Wait();
+            }
         }
     }
-
-    //public class Net47Getter : IRegGetter
-    //{
-    //    public string GetAppPath(string keyPath)
-    //    {
-    //        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath))
-    //        {
-    //            if (key == null)
-    //            {
-    //                throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
-    //            }
-
-    //            string value = key.GetValue("Location")?.ToString();
-    //            if (string.IsNullOrEmpty(value))
-    //            {
-    //                throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
-    //            }
-    //            return value;
-    //        }
-    //    }
-    //}
-
-    //public class TapWrapper : ITestExecutionWrapper, IResultListener
-    //{
-    //    TapThread testPlanThread;
-    //    TestPlan Plan;
-    //    TestPlanRun PlanRun;
-
-    //    public event PropertyChangedEventHandler PropertyChanged;
-
-    //    public event EventHandler<UIMessageEvent> UIMessageEvent;
-    //    public event EventHandler<ExecutionEndEvent> EndExecutionEvent;
-
-    //    public string Name { get; set; }
-
-    //    public bool IsConnected => true;
-
-    //    public object Init()
-    //    {
-    //        RegUtil.Register(new Net47Getter());
-    //        StationGlobalsManager.Register(new DefaultStationGlobalsManager());
-    //        VariableResolverFactory.Register(new DefaultVariableResolverFactory());
-    //        ResultSettings.Current.Add(this);
-    //        return null;
-    //    }
-
-    //    private void PostUIMsgHandler_OnPostUIMsg(object sender, PostUIMsg e)
-    //    {
-    //        UIMessageEvent?.Invoke(this, new UIMessageEvent()
-    //        {
-    //            Origin = e,
-    //            EventCode = e.EventCode,
-    //            BoolData = e.BoolData,
-    //            NumberData = e.NumberData,
-    //            StrData = e.StringData
-    //        });
-    //    }
-
-    //    public object StartSequence(string filePath, string modelPath)
-    //    {
-    //        Plan = TestPlan.Load(filePath);
-    //        testPlanThread = TapThread.Start(() =>
-    //        {
-    //            var res = ResultSettings.Current;
-    //            Plan.Execute(ResultSettings.Current, null);
-    //        });
-    //        return Plan;
-    //    }
-
-
-    //    public T GetFileGlobalValue<T>(string key, int option)
-    //    {
-    //        return PlanRun.Resolve<T>(null, $"FileGlobals.{key}");
-    //    }
-
-    //    public T GetStationGlobalValue<T>(string key, int option)
-    //    {
-    //        if (PlanRun == null)
-    //        {
-    //            return StationGlobalsManager.GetValue<T>(key);
-    //        }
-    //        return PlanRun.Resolve<T>(null, $"StationGlobals.{key}");
-    //    }
-
-    //    public T GetValue<T>(string key, int option)
-    //    {
-    //        return default(T);
-    //    }
-
-    //    public void SetValue<T>(string key, T value, int option)
-    //    {
-
-    //    }
-
-    //    public void SetFileGlobalValue<T>(string key, int option, T value)
-    //    {
-    //        PlanRun.Update(null, $"FileGlobals.{key}", value);
-    //    }
-
-    //    public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
-    //    {
-    //        if (PlanRun == null)
-    //        {
-    //            StationGlobalsManager.SetValue(key, value);
-    //        }
-    //        else
-    //        {
-    //            PlanRun.Update(null, $"StationGlobals.{key}", value);
-    //        }
-    //    }
-
-    //    public void CommitToDisk(bool option)
-    //    {
-    //        StationGlobalsManager.WriteToLocal(null);
-    //    }
-
-    //    public void OnTestPlanRunStart(TestPlanRun planRun)
-    //    {
-    //        PlanRun = planRun;
-    //    }
-
-    //    public void OnTestPlanRunCompleted(TestPlanRun planRun, Stream logStream)
-    //    {
-
-
-    //    }
-
-    //    public void OnTestStepRunStart(TestStepRun stepRun)
-    //    {
-
-    //    }
-
-    //    public void OnTestStepRunCompleted(TestStepRun stepRun)
-    //    {
-
-    //    }
-
-    //    public void OnResultPublished(Guid stepRunID, ResultTable result)
-    //    {
-
-    //    }
-
-    //    public void Open()
-    //    {
-    //        PostUIMsgHandler.OnPostUIMsg += PostUIMsgHandler_OnPostUIMsg;
-    //    }
-
-    //    public void Close()
-    //    {
-    //        PostUIMsgHandler.OnPostUIMsg -= PostUIMsgHandler_OnPostUIMsg;
-    //        EndExecutionEvent?.Invoke(this, new ExecutionEndEvent());
-    //        PlanRun = null;
-    //    }
-
-    //    public bool WaitForExit()
-    //    {
-    //        return true;
-    //    }
-
-    //    public bool ReleaseSeqFile()
-    //    {
-    //        return true;
-    //    }
-
-    //    public void SetContext(object context)
-    //    {
-
-    //    }
-    //}
 }

--
Gitblit v1.9.1