简体   繁体   English

SerialPort (.net) - 未找到端口

[英]SerialPort (.net) - not ports found

using System;
using System.IO.Ports;

public static void getPorts()
{
    string[] ports = SerialPort.GetPortNames();

    Console.WriteLine("The following serial ports were found:");

    foreach (string port in ports)
    {
        Console.WriteLine(port);
    }
    Console.ReadLine();
}

I have problem with this simple code.我对这个简单的代码有问题。 I need to write out my ports because I will work with them later on (I'm using that simple function in my bigger app).我需要写出我的端口,因为我稍后会使用它们(我在我更大的应用程序中使用这个简单的功能)。 Everything was working until I upgraded my Windows.一切正常,直到我升级了我的 Windows。 Do you have any idea what could be the problem?你知道可能是什么问题吗? I have also installed all drivers.我也安装了所有驱动程序。

The SerialPort.GetPortNames method won't list some virtual serial ports (like those provided by some USB-to-RS232 adapters etc.), since it relies on the HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM registry key as specified in the documentation . SerialPort.GetPortNames方法不会列出一些虚拟串行端口(如某些 USB 转 RS232 适配器等提供的那些),因为它依赖于文档中指定的HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM注册表项。 You can sse a WMI query to list all serial ports, as detailed here .您可以使用 WMI 查询来列出所有串行端口,详见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM