【问题标题】:Available Serial ports are not shown in Visual studioVisual Studio 中未显示可用的串行端口
【发布时间】:2016-05-30 04:40:11
【问题描述】:

我最近在做一个串口通信的项目,我想在一个组合框中显示可用的串口,但是在运行时它没有显示可用的串口列表。

我的代码:

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);
        }
     }
 }

【问题讨论】:

  • 你检查你的可用端口了吗?
  • 您在访问端口或显示端口时遇到问题吗?你在visual studio之外检查过吗?就像您通过 com 端口连接的那些设备是否显示在设备管理器中?您可以通过其他方式访问它们吗?
  • 首先从设备管理器中检查可用端口。
  • 你的代码是正确的,去设备管理器看看你的电脑有没有可用的端口。
  • 来自MSDN 中的评论。 端口名称从系统注册表中获取(例如,HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM)。如果注册表包含陈旧或不正确的数据,则 GetPortNames 方法将返回不正确的数据。

标签: c# windows serial-port


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    相关资源
    最近更新 更多