仓库指标
- Star
- (17,886 star)
- PR 合并指标
- (平均合并 12天 11小时) (30 天内合并 661 个 PR)
描述
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?