dotnet/runtime

SerialPort error on Virtual Serial Port for USB

Open

#30,877 opened on 2019年9月17日

GitHub で見る
 (15 comments) (2 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.IO.Portshelp wantedos-windows

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

I'm trying to access a Virtual Serial Port for USB with System.IO.Ports.SerialPort and I get the error The given port name (COM5) does not resolve to a valid serial when I try to open the port. Here is the code, it works with physical serial ports:

using (var serialPort = new System.IO.Ports.SerialPort("COM5", 9600))
{
    try
    {
        serialPort.Open(); // ERROR: The given port name (COM5) does not resolve to a valid serial port.
        serialPort.WriteLine("SerialPort Write Test");
        serialPort.Close();
    }
    catch (Exception exception)
    {
        Console.WriteLine(exception);
    }
}

I did several tests with .NET 4.7, .NET Core 3.0-RC1, the 4.6.0-rc1 of nuget System.IO.Ports, UWP application with Windows.Devices.SerialCommunication.SerialDevice. Always the same error.

The Virtual Serial Port works well with other programs, such as Termite by Compuphase or Serial Port Terminal by Eltima.

I have also tried with an alternative .NET library SerialPortStream and the access to the COM Port works fine.

Looking at the code, I see that if the fileType is different from FILE_TYPE_CHAR and FILE_TYPE_UNKNOWN, the error is reported. The problem is that my Virtual Service Port returns FILE_TYPE_DISK. Is there a reason to refuse FILE_TYPE_DISK? Is it possible to accept it or make it configurable?

コントリビューターガイド