runtime: SerialPort error on Virtual Serial Port for USB
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?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 15 (9 by maintainers)
I’m not sure about type on Windows but for Linux we should be able to use anything as far as termios() succeed.
any news about this?
I think removing the
FILE_TYPE_DISKtype check is fine for Core.Let’s see if @JeremyKuhne has any push backs against changing Windows logic, if not or no response I think this is fine to remove the restriction (at least cannot see why it should be there).
@krwq SerialPort.GetPortNames simply works. The error occurs when you open a virtual usb port on Linux. The problem was well known in Mono, and was solved avoiding any access to DTR. Anyway I opened a new issue 524967076
cc: @krwq