Exemplo n.º 1
0
 private void ConnectButton_Click(object sender, EventArgs e)
 {
     try{
         if (ConnectButton.Text == "Connect")
         {
             CommunicationPort.PortName = SerialPortComboBox.SelectedItem as string;
             CommunicationPort.BaudRate = 57600;
             CommunicationPort.Open();
             log.Info("Open Com Port: " + CommunicationPort.PortName + " with baudrate " + CommunicationPort.BaudRate.ToString());
             ConnectButton.Text = "Disconnect";
         }
         else
         {
             if (CommunicationPort.IsOpen)
             {
                 CommunicationPort.Close();
             }
             ConnectButton.Text = "Connect";
         }
     }
     catch (Exception ex)
     {
         log.Error("Could not connect!", ex);
     }
 }
Exemplo n.º 2
0
        public bool Open()
        {
            if (CommunicationPort.IsConnected)
            {
                return(true);
            }

            lock (CommunicationPortLock)
            {
                Log(LogLevel.Information, "Opening communicaton port: {0}", ComPort);
                bool success = CommunicationPort.Open(ComPort);
                if (success)
                {
                    OnStateChanged();

                    GetGlobalConfiguration();
                    GetIgnitionConfiguration();
                    StartUpdateTimer();
                }
                return(success);
            }
        }