dotnet/runtime

SerialPort error on Virtual Serial Port for USB

Open

#30.877 aberto em 17 de set. de 2019

Ver no GitHub
 (15 comments) (2 reactions) (0 assignees)C# (5.445 forks)batch import
area-System.IO.Portshelp wantedos-windows

Métricas do repositório

Stars
 (17.886 stars)
Métricas de merge de PR
 (Mesclagem média 12d 11h) (661 fundiu PRs em 30d)

Description

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?

Guia do colaborador