private void btnOpenClose_Click(object sender, RoutedEventArgs e)
 {
     if (portChat == null)
     {
         portChat                = new SerialPortChat((string)portsNames.SelectedItem, (int)baudRates.SelectedItem, "None", 8, "One", "None");
         portChat.PortOpen      += PortChat_PortOpen;
         portChat.PortClose     += PortChat_PortClose;
         portChat.RecivedAnswer += PortChat_RecivedAnswer;
         portChat.OpenPort();
         btnMonitoring.IsEnabled = true;
         btnSettings.IsEnabled   = true;
     }
     else
     {
         portChat.ClosePort();
         portChat = null;
     }
 }
 private void btnOpenClose_Click(object sender, RoutedEventArgs e)
 {
     if (portChat == null)
     {
         portChat            = new SerialPortChat((string)portsNames.SelectedItem, (int)baudRates.SelectedItem, "None", 8, "One", "None");
         portChat.PortOpen  += PortChat_PortOpen;
         portChat.PortClose += PortChat_PortClose;
         portChat.OpenPort();
         commandTimer = new Timer(new TimerCallback(SendCommand));
         alarmTimer   = new Timer(new TimerCallback(SendAlarm));
     }
     else
     {
         commandTimer.Dispose();
         alarmTimer.Dispose();
         portChat.ClosePort();
         portChat = null;
     }
 }