Exemple #1
0
        private void btnFindControlUnit_Click(object sender, EventArgs e)
        {
            this.Enabled       = false;
            cbxComPort.Enabled = false;

            // check if the virtual handset is currently connected
            if (Handset.IsConnected())
            {
                // disconnect the virtual handset
                Handset.Disconnect();
            }

            // get the port of the first found control-unit
            // NOTE: this function can take long time to finish,
            //       so prefer to do this on first launch of the app and then
            //       save the COM-port in your application settings.
            string PortNameOfFoundControlUnit = Handset.GetPortOfFirstFoundControlUnit();

            // check if we have not found a control-unit
            if (PortNameOfFoundControlUnit == "")
            {
                MessageBox.Show("No control-unit found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try {
                    // do not select any items
                    cbxComPort.SelectedItem = null;
                    // try to select the found COM-port in the list
                    cbxComPort.SelectedItem = PortNameOfFoundControlUnit;
                } catch {
                    // do not select any items on error
                    cbxComPort.SelectedItem = null;
                }
            }

            cbxComPort.Enabled = true;
            this.Enabled       = true;
        }