Find the GPS com port using DotNet/C# SerialPort.ReadTo("$GP")

0 votes
19 views
I am trying to discover the serial port for GPS using Windows/DotNet.
The following is C# psuedocode:
For each com port, for each baud rate starting at the highest, find an open port and perform a SerialPort.ReadTo("$GP").  If this is successful, i'm good. Unfortunately, the ReadTo doesn't work.  Tried a SerialPort.ReadExisting() and come up empty for every open port. CF-53's have u-blox Virtual COM Port driver and GNSS Location Sensor installed.  

Here's a snippet of actual code:

            var ports = System.IO.Ports.SerialPort.GetPortNames().OrderBy(s => s);
            foreach (var portName in ports)
            {
                using (var port = new System.IO.Ports.SerialPort(portName))
                {
                    List<int> baudRatesToTest = new List<int>(new[] { 115200, 19200, 57600, 38400, 9600, 4800, 2400 }); //Ordered by best to least
                    foreach (var baud in baudRatesToTest)
                    {
                        port.BaudRate = baud;
                        port.ReadTimeout = 2000;
                        bool success = false;
                        try
                        {
                            port.Open();
                            if (!port.IsOpen)
                            {
                                continue; //couldn't open port
                            }

                            log.Warn("portName + "/" + baud.ToString() + ".  Result: " + port.ReadExisting());

                            try
                            {
                                port.ReadTo("$GP");
                                success = true;
                            }
                            catch (TimeoutException)
                            {
                                continue;
                            }

What am i doing wrong?

Thanks
asked Jan 12 by neilgps
Thank you both for your prompt replies.  We resolved the issue by installing the Sierra drivers that were originally on the CF-53's.

2 Answers

0 votes
Assuming that - you are running Windows 10, on the toughbook, with embedded GNSS, the problem may be the Windows Location/Sensor driver which provides a single virtual COM port which is sometimes not recognized by some environments.
Remove the Windows sensor USB driver completely and load in the simple CDC-ACM USB driver and see if that works. That USB driver can be downloaded from the u-blox website under Documents and Resources tab on most GNSS module web pages.
Search this forum for "rugged", "tough", etc. to get more hints on solutions.
answered Jan 12 by grampy Senior Principal Expert
edited Jan 12 by grampy
0 votes
Depending on receiver it might not be sending $GP but rather $GN, suggest looking for "$G" or "\r\n$G"

See if you can open in a generic terminal application, see what's coming out.
answered Jan 12 by clive1 Senior Principal Expert