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.TsSupport/TeststandWrapper.cs | 248 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 248 insertions(+), 0 deletions(-)
diff --git a/Plugin.TsSupport/TeststandWrapper.cs b/Plugin.TsSupport/TeststandWrapper.cs
new file mode 100644
index 0000000..1b7bfec
--- /dev/null
+++ b/Plugin.TsSupport/TeststandWrapper.cs
@@ -0,0 +1,248 @@
+锘縰sing NationalInstruments.TestStand.Interop.API;
+using NationalInstruments.TestStand.Interop.UI.Ax;
+using System;
+using System.Runtime.InteropServices;
+
+namespace Plugin.TsSupport
+{
+ public class TeststandWrapper : ITestExecutionWrapper
+ {
+ #region TestStand浜嬩欢
+ /// <summary>
+ /// TS 寮曟搸
+ /// </summary>
+ private Engine engine = null;
+
+ /// <summary>
+ /// 娴嬭瘯搴忓垪璺緞
+ /// </summary>
+ private string testSeqFile = string.Empty;
+
+ /// <summary>
+ /// 娴嬭瘯搴忓垪
+ /// </summary>
+ private SequenceFile testSeq = null;
+
+ /// <summary>
+ /// 娴嬭瘯妯″瀷搴忓垪
+ /// </summary>
+ private SequenceFile modeSeq = null;
+
+ /// <summary>
+ /// 杩愯瀹炰緥
+ /// </summary>
+ private Execution execution = null;
+
+ public SequenceContext context { get; set; } = null;
+
+ /// <summary>
+ /// 浜嬩欢绠$悊鍣�
+ /// </summary>
+ public AxApplicationMgr AxApplicationMgr { get; private set; }
+ #endregion
+
+ public event EventHandler<UIMessageEvent> UIMessageEvent;
+ public event EventHandler<ExecutionEndEvent> EndExecutionEvent;
+
+ public TeststandWrapper()
+ {
+ AxApplicationMgr = TestAppManager.GetAxApplicationMgr();
+ AxApplicationMgr.EndExecution += AxApplicationMgr_EndExecution;
+ AxApplicationMgr.UIMessageEvent += AxApplicationMgr_UIMessageEvent;
+
+ //AxApplicationMgr.ExitApplication += new EventHandler(this.AxApplicationMgr_ExitApplication);
+ //AxApplicationMgr.ExecutionClosed +=
+ // new _ApplicationMgrEvents_ExecutionClosedEventHandler(this.AxApplicationMgr_ExecutionClosed);
+ }
+
+ private void AxApplicationMgr_UIMessageEvent(object sender, _ApplicationMgrEvents_UIMessageEventEvent e)
+ {
+ UIMessageEvent?.Invoke(this, new UIMessageEvent()
+ {
+ Origin = e,
+ EventCode = Convert.ToInt32(e.uiMsg.Event),
+ NumberData = Convert.ToInt16(e.uiMsg.NumericData),
+ Data = e.uiMsg.ActiveXData,
+ StrData = e.uiMsg.StringData
+ });
+ }
+
+ private void AxApplicationMgr_EndExecution(object sender, _ApplicationMgrEvents_EndExecutionEvent e)
+ {
+ EndExecutionEvent?.Invoke(this, new ExecutionEndEvent() { Origin = e });
+ }
+
+ public object Init()
+ {
+ this.engine = this.AxApplicationMgr.GetEngine();
+ this.engine.PersistBreakpoints = false;
+ this.AxApplicationMgr.IsEditor = true;
+ this.AxApplicationMgr.LoginOnStart = false;
+ this.AxApplicationMgr.Start();
+ return this.AxApplicationMgr;
+ }
+
+ private SequenceFile GetFile(string path)
+ {
+ return null;
+ }
+
+ public object StartSequence(string filePath, string modelPath)
+ {
+ this.testSeqFile = filePath;
+
+ this.modeSeq = this.engine.GetSequenceFileEx(modelPath);
+ this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 107, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
+ this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
+ return execution;
+ }
+
+ public T GetFileGlobalValue<T>(string key, int option)
+ {
+ if (typeof(T) == typeof(bool))
+ {
+ return (T)(object)context?.FileGlobals?.GetValBoolean(key, option);
+ }
+ else if (typeof(T) == typeof(string))
+ {
+ return (T)(object)context?.FileGlobals?.GetValString(key, option);
+ }
+ else if (typeof(T) == typeof(int))
+ {
+ return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
+ }
+ else if (typeof(T) == typeof(double))
+ {
+ return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
+ }
+ return default(T);
+ }
+
+ public T GetStationGlobalValue<T>(string key, int option)
+ {
+ if (typeof(T) == typeof(bool))
+ {
+ return (T)(object)engine?.Globals?.GetValBoolean(key, option);
+ }
+ else if (typeof(T) == typeof(string))
+ {
+ return (T)(object)engine?.Globals?.GetValString(key, option);
+ }
+ else if (typeof(T) == typeof(int))
+ {
+ return (T)(object)engine?.Globals?.GetValNumber(key, option);
+ }
+ else if (typeof(T) == typeof(double))
+ {
+ return (T)(object)engine?.Globals?.GetValNumber(key, option);
+ }
+ else if (typeof(T) == typeof(float))
+ {
+ return (T)(object)engine?.Globals?.GetValNumber(key, option);
+ }
+ return default(T);
+ }
+
+ public void SetFileGlobalValue<T>(string key, int option, T value)
+ {
+ if (value is bool bVal)
+ {
+ context?.FileGlobals?.SetValBoolean(key, option, bVal);
+ }
+ else if (value is string sVal)
+ {
+ context?.FileGlobals?.SetValString(key, option, sVal);
+ }
+ else if (value is int iVal)
+ {
+ context?.FileGlobals?.SetValNumber(key, option, iVal);
+ }
+ else if (value is double dVal)
+ {
+ context?.FileGlobals?.SetValNumber(key, option, dVal);
+ }
+ else if (value is float fVal)
+ {
+ context?.FileGlobals?.SetValNumber(key, option, fVal);
+ }
+ }
+
+ public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
+ {
+ PropertyObject obj = null;
+ if (inContext)
+ {
+ obj = context?.StationGlobals;
+ }
+ else
+ {
+ obj = engine?.Globals;
+ }
+
+ if (value is bool bVal)
+ {
+ obj?.SetValBoolean(key, option, bVal);
+ }
+ else if (value is string sVal)
+ {
+ obj?.SetValString(key, option, sVal);
+ }
+ else if (value is int iVal)
+ {
+ obj?.SetValNumber(key, option, iVal);
+ }
+ else if (value is double dVal)
+ {
+ obj?.SetValNumber(key, option, dVal);
+ }
+ else if (value is float fVal)
+ {
+ obj?.SetValNumber(key, option, fVal);
+ }
+ //engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+ }
+
+ public void CommitToDisk(bool option)
+ {
+ engine?.CommitGlobalsToDisk(option);
+ }
+
+ public bool WaitForExit()
+ {
+ return this.execution?.WaitForEndEx(-1, true, Type.Missing, null) == true;
+ }
+
+ public bool ReleaseSeqFile()
+ {
+ if (this.testSeq != null && this.engine?.ReleaseSequenceFileEx(this.testSeq, 4) == true)
+ {
+ Marshal.ReleaseComObject(this.testSeq);
+ this.testSeq = null;
+ }
+
+ if (this.modeSeq != null && this.engine?.ReleaseSequenceFileEx(this.modeSeq, 4) == true)
+ {
+ Marshal.ReleaseComObject(this.modeSeq);
+ this.modeSeq = null;
+ }
+ this.engine?.UnloadAllModules();
+ return this.testSeq == null && this.modeSeq == null;
+ }
+
+ public void SetContext(object context)
+ {
+ this.context = (SequenceContext)context;
+ }
+
+ public void Dispose()
+ {
+ AxApplicationMgr = null;
+ engine = null;
+ TestAppManager.Dispose();
+ }
+ }
+}
--
Gitblit v1.9.1