c#获取本机的串口列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nineleafclover/article/details/77196833

1.定义一个字符串数组,并将获取到的电脑上串口名字赋值给它。
string[] ArryPort = SerialPort.GetPortNames();
2.将一个组合框的内容清除
cmbPort.Items.Clear();
3。将数组中的值添加到组合框中

 for (int i = 0; i < ArryPort.Length; i++)
  {
       cmbPort.Items.Add(ArryPort[i]);
   }

猜你喜欢

转载自blog.csdn.net/nineleafclover/article/details/77196833