private async void btn_TLS_on_Click(object sender, RoutedEventArgs e) { if (vm.PD_or_PM == true && vm.IsGoOn == true) { await vm.PM_Stop(); } vm.isLaserActive = vm.isLaserActive == true ? false : true; vm.tls.SetActive(vm.isLaserActive); await vm.AccessDelayAsync(vm.Int_Set_WL_Delay + 100); if (vm.PD_or_PM == true && vm.IsGoOn == true) { vm.PM_GO(); } }
private async void Button_Click(object sender, RoutedEventArgs e) { if (vm.station_type != "Hermetic Test") { return; } Button obj = (Button)sender; int switch_index; string[] tag_index = obj.Tag.ToString().Split('_'); if (tag_index.Length == 2) { if (page_now == 1) { switch_index = int.Parse(tag_index[0]); } else { switch_index = int.Parse(tag_index[1]); } } else { return; } if (obj.Content == null) { return; } if (string.IsNullOrEmpty(obj.Content.ToString())) { return; } if (vm.PD_or_PM == true && vm.IsGoOn == true) { await vm.PM_Stop(); } double txt_value = Convert.ToDouble(obj.Content); if (txt_value > 1000 && txt_value < 2000) { #region set WL double wl = txt_value; vm.tls.SetWL(wl); vm.Double_Laser_Wavelength = wl; await vm.AccessDelayAsync(vm.Int_Set_WL_Delay); vm.pm.SetWL(Convert.ToDouble(obj.Content)); #endregion } else { double dac = txt_value; //Reset COM port if (string.IsNullOrEmpty(vm.list_Board_Setting[switch_index - 1][1])) { return; } savePort = vm.port_PD; #region Port Open try { if (!vm.IsGoOn) { vm.port_PD.Open(); } else { if (vm.PD_or_PM == false) { vm.timer2.Stop(); } else { vm.timer3.Stop(); } await vm.AccessDelayAsync(vm.Int_Read_Delay); vm.port_PD.Close(); await vm.AccessDelayAsync(50); vm.port_PD.Open(); vm.port_PD.DiscardInBuffer(); // RX vm.port_PD.DiscardOutBuffer(); // TX } } catch { } #endregion //Set voltage vm.Str_comment = "D1 0,0," + (dac).ToString(); //cmd = D1 0,0,1000 vm.port_PD.Write(vm.Str_comment + "\r"); await vm.AccessDelayAsync(vm.Int_Write_Delay); vm.port_PD.Close(); await vm.AccessDelayAsync(50); vm.port_PD.DiscardInBuffer(); // RX vm.port_PD.DiscardOutBuffer(); // TX } if (vm.PD_or_PM == true && vm.IsGoOn == true) { vm.PM_GO(); } #region set switch try { if (vm.port_Switch != null) { vm.port_Switch.Close(); } await vm.AccessDelayAsync(50); if (vm.Comport_Switch > 0) { vm.port_Switch = new SerialPort("COM" + vm.Comport_Switch.ToString(), 115200, Parity.None, 8, StopBits.One); vm.port_Switch.Open(); vm.port_Switch.DiscardInBuffer(); // RX vm.port_Switch.DiscardOutBuffer(); // TX } } catch { vm.Str_bear_say = "Switch Comport Error"; vm.Winbear = new Window_Bear(vm, false, "String"); vm.Winbear.Show(); } if (switch_index > 12) { return; } if (switch_index > 0 && switch_index < 13) //Switch 1~12 { if (string.IsNullOrWhiteSpace("I1 " + switch_index.ToString())) //Check comment box is empty or not { return; } if (switch_index < 9 && int_saved_combox_index >= 9) //換頁 page1 { vm.Bool_Page2 = vm.Bool_Gauge_Show; vm.Str_Channel = new List <string>() { "1", "2", "3", "4", "5", "6", "7", "8", }; vm.Channel_visible = new List <Visibility>() { }; vm.Bool_Gauge_Show = vm.Bool_Page1; } else if (switch_index > 8 && int_saved_combox_index <= 8) //換頁 page2 { vm.Bool_Page1 = vm.Bool_Gauge_Show; vm.Str_Channel = new List <string>() { "9", "10", "11", "12" }; vm.Channel_visible = new List <Visibility>() { Visibility.Visible, Visibility.Visible, Visibility.Visible, Visibility.Visible, Visibility.Hidden, Visibility.Hidden, Visibility.Hidden, Visibility.Hidden }; vm.Bool_Gauge_Show = vm.Bool_Page2; } try { vm.Str_comment = "I1 " + switch_index.ToString(); vm.port_Switch.Write(vm.Str_comment + "\r"); await vm.AccessDelayAsync(vm.Int_Write_Delay); } catch { } } else if (switch_index == 0) //Switch ? { vm.Str_comment = "I1?"; vm.port_Switch.Write(vm.Str_comment + "\r"); await vm.AccessDelayAsync(vm.Int_Read_Delay); } else { vm.Str_Channel = new List <string>() { "1", "2", "3", "4", "5", "6", "7", "8", }; vm.Channel_visible = new List <Visibility>() { }; } int_saved_combox_index = switch_index; vm.ch = switch_index; //Save Switch channel vm.switch_index = switch_index; #endregion }