可用的串行端口未在Visual Studio中显示

时间:2016-05-30 04:40:11

标签: c# windows serial-port

我最近正在开发串口通信的项目,我想在comboBox中显示可用的串口,但是在运行它时没有显示可用的com端口列表。

我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace Serial_application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
           InitializeComponent();
           getPortsNames();
        }
        void getPortsNames()
        {
          string[] ports = SerialPort.GetPortNames();
          comboBox1.Items.AddRange(ports);
        }
     }
 }

1 个答案:

答案 0 :(得分:0)

大多数现代计算机上没有旧式com端口,它们是USB转换器。如果尚未安装USB设备驱动程序,则计算机中未列出任何端口。刚为自己解决了这个问题。