| | |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Manager; |
| | | using HMI.Core.Setting; |
| | | using HMI.Core.Util; |
| | | using HMI.UI.Util; |
| | | using HMI.Util; |
| | | using NationalInstruments.TestStand.Interop.API; |
| | | using Plugin.TsExecution.Entity; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Timers; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using Util.ManualDebug; |
| | | |
| | | namespace Plugin.TsExecution |
| | | { |
| | |
| | | Set(ref totalNum, value); |
| | | } |
| | | } |
| | | |
| | | public TsExecution parent { get; set; } |
| | | |
| | | private int passNum; |
| | | public int PassNum |
| | |
| | | set |
| | | { |
| | | Set(ref _probeCount, value); |
| | | try |
| | | { |
| | | if (ProbeWarn <= 0) probeCountAlarm.Visibility = Visibility.Collapsed; |
| | | else if (value >= ProbeWarn) probeCountAlarm.Visibility = Visibility.Visible; |
| | | else probeCountAlarm.Visibility = Visibility.Collapsed; |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public int ProbeWarn { get; private set; } |
| | | private int _probeWarn; |
| | | public int ProbeWarn |
| | | { |
| | | get => _probeWarn; |
| | | private set |
| | | { |
| | | Set(ref _probeWarn, value); |
| | | } |
| | | } |
| | | |
| | | private bool isAutoMode; |
| | | public bool IsAutoMode |
| | |
| | | Interval = 100 |
| | | }; |
| | | refreshTimer.Elapsed += RefreshTimer_Elapsed; |
| | | ReadProbeCount(); |
| | | ReadCounter(); |
| | | InitializeComponent(); |
| | | RefreshProbeCount(null); |
| | | try |
| | | { |
| | | var value = ParameterManager.GetCommonParameterByName("AutoTestMode"); |
| | | IsAutoMode = bool.Parse(value.Value); |
| | | IsAutoMode = value == null ? true : bool.Parse(value.Value); |
| | | } |
| | | catch |
| | | { |
| | |
| | | |
| | | public void IniTestData() |
| | | { |
| | | Datasource.Clear(); |
| | | Dispatcher.Invoke(() => |
| | | { |
| | | Datasource.Clear(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | this.WriteCounter(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从ini读取探针使用次数 |
| | | /// </summary> |
| | | private void ReadProbeCount() |
| | | { |
| | | try |
| | | { |
| | | var num = IniFileHelper.ReadIniData("Socket" + this.index.ToString(), "ProbeCount", "0", this.CountIniPath); |
| | | this.ProbeCount = int.Parse(num); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | this.ProbeCount = 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新探针使用次数 |
| | | /// </summary> |
| | | /// <param name="count"></param> |
| | | private void UpdateProbeCount(int count) |
| | | { |
| | | /// 写到配置文件 |
| | | IniFileHelper.WriteIniData("Socket" + this.index.ToString(), "ProbeCount", count.ToString(), this.CountIniPath); |
| | | ProbeCount = count; |
| | | |
| | | //if (ProbeWarn <= 0) probeCountAlarm.Visibility = Visibility.Collapsed; |
| | | //else if (count >= ProbeWarn) probeCountAlarm.Visibility = Visibility.Visible; |
| | | //else probeCountAlarm.Visibility = Visibility.Collapsed; |
| | | } |
| | | |
| | | private void WriteCounter() |
| | | { |
| | | IniFileHelper.WriteIniData("Socket" + this.index.ToString(), "Pass", |
| | |
| | | this.UpdateTestCounter(null); |
| | | } |
| | | |
| | | public void WriteToExcel(string path) |
| | | { |
| | | Dispatcher.Invoke(() => |
| | | { |
| | | try |
| | | { |
| | | string suffix = Path.GetExtension(path); |
| | | if (!string.Equals(".xlsx", suffix, StringComparison.OrdinalIgnoreCase) && |
| | | !string.Equals(".xls", suffix, StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | path = path.Replace(suffix, ".xls"); |
| | | } |
| | | |
| | | FileInfo fi = new FileInfo(path); |
| | | if (!fi.Directory.Exists) |
| | | { |
| | | fi.Directory.Create(); //文件不存在,创建文件 |
| | | } |
| | | List<string[]> rows = new List<string[]>(); |
| | | rows.Add(new string[] { "测试时间", "测试人", "测试设备", "条形码", "测试结果" }); |
| | | rows.Add(new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), UserInfo.User.Name, ParamSetting.StationName, Barcode, Status }); |
| | | rows.Add(new string[] { "项目名称", "测试参数", "测试值", "上限", "下限", "单位", "结果" }); |
| | | if (Datasource != null && Datasource.Count > 0) |
| | | { |
| | | foreach (var data in Datasource) |
| | | { |
| | | rows.Add(new string[] { data.Name, data.Step, data.Value, data.LimitUp, data.LimitDown, data.Unit, data.Result }); |
| | | } |
| | | } |
| | | ExcelHelper.ExportExcel(path, rows); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | TsExecution.logger.Error("Write CSV File Failed.", ex); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | public void WriteToCSV(string path) |
| | | { |
| | | Dispatcher.BeginInvoke(new Action(() => |
| | | Dispatcher.Invoke(() => |
| | | { |
| | | try |
| | | { |
| | |
| | | { |
| | | TsExecution.logger.Error("Write CSV File Failed.", ex); |
| | | } |
| | | })); |
| | | }); |
| | | } |
| | | |
| | | public void ShowPausePanel() |
| | |
| | | |
| | | private void SendSnr2Ts() |
| | | { |
| | | //try |
| | | //{ |
| | | // string snr = TbManualSnr.Text; |
| | | // SequenceFileContext?.StationGlobals.SetValString($"StationState.SN[{index}]", 1, snr); |
| | | // scannerPanel.Visibility = Visibility.Collapsed; |
| | | // TbManualSnr.Text = string.Empty; |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // ToastHelper.Error(ex.Message); |
| | | //} |
| | | |
| | | } |
| | | |
| | | private void pausePanel_Loaded(object sender, RoutedEventArgs e) |
| | |
| | | screens[index].DrawPoint(x, y); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绘图之前清空已有的 |
| | | /// </summary> |
| | | /// <param name="index"></param> |
| | | /// <param name="points"></param> |
| | | public void DrawScreenPoints(int index, int[][] points) |
| | | { |
| | | screens[index].DrawPoints(points); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绘图之前不清空已有的 |
| | | /// </summary> |
| | | /// <param name="index"></param> |
| | | /// <param name="points"></param> |
| | | public void DrawNewScreenPoints(int index, int[][] points) |
| | | { |
| | | screens[index].DrawNewPoints(points); |
| | | } |
| | | |
| | | public void ClearScreenPoint(int index) |
| | | { |
| | | screens[index].Clear(); |
| | | } |
| | | |
| | | public void RefreshProbeCount(ProductData product) |
| | | { |
| | | try |
| | | { |
| | | var num = IniFileHelper.ReadIniData($"Socket{this.index.ToString()}", "ProbeCount", "0", this.CountIniPath); |
| | | this.ProbeCount = int.Parse(num); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | this.ProbeCount = 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新探针使用次数 |
| | | /// </summary> |
| | | /// <param name="count"></param> |
| | | private void UpdateProbeCount(int count) |
| | | { |
| | | /// 写到配置文件 |
| | | IniFileHelper.WriteIniData("Socket" + this.index.ToString(), "ProbeCount", count.ToString(), this.CountIniPath); |
| | | ProbeCount = count; |
| | | } |
| | | |
| | | public void RefreshProduct(ProductData product) |
| | |
| | | }.ShowDialog(); |
| | | } |
| | | } |
| | | |
| | | private void control_PreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
| | | { |
| | | if (parent.EnableManualDebug) |
| | | { |
| | | ContextMenu contextMenu = new ContextMenu(); |
| | | contextMenu.Closed += ContextMenu_Closed; |
| | | var item = new MenuItem |
| | | { |
| | | IsCheckable = false, |
| | | Name = "manualDebugItem", |
| | | Header = this.lang("手动调试"), |
| | | }; |
| | | item.Click += Item_Click; ; |
| | | contextMenu.Items.Add(item); |
| | | this.ContextMenu = contextMenu; |
| | | } |
| | | else |
| | | { |
| | | |
| | | this.ContextMenu = null; |
| | | } |
| | | } |
| | | |
| | | private void Item_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | string manualDebugSeq = ParameterManager.GetCommonParameterByName("ManualDebugSeqPath")?.Value; |
| | | if (string.IsNullOrEmpty(manualDebugSeq)) |
| | | { |
| | | MsgBoxHelper2.Error("请先设置手动调试序列路径[ManualDebugSeqPath]!"); |
| | | return; |
| | | } |
| | | string modelPath = parent.tsModelPath; |
| | | var win = new ManualDebugWindow(manualDebugSeq, modelPath, false) |
| | | { |
| | | Title = $"工位{this.index}手动调试", |
| | | |
| | | Owner = Window.GetWindow(this), |
| | | OvenIndex = 0, |
| | | OvenName = "", |
| | | CellCount = parent.tsSockets.Count, |
| | | |
| | | CellIndex = this.index, |
| | | CellName = "", |
| | | }; |
| | | win.ShowDialog(); |
| | | } |
| | | |
| | | private void ContextMenu_Closed(object sender, RoutedEventArgs e) |
| | | { |
| | | this.ContextMenu = null; |
| | | } |
| | | } |
| | | } |