管延文

管延文程序空间 QQ:27651302

导航

Winform 串口相关

 

查找当前电脑上有哪些串口

 

using System.IO;
using System.IO.Ports;

  private void button1_Click(object sender, EventArgs e)
        {
            //用以下方法知道此
            
//方法一:comboBox1.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());  

            
//方法二: 
            string[] portList = System.IO.Ports.SerialPort.GetPortNames();
            for (int i = 0; i < portList.Length; ++i)
            {
                string name = portList[i];
                comboBox1.Items.Add(name);
            }

        }

 

posted on 2011-12-27 10:07  tiger8000  阅读(476)  评论(0)    收藏  举报