/// <summary>
        /// Connects this instance.
        /// </summary>
        private void Connect()
        {
            if (_serialComService.IsConnected)
            {
                AppendStatusText("Already connected!");
                return;
            }

            if (drpPorts.Items.Count == 0)
            {
                MessageBox.Show("No available Com Ports", "Unable to connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            int    baudRate = Convert.ToInt32(drpBaudRate.SelectedItem.ToString());
            string comPort  = drpPorts.SelectedItem.ToString();

            if (_serialComService.Connect(comPort, baudRate))
            {
                AppendStatusText("Connected");
            }
            else
            {
                AppendStatusText("ConnectionFailed: " + _serialComService.LastError);
            }
        }
Esempio n. 2
0
        private void ConnectToFirstOpenComPort()
        {
            if (_serialComService.IsConnected)
            {
                lblStatus2.Text = "Error, already connected. Disconnect before making a new connection.";
                return;
            }

            int    defBaudRate = Settings.Default.BaudRate;
            string portName    = SerialComService.GetPortNamesAvailable().FirstOrDefault();

            if (string.IsNullOrEmpty(portName))
            {
                lblStatus2.Text = "Quick connect was not possible because no available ports where available.";
                return;
            }

            bool result = _serialComService.Connect(portName, defBaudRate);

            lblStatus2.Text = result ? "Quick Connect Successful" : "Quick connect failed.";
        }