| | |
| | | using HMI.Core.Util; |
| | | using HMI.Core.Entity; |
| | | using HMI.Core.Manager; |
| | | using HMI.Core.Setting; |
| | | using HMI.Core.Util; |
| | | using HMI.Util; |
| | | using NationalInstruments.TestStand.Interop.API; |
| | | using NPOI.HSSF.UserModel; |
| | | using NPOI.SS.Formula.Functions; |
| | | using NPOI.SS.UserModel; |
| | | using Plugin.TsExecution.Entity; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | |
| | | |
| | | protected void Set([CallerMemberName] string name = null) |
| | | { |
| | | |
| | | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | #endregion |
| | | private bool isLoadOK = false; |
| | | private int index; |
| | | private string CountIniPath; |
| | | |
| | | private string status = "Ready"; |
| | | |
| | | private ScreenTouch[] screens; |
| | | private ScreenGrid screenGrid; |
| | | |
| | | public string Status |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private double passNum; |
| | | public double PassNum |
| | | private int passNum; |
| | | public int PassNum |
| | | { |
| | | get => passNum; |
| | | private set { Set(ref passNum, value); } |
| | | } |
| | | |
| | | private double failNum; |
| | | public double FailNum |
| | | private int failNum; |
| | | public int FailNum |
| | | { |
| | | get => failNum; |
| | | private set { Set(ref failNum, value); } |
| | |
| | | set { Set(ref barcode, value); } |
| | | } |
| | | |
| | | private string model = string.Empty; |
| | | public string Model |
| | | { |
| | | get { return model; } |
| | | set { Set(ref model, value); } |
| | | } |
| | | |
| | | private string elapseTime = "00:00:00"; |
| | | public string ElapseTime |
| | | { |
| | |
| | | if (value == "Start Timing") |
| | | { |
| | | this.refreshTimer.Enabled = true; |
| | | TimeNow = DateTime.Now; |
| | | TestStartTime = DateTime.Now; |
| | | StepStartTime = DateTime.Now; |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private string socketName = string.Empty; |
| | | public string SocketName |
| | | { |
| | | get { return socketName; } |
| | | set |
| | | { |
| | | Set(ref socketName, value); |
| | | } |
| | | } |
| | | |
| | | private ObservableCollection<TestStep> _datasource = new ObservableCollection<TestStep>(); |
| | | public ObservableCollection<TestStep> Datasource |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private DateTime TimeNow = new DateTime(); |
| | | private DateTime TestStartTime = new DateTime(); |
| | | private DateTime StepStartTime = new DateTime(); |
| | | private TimeSpan TimeCount = new TimeSpan(); |
| | | |
| | | private Timer refreshTimer; |
| | | private System.Timers.Timer refreshTimer; |
| | | |
| | | private string currentStep = "等待扫码"; |
| | | private string currentStep = ""; |
| | | public string CurrentStep |
| | | { |
| | | get => currentStep; |
| | |
| | | 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 |
| | | { |
| | | get => isAutoMode; |
| | | set |
| | | { |
| | | Set(ref isAutoMode, value); |
| | | } |
| | | } |
| | | |
| | | public SingleControl(int Index, string CountIniPath, int probeWarn) |
| | | { |
| | | this.CountIniPath = CountIniPath; |
| | | DataContext = this; |
| | | this.CountIniPath = CountIniPath; |
| | | this.index = Index; |
| | | ProbeWarn = probeWarn; |
| | | |
| | | refreshTimer = new Timer() |
| | | refreshTimer = new System.Timers.Timer() |
| | | { |
| | | Interval = 100 |
| | | }; |
| | | refreshTimer.Elapsed += RefreshTimer_Elapsed; |
| | | ReadProbeCount(); |
| | | ReadCounter(); |
| | | InitializeComponent(); |
| | | RefreshProbeCount(null); |
| | | try |
| | | { |
| | | var value = ParameterManager.GetCommonParameterByName("AutoTestMode"); |
| | | IsAutoMode = bool.Parse(value.Value); |
| | | } |
| | | catch |
| | | { |
| | | IsAutoMode = true; |
| | | } |
| | | //if (ProbeWarn > 0) |
| | | //{ |
| | | // probeWarnPanel.Visibility = Visibility.Visible; |
| | |
| | | |
| | | //AddTestData("1", "1", "1", "1", "1", "1", "1"); |
| | | |
| | | TimeCount = DateTime.Now - TimeNow; |
| | | TimeCount = DateTime.Now - TestStartTime; |
| | | elapseTime = string.Format("{0:00}:{1:00}:{2:00}", TimeCount.Hours, TimeCount.Minutes, TimeCount.Seconds); |
| | | Set("ElapseTime"); |
| | | Set("TestInfo"); |
| | |
| | | Unit = unit, |
| | | Result = Status |
| | | }; |
| | | Dispatcher.BeginInvoke(new Action(() => |
| | | table.Dispatcher.Invoke(new Action(() => |
| | | { |
| | | var now = DateTime.Now; |
| | | var span = now - StepStartTime; |
| | | StepStartTime = now; |
| | | data.ConsumeTime = $"{(span.TotalMilliseconds / 1000d).ToString("F2")}s"; |
| | | Datasource.Add(data); |
| | | table.ScrollIntoView(data); |
| | | })); |
| | |
| | | if (result == true) |
| | | { |
| | | PassNum += 1; |
| | | //Interlocked.Increment(ref passNum); |
| | | //Set("PassNum"); |
| | | } |
| | | else if (result == false) |
| | | { |
| | | FailNum += 1; |
| | | //Interlocked.Increment(ref failNum); |
| | | //Set("FailNum"); |
| | | } |
| | | |
| | | TotalNum = PassNum + FailNum; |
| | | if (TotalNum != 0) |
| | | { |
| | | PassRate = (PassNum / TotalNum); |
| | | PassRate = ((double)PassNum / TotalNum); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | Set("NumInfo"); |
| | | 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() |
| | |
| | | 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() |
| | |
| | | SequenceFileContext?.StationGlobals.SetValBoolean($"StationState.IsContinue_{index}", 1, true); |
| | | pausePanel.Visibility = Visibility.Collapsed; |
| | | break; |
| | | case "scannerSetting": |
| | | //ScannerSetting setting = new ScannerSetting() |
| | | //{ |
| | | // Owner = Window.GetWindow(this) |
| | | //}; |
| | | //setting.Open(true, $"Socket{index}", CountIniPath); |
| | | ShowScannerPanel(); |
| | | break; |
| | | case "scannerOkBtn": |
| | | SendSnr2Ts(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | public void ShowScannerPanel() |
| | | { |
| | | //scannerPanel.Visibility = Visibility.Visible; |
| | | } |
| | | |
| | | private void SendSnr2Ts() |
| | | { |
| | | |
| | | } |
| | | |
| | | private void pausePanel_Loaded(object sender, RoutedEventArgs e) |
| | | { |
| | | var can = pausePanel; |
| | | var modal = visualModal; |
| | | Canvas.SetLeft(modal, (pausePanel.ActualWidth - visualModal.ActualWidth) / 2); |
| | | Canvas.SetTop(modal, (pausePanel.ActualHeight - visualModal.ActualHeight) / 2); |
| | | if (sender == pausePanel) |
| | | { |
| | | var can = pausePanel; |
| | | var modal = visualModal; |
| | | Canvas.SetLeft(modal, (pausePanel.ActualWidth - visualModal.ActualWidth) / 2); |
| | | Canvas.SetTop(modal, (pausePanel.ActualHeight - visualModal.ActualHeight) / 2); |
| | | } |
| | | else |
| | | { |
| | | //var can = scannerPanel; |
| | | //var modal = scannerVisualModal; |
| | | //Canvas.SetLeft(modal, (scannerPanel.ActualWidth - scannerVisualModal.ActualWidth) / 2); |
| | | //Canvas.SetTop(modal, (scannerPanel.ActualHeight - scannerVisualModal.ActualHeight) / 2); |
| | | } |
| | | } |
| | | |
| | | public void RefreshScreen(int[][] configs) |
| | | { |
| | | //foreach (UIElement item in canvas.Children) |
| | | //{ |
| | | // if (item is ScreenTouch) |
| | | // { |
| | | // canvas.Children.Remove(item); |
| | | // } |
| | | //} |
| | | screenContainer.Child = null; |
| | | |
| | | |
| | | screenGrid = new ScreenGrid(1, configs.Length); |
| | | |
| | | screens = new ScreenTouch[configs.Length]; |
| | | |
| | | int space = 2 * (screens.Length + 1); |
| | | for (int i = 0; i < configs.Length; i++) |
| | | { |
| | | var screen = new ScreenTouch(configs[i][0], configs[i][1]) |
| | | { |
| | | Width = Math.Max((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length, 0), |
| | | Height = Math.Max((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length / 16 * 9, 0) |
| | | }; |
| | | screens[i] = screen; |
| | | screenGrid.AddScreen(screen, 0, i); |
| | | } |
| | | screenContainer.Child = screenGrid; |
| | | |
| | | //canvas.Children.Add(screens[0]); |
| | | //Canvas.SetBottom(screens[0], 0); |
| | | //Canvas.SetRight(screens[0], 0); |
| | | //Panel.SetZIndex(screens[0], 999); |
| | | } |
| | | |
| | | public void DrawScreenPoint(int index, int x, int y) |
| | | { |
| | | 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) |
| | | { |
| | | if (product == null) |
| | | { |
| | | screenContainer.Child = null; |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | string screenSize = ProductManager.GetParameterByProductAndName(product.Name, "ScreenTouch")?.Value; |
| | | if (string.IsNullOrEmpty(screenSize)) |
| | | { |
| | | screenContainer.Child = null; |
| | | return; |
| | | } |
| | | string[] arr = screenSize.Split(';'); |
| | | int[][] configs = new int[arr.Length][]; |
| | | |
| | | for (int i = 0; i < arr.Length; i++) |
| | | { |
| | | string[] size = arr[i].Split(','); |
| | | configs[i] = new int[2] { int.Parse(size[0]), int.Parse(size[1]) }; |
| | | } |
| | | RefreshScreen(configs); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | TsExecution.logger.Error("RefreshProduct Failed.", ex); |
| | | screenContainer.Child = null; |
| | | } |
| | | } |
| | | |
| | | private void control_SizeChanged(object sender, SizeChangedEventArgs e) |
| | | { |
| | | if (screenGrid == null) |
| | | { |
| | | return; |
| | | } |
| | | //screenGrid.Height = tableHeader.ActualHeight - 2; |
| | | //screenGrid.Width = tableHeader.ActualHeight / 9 * 16 - 2; |
| | | |
| | | int space = 2 * (screens.Length + 1); |
| | | |
| | | for (int i = 0; i < screens.Length; i++) |
| | | { |
| | | var screen = screens[i]; |
| | | screen.Width = Math.Max(Math.Floor((tableHeader.ActualHeight / 9 * 16 - space) / screens.Length), 0); |
| | | screen.Height = Math.Max(Math.Floor(screen.Width / 16 * 9), 0); |
| | | } |
| | | } |
| | | |
| | | private void screenContainer_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
| | | { |
| | | if (e.ClickCount == 2) |
| | | { |
| | | new ScreenTouchWin(screens) |
| | | { |
| | | Owner = Window.GetWindow(this) |
| | | }.ShowDialog(); |
| | | } |
| | | } |
| | | } |
| | | } |