| | |
| | | using Plugin.TestResult_WPF.Constant; |
| | | using HMI.Util; |
| | | using Plugin.TestResult_WPF.Constant; |
| | | using Plugin.TestResult_WPF.Model; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.IO; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | public SingleCell(string parentName, int index, int maxSize) |
| | | public SingleCell(string parentName, int index, int maxSize, string iniFile) |
| | | { |
| | | this.parentName = parentName; |
| | | this.index = index; |
| | | this.maxSize = maxSize; |
| | | this.countIniPath = iniFile; |
| | | DataContext = this; |
| | | InitializeComponent(); |
| | | LoadProbeCount(); |
| | | } |
| | | |
| | | private string _parentName; |
| | |
| | | } |
| | | } |
| | | |
| | | public string title => $"{parentName}{index + 1}"; |
| | | private bool cellIsDisabled; |
| | | |
| | | public bool CellIsDisabled |
| | | { |
| | | get { return cellIsDisabled; } |
| | | set |
| | | { |
| | | RaiseAndSetIfchanged(ref cellIsDisabled, value); |
| | | } |
| | | } |
| | | |
| | | |
| | | public string title => $"{parentName}-{index + 1}"; |
| | | |
| | | private string _status = CommonStatus.WAITING; |
| | | |
| | |
| | | |
| | | private ConcurrentQueue<Info> queue = new ConcurrentQueue<Info>(); |
| | | |
| | | private ObservableCollection<Info> _infos; |
| | | private ObservableCollection<Info> _infos = new ObservableCollection<Info>(); |
| | | |
| | | public ObservableCollection<Info> infos |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private string countIniPath; |
| | | /// <summary> |
| | | /// 探针寿命 |
| | | /// </summary> |
| | | private int probeCount; |
| | | public int ProbeCount |
| | | { |
| | | get => probeCount; |
| | | set |
| | | { |
| | | RaiseAndSetIfchanged(ref probeCount, value); |
| | | } |
| | | } |
| | | |
| | | public void LoadProbeCount() |
| | | { |
| | | string temp = IniFileHelper.ReadIniData($"{title}", "ProbeCount", "", countIniPath); |
| | | if (!string.IsNullOrEmpty(temp)) |
| | | { |
| | | int count = Convert.ToInt32(temp); |
| | | ProbeCount = count; |
| | | } |
| | | } |
| | | |
| | | private void UpdateProbeCount(int count) |
| | | { |
| | | ProbeCount = count; |
| | | IniFileHelper.WriteIniData($"{title}", "ProbeCount", ProbeCount.ToString(), countIniPath); |
| | | if (window != null) window.UpdateProbeCount(ProbeCount); |
| | | } |
| | | |
| | | private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
| | | { |
| | | if (window == null) |
| | | { |
| | | window = new InfoWindow(title, infos); |
| | | window = new InfoWindow(title, infos, electricChart, ProbeCount); |
| | | window.Closed += Window_Closed; |
| | | window.ClearProbeCountEvent += Window_ClearProbeCountEvent; |
| | | window.Owner = Window.GetWindow(this); |
| | | window.Show(); |
| | | } |
| | |
| | | { |
| | | window.Activate(); |
| | | } |
| | | } |
| | | |
| | | private void Window_ClearProbeCountEvent(object sender, EventArgs e) |
| | | { |
| | | UpdateProbeCount(0); |
| | | } |
| | | |
| | | private void Window_Closed(object sender, EventArgs e) |
| | |
| | | public void SetStatus(string status) |
| | | { |
| | | this.status = status; |
| | | } |
| | | |
| | | public void SetInfos(List<Info> infos) |
| | | { |
| | | this.infos = new ObservableCollection<Info>(infos); |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | } |
| | | |
| | | public void SetInfos(string[,] infos) |
| | | { |
| | | var data = new ObservableCollection<Info>(); |
| | | for (int i = 0; i < infos.GetLength(0); i++) |
| | | if (status == "testing") |
| | | { |
| | | data.Add(new Info |
| | | { |
| | | step = infos[i, 0], |
| | | result = infos[i, 1] |
| | | }); |
| | | UpdateProbeCount(ProbeCount + 1); |
| | | } |
| | | this.infos = data; |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | } |
| | | |
| | | public void SetInfos(Info info) |
| | |
| | | if (queue.Count >= maxSize) |
| | | { |
| | | queue.TryDequeue(out var first); |
| | | queue.Enqueue(info); |
| | | this.infos = new ObservableCollection<Info>(queue); |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | } |
| | | queue.Enqueue(info); |
| | | var list = new ObservableCollection<Info>(queue); |
| | | this.infos = list; |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | else |
| | | { |
| | | queue.Enqueue(info); |
| | | if (window != null) |
| | | { |
| | | window.Dispatcher.Invoke(() => |
| | | { |
| | | this.infos.Add(info); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | Dispatcher.Invoke(() => |
| | | { |
| | | this.infos.Add(info); |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public void ClearInfo() |
| | |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | } |
| | | |
| | | public void SetInfos(string step, string result) |
| | | private Chart electricChart = new Chart("电流曲线(A)", false, 20); |
| | | public void AddElectricData(double data) |
| | | { |
| | | if (queue.Count >= maxSize) |
| | | electricChart.AddData(data); |
| | | } |
| | | |
| | | public void ClearElectricData() |
| | | { |
| | | electricChart.Clear(); |
| | | } |
| | | |
| | | public void SaveElectricDataToCSV(string filePath) |
| | | { |
| | | try |
| | | { |
| | | queue.TryDequeue(out var info); |
| | | List<double> datas = electricChart?.GetSingleData(); |
| | | |
| | | FileInfo fi = new FileInfo(filePath); |
| | | if (!fi.Directory.Exists) |
| | | { |
| | | fi.Directory.Create(); //文件不存在,创建文件 |
| | | } |
| | | |
| | | using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) |
| | | using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8)) |
| | | { |
| | | string title = "电流数据(A)"; |
| | | sw.WriteLine(title); |
| | | if (datas != null) |
| | | { |
| | | for (int i = 0; i < datas.Count; i++) |
| | | { |
| | | sw.WriteLine(datas[i].ToString()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | queue.Enqueue(new Info() { step = step, result = result }); |
| | | var list = new ObservableCollection<Info>(queue); |
| | | this.infos = list; |
| | | if (window != null) window.UpdateSource(this.infos); |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.ToString()); |
| | | } |
| | | } |
| | | } |
| | | } |