//List<string> _write_line = new List<string>(); private async void btn_board_v123_Click(object sender, RoutedEventArgs e) { Button obj = (Button)sender; vm.BoardTable_V123 = int.Parse(obj.Tag.ToString()); #region MultiMeter Setting GPIB_CMD myGPIB = new GPIB_CMD(0, 22); //MultiMeter GPIB Setting string mystring = "MEAS:VOLT:DC? 50,0.0001"; //MultiMeter GPIB Read Voltage Command Byte[] mybytes = System.Text.Encoding.Default.GetBytes(mystring); #endregion vm.port_PD = new SerialPort(vm.Selected_Comport, 115200, Parity.None, 8, StopBits.One); List <List <string> > _List_Bear_Say = new List <List <string> >(); for (int dac = initial_dac; dac <= 60000; dac += 10000) { if (vm.BoardTable_V123 == 1) { vm.WriteDac("1", "D", dac.ToString() + ",0,0"); //V1 Write Dac } else if (vm.BoardTable_V123 == 2) { vm.WriteDac("1", "D", "0," + dac.ToString() + ",0"); //V2 Write Dac } else { vm.WriteDac("1", "D", "0,0," + dac.ToString()); //V3 Write Dac } await vm.AccessDelayAsync(vm.Int_Write_Delay); vm.port_PD.Close(); myGPIB.Write(mybytes); string volt = myGPIB.Read(); if (vm.List_BoardTable.Count > 0) { double volt_before = 0; if (vm.BoardTable_V123 == 3) { List <double> list_voltage = new List <double>(); List <int> list_dac = new List <int>(); double final_voltage = 0; for (int c = 0; c < 1; c++) { if (vm.isStop) { break; } if (!vm.Bool_Gauge[c]) { continue; } string board_id = vm.BoardTable_SelectedBoard; string path = @"\\192.168.2.3\tff\Data\BoardCalibration\UFA\" + board_id + "-boardtable.txt"; if (!File.Exists(path)) { vm.Show_Bear_Window("UFV Board table is not exist", false, "String"); return; } StreamReader str = new StreamReader(path); str.ReadLine(); int count = 0; while (!vm.isStop) //Read board v3 data { string[] board_read = str.ReadLine().Split(','); //(一行一行讀取) if (board_read.Length < 1) { break; } string v3_table_voltage = board_read[0]; int v3_table_dac = int.Parse(board_read[1]); list_voltage.Add(Convert.ToDouble(v3_table_voltage)); list_dac.Add(v3_table_dac); if (v3_table_dac >= dac && count > 0) { int delta_x = (dac - list_dac[count - 1]); int delta_X = (list_dac[count] - list_dac[count - 1]); double delta_Y = (list_voltage[count] - list_voltage[count - 1]); final_voltage = (Convert.ToDouble(delta_x) / Convert.ToDouble(delta_X)) * delta_Y + list_voltage[count - 1]; final_voltage = Math.Round(final_voltage, 2); break; } count++; } str.Close(); //(關閉str) volt_before = final_voltage; } } else { volt_before = Convert.ToDouble(vm.List_BoardTable[vm.BoardTable_SelectedIndex][vm.BoardTable_V123]) * dac; //V1: BoardTable_V123 = 1 } double volt_after = Math.Round(Convert.ToDouble(volt), 4); double delta_volt = Math.Round(volt_after - volt_before, 4); vm.Str_Status = "Write DAC"; vm.Str_cmd_read = "DAC: " + dac.ToString() + " , Delta Volt: " + delta_volt.ToString(); #region Bear Say vm.txt_No = new string[] { "30000", "40000", "50000", "60000", "", "", "", "" }; _List_Bear_Say.Add(new List <string>() { volt_before.ToString(), volt_after.ToString() }); #endregion } } #region Show Bear Say vm._write_line = new List <string>(); for (int i = 0; i < 4; i++) //判斷是否NG { if (_List_Bear_Say[i].Count >= 2) { double NG_Criteria = i == 0 ? 0.015 : 0.015; //Setting delta V criteria double delta_volt = Math.Round(double.Parse(_List_Bear_Say[i][1]) - double.Parse(_List_Bear_Say[i][0]), 4); if (Math.Abs(delta_volt) > NG_Criteria) { _List_Bear_Say.Add(new List <string>() { delta_volt.ToString(), "NG" }); } else { _List_Bear_Say.Add(new List <string>() { delta_volt.ToString(), "PASS" }); } //Save Data to WriteLine vm._write_line.Add(vm.BoardTable_SelectedBoard + " , " + "V" + vm.BoardTable_V123 + " , " + (10000 * i + 30000).ToString() + " , " + _List_Bear_Say[i][0] + " , " + _List_Bear_Say[i][1] + " , " + delta_volt.ToString() + " , " + _List_Bear_Say[i + 4][1]); } } vm.List_bear_say = _List_Bear_Say; vm.Collection_bear_say.Add(_List_Bear_Say); vm.bear_say_all++; vm.bear_say_now = vm.bear_say_all; vm.Show_Bear_Window(vm.List_bear_say, false, "List"); #endregion }