简体   繁体   中英

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. 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 . You can sse a WMI query to list all serial ports, as detailed here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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