wenxiangchao
2026-11-02 fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f
Plugin.TestResult/DataTable.xaml.cs
@@ -1,10 +1,13 @@
using HMI.Core.Setting;
using 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;
            //将读到的条码写入到SN中
            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];
            //将读到的条码写入到SN中
            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("测试启动中,不允许Abort");
            //    return;
            //}
            var win = new RequirePasswordByUser("admin")
            {
                Owner = Window.GetWindow(this)
            };
            if (win.ShowDialog() != true)
            {
                return;
            }
            if (MsgBoxHelper2.WarnChoose("请确认老化仓在安全温度,水冷机吹水完成,单击OK按钮仓位回到初始化状态") != 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);
        }
    }
}