.net获取串口列表

  • Post author:
  • Post category:其他


//方法一
            String[] Str2 = System.IO.Ports.SerialPort.GetPortNames();
            if (Str2.Length > 0)
            {
                for (int k = 0; k < Str2.Length; k++)
                {
                    comboBoxEdit1.Properties.Items.Add(Str2[k]);
                }
            }
            //方法二
            String[] Str2 = Gprs.GetSerialPortNames();
            if (Str2.Length > 0)
            {
                for (int k = 0; k < Str2.Length; k++)
                {
                    comboBoxEdit1.Properties.Items.Add(Str2[k]);
                }
            }
            //方法三
            RegistryKey keyCom = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
            if (keyCom != null)
            {
                string[] sSubKeys = keyCom.GetValueNames();
                comboBoxEdit1.Properties.Items.Clear();
                foreach (string sName



版权声明:本文为bjut_yue原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。