John Demetriou
John Demetriou

Reputation: 4371

ArgumentException: The given port name does not start with COM/com or does not resolve to a valid serial port

I am trying to connect to a virtual com port provided by the drivers of a u-blox GPS device.

The device appears normally under the Sensors tab in Device Manager and I can really get the coordinate data using GeoCoordinateWatcher class from C#.

But I want to read the underlying NMEA data. So in the process of doing that I installed the Virtual Com Port driver provided by U-BLOX and it generated a u-blox virta com port in devices manager.

Connecting to that using Putty is OK and I can see all the NMEA lines being dumped there.

but when I try to connect to the same port (after Putty is closed obviously) using C# I get the exception mentioned in the title

The given port name does not start with COM/com or does not resolve to a valid serial port

My code is fairly simple (not the first time I use com ports) and everything is correctly defined (Port Name, Stop Bits, Parity, BaudRate etc). I even tried changing to a "wrong" com port name to see the exception I will get and it is completely different (Com Port does not a exit exception).

So what is happening with C# at this point? Am I doing something wrong? Is this a bug in the SerialPort class? Putty seems to work just fine in connecting and streaming the data. My code is as simple as the following

m_port = new SerialPort
{
    PortName = m_portName,
    BaudRate = m_baudRate,
    Parity = m_parityBit,
    DataBits = m_dataBits,
    StopBits = m_stopBit
};

m_port.Open();

I even tried hardcoding the values and I still get the same exception. I tried many of the suggested solutions found here, none of them helped. I also tried changing the COM port number from Device Manager advanced settings, that also did not help

Upvotes: 5

Views: 3791

Answers (3)

HLChucky
HLChucky

Reputation: 11

I managed to resolve this issue, and thought I'd share my solution.

I wasn't able to use the CDC driver, as my device is a Rugged Windows Device with a dedicated GPS - the CDC solution may only work for removable gps devices via USB. The sensor driver must be installed, and the VCP driver can be installed alongside the sensor to provide a COM port.

Whilst the VCP driver does not fully emulate a COM port, you can use another piece of software to fully emulate the uBlox virtual com port and fill in the gaps. GPS Gate was that software for me - https://gpsgate.com/. The end result is uBlox Sensor -> uBlox VCP -> GPS Gate VCP. I was then able to successfully use the GPS Gate VCP in my C# app, and have GPS data coming down.

GPS Gate also offers a Location API plugin which could remove the uBlox VCP from the equation (uBlox Sensor -> GPS Gate VCP through Location API), but I didn't have much luck with it, plus I already had a working solution.

Upvotes: 1

matli
matli

Reputation: 28580

If you don't have any particular reason for using the VCP driver, use the CDC driver instead. Available as "u-blox GNSS Standard Driver for Windows" at their website:

https://www.u-blox.com/en/product-resources/2673The/field_file_category/driver-221/field_file_products%253Afield_product_category/position-time-152

I had the same problem as you, but by changing the device driver, everything works as expected. It seems like their VCP driver is not fully compatible with the regular serial port driver structure.

Upvotes: 2

John Demetriou
John Demetriou

Reputation: 4371

As it turns out U-BLOX virtual COM port driver does not fully emulate a COM port which causes issues with .Net. Regardless if it is C# or C++ or any other language running on .Net The only solution is to either, not use this device, or use an intermediary software.

Upvotes: 3

Related Questions