How can I read and analyze high-speed SerialPort data

I am trying to write C # code that takes serialport data from a high speed GPS device and analyzes the data to capture the coordinates.

The problem with this compared to other serial GPS devices is that it spills out 5-6 lines of data every 100 milliseconds instead of the same second. Thus, basically, every 0.1 seconds, I get 5 or 6 lines of data that will last continuously while the device is on.

When I tried this on a simulated GPS device with normal speed, it works fine.

This I get 5 lines once a second. But when it accelerates 10 times, it stops working. In principle, the effect of SerialDataReceivedEventHandler does not work at all.

So, what is the best way to get a continuous read of what is essentially a super-fast data dump in serialport format?

My code is below. For you guys from GPS, this particular receiver has a speed of non-standard 115200, not standard 4800. I checked that it works with PuTTY, as well as GPS-ready software for Windows.

  public List<double[]> coords = new List<double[]>(); SerialPort com; ... try { com = new SerialPort(COMPORT); com.BaudRate = 115200; com.DataBits = 8; com.StopBits = StopBits.One; com.Handshake = Handshake.None; com.Open(); com.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } public void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { SerialPort port = (SerialPort)sender; double longitude = -1000; double latitude = -1000; double altitude = -1000; string sentence = port.ReadLine(); if (sentence.StartsWith("$GPGGA")) { string[] values = sentence.Split(','); if (values[2].Length > 1 && values.Count() > 10) { latitude = double.Parse(values[2].Substring(0, values[2].IndexOf('.') - 2)); latitude += double.Parse(values[2].Substring(values[2].IndexOf('.') - 2)) / 60; if (values[3] == "S") latitude = 0 - latitude; longitude = double.Parse(values[4].Substring(0, values[4].IndexOf('.') - 2)); longitude += double.Parse(values[4].Substring(values[4].IndexOf('.') - 2)) / 60; if (values[5] == "W") longitude = 0 - longitude; altitude = double.Parse(values[9]); coords.RemoveAt(0); coords.Add(new double[] { longitude, latitude, altitude }); } else { coords.RemoveAt(0); coords.Add(coords.Last()); } } } 
+4
source share

All Articles