Ejemplo n.º 1
0
 //Button Click event
 private void connect_button_Click(object sender, RoutedEventArgs e)
 {
     if (connect_button.Content.ToString() == "Disconnect") //If already connected disconnect
     {
         contentControl.Content  = setup;                   //Set the Content control
         enter_button.Visibility = Visibility.Hidden;       //Hide Button
         connect_button.Content  = "Connect";               //Add Connect Button
         port_con.disconnect();                             //Call function Disconnect
         update_button.Visibility = Visibility.Hidden;
         slider.Visibility        = Visibility.Hidden;
         pwm_progress.Visibility  = Visibility.Hidden;
         pwmVal_label.Visibility  = Visibility.Hidden;
         pwm_label.Visibility     = Visibility.Hidden;
     }
     else
     {
         //exception handling
         try
         {
             if (setup.checkData())
             {
                 System.Windows.MessageBox.Show("You have entered an incorrect configuration");
             }
             else
             {
                 port_con = new SerialPortProgram(setup.port_box.Text, int.Parse(setup.baudrate_box.Text));
                 contentControl.Content   = keypad;
                 connect_button.Content   = "Disconnect";
                 enter_button.Visibility  = Visibility.Visible;
                 update_button.Visibility = Visibility.Visible;
                 slider.Visibility        = Visibility.Visible;
                 pwm_progress.Visibility  = Visibility.Visible;
                 pwmVal_label.Visibility  = Visibility.Visible;
                 pwm_label.Visibility     = Visibility.Visible;
             }
         }
         catch
         {
         }
     }
 }