Example #1
0
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;   //avoid multiply threads cause error

            usb = new USB();

            refreshPortnameTimer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshPortname);
            refreshPortnameTimer.Start();
        }
Example #2
0
        //initial combobox
        private void InitComboBox(ComboBox combo)
        {
            try
            {
                string[] ports = USB.GetPorts(); //SerialPort.GetPortNames();//
                combo.Items.Clear();
                for (int i = 0; i < ports.Length; i++)
                {
                    combo.Items.Add(ports[i]);
                }

                if (ports.Length > 0)
                {
                    // combo.SelectedIndex = ports.Length - 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }