From 12e606635c42ea20f4b7c2bdda5204237a4b4c96 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 02 三月 2026 16:14:49 +0800
Subject: [PATCH] 优化
---
Plugin.TsExecution/TsExecution.xaml.cs | 379 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 258 insertions(+), 121 deletions(-)
diff --git a/Plugin.TsExecution/TsExecution.xaml.cs b/Plugin.TsExecution/TsExecution.xaml.cs
index 447b893..289d5be 100644
--- a/Plugin.TsExecution/TsExecution.xaml.cs
+++ b/Plugin.TsExecution/TsExecution.xaml.cs
@@ -3,15 +3,14 @@
using HMI.Core.Api;
using HMI.Core.Entity;
using HMI.Core.Manager;
+using HMI.Core.Setting;
using HMI.Core.Util;
using HMI.MQUtil;
-using HMI.UI;
using HMI.UI.Util;
using HMI.Util;
using log4net;
using NationalInstruments.TestStand.Interop.API;
using NationalInstruments.TestStand.Interop.UI.Ax;
-using Panuon.WPF.UI;
using Plugin.TsSupport;
using ScottPlot;
using ScottPlot.Plottables;
@@ -31,7 +30,7 @@
/// <summary>
/// UserControl1.xaml 鐨勪氦浜掗�昏緫
/// </summary>
- public partial class TsExecution : PluginControl
+ public partial class TsExecution : PluginMaskControl
{
#region TestStand浜嬩欢
/// <summary>
@@ -101,7 +100,18 @@
set
{
Set(ref selectedProduct, value);
+ CurrentProductModel = value?.Name;
SetTestSeqFile(value);
+ }
+ }
+
+ private string currentProductModel;
+ public string CurrentProductModel
+ {
+ get => currentProductModel;
+ set
+ {
+ Set(ref currentProductModel, value);
}
}
@@ -248,6 +258,8 @@
if (WriteIni("UI_CurrentWorkorder", value))
{
Set(ref currentWorkorder, value);
+ engine?.Globals.SetValString("StationState.WorkOrder", 1, value);
+ engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
}
}
}
@@ -277,6 +289,7 @@
DataContext = this;
GCTimer = new Timer();
InitializeComponent();
+
InitChart();
InitTsEngine();
//鍒濆鍖朤estStand寮曟搸
@@ -338,6 +351,25 @@
InitProducts();
CheckSqlHelper();
base.InitFinish();
+
+ if (ParamSetting.EnableAutoModel)
+ {
+ selectModelPanel.Visibility = Visibility.Collapsed;
+ autoModelPanel.Visibility = Visibility.Visible;
+ CurrentProductModel = string.Empty;
+ }
+
+ try
+ {
+ UserInfo user = UserInfo.User;
+ CurrentUserCode = user?.Code;
+ engine?.Globals.SetValString("StationState.OPID", 1, CurrentUserCode);
+ engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+ }
+ catch (Exception ex)
+ {
+ log.Warn("Get Login User Failed.", ex);
+ }
}
private void InitMQ()
@@ -476,49 +508,87 @@
private void PluginControl_Loaded(object sender, RoutedEventArgs e)
{
- new MaskWindow((WindowX)Window.GetWindow(this),
- (win) =>
+ ShowMask(() =>
+ {
+ try
{
- try
- {
- Dispatcher.Invoke(() =>
- {
- try
- {
- UserInfo user = UserInfo.User;
- CurrentUserCode = user?.Code;
- }
- catch (Exception ex)
- {
- log.Warn("Get Login User Failed.", ex);
- }
- });
- isLoadOK = true;
- if (AutoExecuteSeq) StartSequence();
- }
- catch (Exception ex)
- {
- log.Error("TsExecution Loaded Failed.", ex);
- MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.UserControlLoadFailed")}: {ex.Message}");
- }
+ //Dispatcher.Invoke(() =>
+ //{
- try
- {
- if (Environment.Version.ToString() != this.AxApplicationMgr.GetEngine().DotNetCLRVersion)
- this.GCTimer.Enabled = true;
- }
- catch (Exception ex)
- {
- log.Error("TsExecution GCTimer Start Failed", ex);
- MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.LoadFailed")}: {ex.Message}");
- }
-
- Dispatcher.Invoke(() =>
- {
- if (isLoadOK) Loaded -= PluginControl_Loaded;
- });
+ //});
+ isLoadOK = true;
+ if (AutoExecuteSeq) StartSequence();
}
- ).Info(LangUtil.Get("App.UsercontrolIsLoading"));
+ catch (Exception ex)
+ {
+ log.Error("TsExecution Loaded Failed.", ex);
+ MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.UserControlLoadFailed")}: {ex.Message}");
+ }
+
+ try
+ {
+ if (Environment.Version.ToString() != this.AxApplicationMgr.GetEngine().DotNetCLRVersion)
+ this.GCTimer.Enabled = true;
+ }
+ catch (Exception ex)
+ {
+ log.Error("TsExecution GCTimer Start Failed", ex);
+ MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.LoadFailed")}: {ex.Message}");
+ }
+
+ Dispatcher.Invoke(() =>
+ {
+ if (isLoadOK) Loaded -= PluginControl_Loaded;
+ });
+ }, (ex) =>
+ {
+ ToastHelper.Error("Loaded Failed.");
+ log.Error("Loaded Error.", ex);
+ }, null, LangUtil.Get("App.UsercontrolIsLoading"));
+
+ //new MaskWindow((WindowX)Window.GetWindow(this),
+ // (win) =>
+ // {
+ // try
+ // {
+ // Dispatcher.Invoke(() =>
+ // {
+ // try
+ // {
+ // UserInfo user = UserInfo.User;
+ // CurrentUserCode = user?.Code;
+ // }
+ // catch (Exception ex)
+ // {
+ // log.Warn("Get Login User Failed.", ex);
+ // }
+ // });
+ // isLoadOK = true;
+ // if (AutoExecuteSeq) StartSequence();
+ // }
+ // catch (Exception ex)
+ // {
+ // log.Error("TsExecution Loaded Failed.", ex);
+ // MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.UserControlLoadFailed")}: {ex.Message}");
+ // }
+
+ // try
+ // {
+ // if (Environment.Version.ToString() != this.AxApplicationMgr.GetEngine().DotNetCLRVersion)
+ // this.GCTimer.Enabled = true;
+ // }
+ // catch (Exception ex)
+ // {
+ // log.Error("TsExecution GCTimer Start Failed", ex);
+ // MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.LoadFailed")}: {ex.Message}");
+ // }
+
+ // Dispatcher.Invoke(() =>
+ // {
+ // if (isLoadOK) Loaded -= PluginControl_Loaded;
+ // });
+ // }
+ // ).Info(LangUtil.Get("App.UsercontrolIsLoading"));
}
private void RefershUI()
@@ -577,8 +647,8 @@
pass = Convert.ToInt32(IniFileHelper.ReadIniData("Count", "Pass", "0", CountIniPath));
fail = Convert.ToInt32(IniFileHelper.ReadIniData("Count", "Fail", "0", CountIniPath));
var fontSize = Convert.ToDouble(IniFileHelper.ReadIniData("Config", "TableFontSize", "12", CountIniPath));
- this.Resources["tableFontSize"] = fontSize;
- CbFontSize.SelectedItem = fontSize;
+ this.Resources["tableFontSize"] = 20d;
+ //CbFontSize.SelectedItem = fontSize;
}
private string csvDir;
@@ -791,13 +861,11 @@
{
value = ParameterManager.GetCommonParameterByName("UI_CurrentWorkorder");
- currentWorkorder = value.Value;
- Set("CurrentWorkorder");
+ CurrentWorkorder = value.Value;
}
catch
{
- currentWorkorder = string.Empty;
- Set("CurrentWorkorder");
+ CurrentWorkorder = string.Empty;
}
try
@@ -814,22 +882,13 @@
{
}
- try
- {
-
- value = ParameterManager.GetCommonParameterByName("TS_DataLogPath");
- dataLogPath = value.Value;
- }
- catch
- {
- dataLogPath = Path.Combine(PathHelper.ConfigFolder, "DataBoard");
- }
+ dataLogPath = ParamSetting.DataLogFolder;
try
{
value = ParameterManager.GetCommonParameterByName("TsModelPath");
- tsModelPath = value.Value;
+ tsModelPath = value?.Value ?? @"C:\Users\Public\Documents\National Instruments\TestStand 2020 (64-bit)\Components\Models\ParallelModel.seq";
}
catch
{
@@ -861,6 +920,11 @@
foreach (var ts in tsSockets)
{
ts?.SequenceFileContext?.StationGlobals.SetValBoolean($"SystemSetting.{name}", 1, value);
+ if (ts?.SequenceFileContext?.Sequence != null)
+ {
+ ts.SequenceFileContext.Sequence.FailureAction =
+ value ? FailureActions.FailureAction_None : FailureActions.FailureAction_GotoCleanup;
+ }
}
return true;
}
@@ -963,53 +1027,93 @@
private void StartSequence()
{
if (!isLoadOK) return;
- //MaskWindow mask = new MaskWindow();
- try
- {
- engine?.Globals.SetValString("StationState.ProductModel", 1, SelectedProduct?.Name);
- engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
- this.modeSeq = this.engine.GetSequenceFileEx(tsModelPath);
- this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 2, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
- this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
- IsTesting = true;
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(() =>
- {
- log.Error("Start Sequence Failed.", ex);
- MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.StartSequenceFail")}: {ex.Message}");
- });
- }
- finally
- {
+ if (ParamSetting.EnableAutoModel)
+ {
+ try
+ {
+ var path = ParameterManager.GetCommonParameterByName<string>("CommonMainSeq", "");
+ if (string.IsNullOrEmpty(path))
+ {
+ Dispatcher.Invoke(() =>
+ {
+ MsgBoxHelper.Error(this, $"璇峰厛璁剧疆CommonMainSeq鍙傛暟");
+ });
+ return;
+ }
+ this.testSeqFile = path;
+ this.modeSeq = this.engine.GetSequenceFileEx(tsModelPath);
+ this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 2, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
+ this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
+ IsTesting = true;
+ }
+ catch (Exception ex)
+ {
+ Dispatcher.Invoke(() =>
+ {
+ log.Error("Start Sequence Failed.", ex);
+ MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.StartSequenceFail")}: {ex.Message}");
+ });
+ }
+ }
+ else
+ {
+ //MaskWindow mask = new MaskWindow();
+ try
+ {
+ engine?.Globals.SetValString("StationState.ProductModel", 1, CurrentProductModel);
+ engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
+ this.modeSeq = this.engine.GetSequenceFileEx(tsModelPath);
+ this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 2, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
+ this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
+ IsTesting = true;
+ }
+ catch (Exception ex)
+ {
+ Dispatcher.Invoke(() =>
+ {
+ log.Error("Start Sequence Failed.", ex);
+ MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.StartSequenceFail")}: {ex.Message}");
+ });
+ }
+ finally
+ {
+
+ }
}
}
public void StopSequenceClick()
{
- new MaskWindow((WindowX)Window.GetWindow(this),
- (win) =>
- {
- try
- {
- bool stoped = StopSequence();
- if (stoped)
- {
- IsTesting = false;
- }
- }
- finally
- {
- Dispatcher.Invoke(() =>
- {
+ ShowMask(() =>
+ {
+ bool stoped = StopSequence();
+ if (stoped)
+ {
+ IsTesting = false;
+ }
+ }, null, null, LangUtil.Get("App.SequenceIsStopping"));
+ //new MaskWindow((WindowX)Window.GetWindow(this),
+ // (win) =>
+ // {
+ // try
+ // {
+ // bool stoped = StopSequence();
+ // if (stoped)
+ // {
+ // IsTesting = false;
+ // }
+ // }
+ // finally
+ // {
+ // Dispatcher.Invoke(() =>
+ // {
- win.Close();
- });
- }
- }
- ).Info(LangUtil.Get("App.SequenceIsStopping"));
+ // win.Close();
+ // });
+ // }
+ // }
+ // ).Info(LangUtil.Get("App.SequenceIsStopping"));
}
/// <summary>
@@ -1070,21 +1174,28 @@
private void StartClick()
{
- new MaskWindow(Window.GetWindow(this),
- (win) =>
- {
- try
- {
- StartSequence();
- }
- finally
- {
- win.Dispatcher.Invoke(() =>
- {
- win.Close();
- });
- }
- }).Info(LangUtil.Get("Ts.SequenceIsStarting"));
+ ShowMask(() =>
+ {
+ StartSequence();
+ }, null, null, LangUtil.Get("Ts.SequenceIsStarting"));
+ //new MaskWindow(Window.GetWindow(this),
+ // (win) =>
+ // {
+ // try
+ // {
+ // StartSequence();
+ // }
+ // catch (Exception ex) {
+
+ // }
+ // finally
+ // {
+ // win.Dispatcher.Invoke(() =>
+ // {
+ // win.Close();
+ // });
+ // }
+ // }).Info(LangUtil.Get("Ts.SequenceIsStarting"));
}
/// <summary>
@@ -1148,7 +1259,7 @@
{
var time = DateTime.Now;
string status = this.tsSockets[index].Status == "Passed" ? "PASS" : "FAIL";
- string csvPath = Path.Combine(csvDir, SelectedProduct?.Name ?? "鏈煡浜у搧", time.ToString("yyyyMMdd"), status, $"{this.tsSockets[index].Barcode}-{time.ToString("HHmmss")}.csv");
+ string csvPath = Path.Combine(csvDir, CurrentProductModel ?? "鏈煡浜у搧", time.ToString("yyyyMMdd"), status, $"{this.tsSockets[index].Barcode}-{time.ToString("HHmmss")}.csv");
this.tsSockets[index].WriteToCSV(csvPath);
}
@@ -1158,7 +1269,7 @@
var socket = this.tsSockets[index];
var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string snr = socket.Barcode;
- string model = SelectedProduct?.Name;
+ string model = CurrentProductModel;
List<string> sqls = new List<string>();
foreach (var data in socket.Datasource)
@@ -1284,7 +1395,15 @@
this.tsSockets[index].ShowPausePanel();
break;
case 10033:
- ShowAlarm(strData);
+ var alarm = new AlarmText
+ {
+ VirtualId = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
+ AlarmInfo = strData
+ };
+ ShowAlarm(alarm);
+ break;
+ case 10034:
+ CurrentProductModel = strData;
break;
case 10099:
break;
@@ -1293,10 +1412,10 @@
}
}
- private void ShowAlarm(string info)
+ private void ShowAlarm(AlarmText alarm)
{
- AlarmShowHelper.ShowAlarm(info);
- mSMQHelper.Send("Alarm", $"ATE娴嬭瘯 {info}");
+ AlarmShowHelper.ShowAlarm(alarm);
+ mSMQHelper.Send("Alarm", $"ATE娴嬭瘯 {alarm.AlarmInfo}");
}
/// <summary>
@@ -1461,5 +1580,23 @@
{
}
}
+
+ private void Label_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ //workOrderEditor.Focus();
+ //workOrderEditor.IsEditing = true;
+ if (RequirePassword() == true)
+ {
+ var win = new WorkOrderWin
+ {
+ WorkOrder = CurrentWorkorder,
+ Owner = Window.GetWindow(this)
+ };
+ if (win.ShowDialog() == true)
+ {
+ CurrentWorkorder = win.WorkOrder;
+ }
+ }
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.1