/// <summary> /// 监控仪表电压和电流 /// </summary> /// <param name="timeout">查询时间间隔,单位ms</param> public void MonitorInstrument(int timeout, DateTime time) { Voltages.Clear(); Currents.Clear(); if (!t6332A.Open()) { return; } //if (!t6942A.Open()) // return; CsvHelper csvHelper = new CsvHelper($@"D:\HTOL\{time:yyyyMMddHHmmss}\InstrumentData.csv"); csvHelper.WirteLine(new string[] { "Time(MMdd:HH:mm:ss)", "CH1_Voltage(V)", "CH2_Voltage(V)", "CH3_Voltage(V)", "CH1_Current(A)", "CH2_Current(A)", "CH3_Current(A)" }); isMonitorInstrument = true; while (isMonitorInstrument) { var now = DateTime.Now; double[] voltages = t6332A.QueryVoltage(); Voltages.Add(new GraphModel { DateTime = now, Value = voltages[0] }); double[] currents = t6332A.QueryCurrent(); Currents.Add(new GraphModel { DateTime = now, Value = currents[0] }); csvHelper.WirteLine(new string[] { now.ToString("MMdd:HH:mm:ss"), voltages[0].ToString("0.000"), voltages[1].ToString("0.000"), voltages[2].ToString("0.000"), currents[0].ToString("0.000"), currents[1].ToString("0.000"), currents[2].ToString("0.000"), }); SetAxisLimits(now); //lets only use the last 15 values if (Voltages.Count > 120) { Voltages.RemoveAt(0); } if (Currents.Count > 120) { Currents.RemoveAt(0); } Thread.Sleep(timeout); } }
private void Bg2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (powerOn == false && meterConnected == true) { if (pass == true) { ID.Text = SerialNumber.Text; Test480.Text = "480V Test Passed"; DateTime aDate = DateTime.Now; //string time = aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"); string result = "Pass"; string result240 = "Pass"; string result480 = "Pass"; string barCode = SerialNumber.Text; string supplierCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 1); string dateCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 2); string serialNumber = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 3); string partNumber = _stringHelper.RemoveLaggingChars(SerialNumber.Text); string leadsCover = "Yes"; DatabaseHelper.AddData(barCode, partNumber, supplierCode, dateCode, serialNumber, leadsCover, result240, dcVoltage1.ToString(), result480, dcVoltage2.ToString(), result, aDate); Fail.Text = ""; Pass.Text = "PASS"; Pass.Foreground = Brushes.Green; } if (fail == true) { ID.Text = SerialNumber.Text; Test480.Text = "480V Test Failed"; DateTime aDate = DateTime.Now; //string time = aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"); string result = "Fail"; string result240 = "Pass"; string result480 = "Fail"; string barCode = SerialNumber.Text; string supplierCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 1); string dateCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 2); string serialNumber = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 3); string partNumber = _stringHelper.RemoveLaggingChars(SerialNumber.Text); string leadsCover = "Yes"; DatabaseHelper.AddData(barCode, partNumber, supplierCode, dateCode, serialNumber, leadsCover, result240, dcVoltage1.ToString(), result480, dcVoltage2.ToString(), result, aDate); Pass.Text = ""; Fail.Text = "FAIL"; Fail.Foreground = Brushes.Red; } if (fail240 == true) { ID.Text = SerialNumber.Text; Test240.Text = "240V Test Failed"; DateTime aDate = DateTime.Now; //string time = aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"); string result = "Fail"; string result240 = "Fail"; string result480 = ""; string barCode = SerialNumber.Text; string supplierCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 1); string dateCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 2); string serialNumber = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 3); string partNumber = _stringHelper.RemoveLaggingChars(SerialNumber.Text); string leadsCover = "Yes"; DatabaseHelper.AddData(barCode, partNumber, supplierCode, dateCode, serialNumber, leadsCover, result240, dcVoltage1.ToString(), result480, dcVoltage2.ToString(), result, aDate); Pass.Text = ""; Fail.Text = "FAIL"; Fail.Foreground = Brushes.Red; } if (coverOpen == true) { MessageBox.Show("Check if Cover is closed. Check if leads are connected. Check if Base is assembled properly."); DateTime aDate = DateTime.Now; //string time = aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"); string result = ""; string result240 = ""; string result480 = ""; string barCode = SerialNumber.Text; string supplierCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 1); string dateCode = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 2); string serialNumber = _stringHelper.RemoveLeadingChars(SerialNumber.Text, 3); string partNumber = _stringHelper.RemoveLaggingChars(SerialNumber.Text); string leadsCover = "No"; dcVoltage1 = double.NaN; DatabaseHelper.AddData(barCode, partNumber, supplierCode, dateCode, serialNumber, leadsCover, result240, dcVoltage1.ToString(), result480, dcVoltage2.ToString(), result, aDate); } SerialNumber.Text = ""; IsOn.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); IsOn.Text = "Power ON"; form = null; base_ = null; while (Math.Abs(myDmm.Measure()) > 5.0) { } Measage1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); Measage2.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); } else if (powerOn == true) { Test240.Text = ""; Test480.Text = ""; Voltages.Clear(); Voltages2.Clear(); SerialNumber.Text = ""; form = null; base_ = null; while (Math.Abs(myDmm.Measure()) > 5.0) { } Measage1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); Measage2.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); } else if (meterConnected == false) { IsOn.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); IsOn.Text = "Power ON"; SerialNumber.Text = ""; Test240.Text = ""; Test480.Text = ""; Voltages.Clear(); Voltages2.Clear(); form = null; base_ = null; } else if (power480 == false) { SerialNumber.Text = ""; Voltages.Clear(); Voltages2.Clear(); IsOn.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); IsOn.Text = "Power ON"; MessageBox.Show("480V POWER UP FAIL: " + power.fail); form = null; base_ = null; while (Math.Abs(myDmm.Measure()) > 5.0) { } Measage1.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); Measage2.Foreground = new System.Windows.Media.SolidColorBrush((Color)ColorConverter.ConvertFromString("#C0C0C0")); } }
private void SerialNumber_TextChanged(object sender, TextChangedEventArgs e) { if (SerialNumber.Text.Length >= 26) { ID.Text = ""; Fail.Text = ""; Pass.Text = ""; Test240.Text = ""; Test480.Text = ""; fail = false; pass = false; fail240 = false; coverOpen = false; dcVoltage1 = double.NaN; dcVoltage2 = double.NaN; Application.Current.Dispatcher.Invoke(() => Voltages.Clear()); Application.Current.Dispatcher.Invoke(() => Voltages2.Clear()); string trim = SerialNumber.Text.Trim(); if (_stringHelper.NumberComplete(trim) == true) { string baseNumber = _stringHelper.RemoveLaggingChars(SerialNumber.Text); result1 = DatabaseHelper.SetForm_Base(baseNumber); foreach (var x in result1) { form = x.form_no; base_ = x.base_; } if (form != null && base_ != null) { Launch(); } else { MessageBox.Show("INVAILD BASE NUMBER"); SerialNumber.Text = ""; form = null; base_ = null; } } else if (trim.Length >= 28) { MessageBox.Show("INVAILD BASE NUMBER"); SerialNumber.Text = ""; } } }