read NMEA sentences from GPS

匆匆过客 提交于 2019-12-06 08:02:21

问题


I have a Mio P550 device, which has a GPS included. I try to use SerialPort to get NMEA sentences, by simply use SerialPort.Read(). Data is returned in some weird encoding. GPS should return NMEA sentences in ASCII, but it doesn't. Here is my code for reading:

                dataLength = this.serialPort.Read(buffor, 0, Gps.BUFFOR_LENGTH);
                Debug.WriteLine("data length: " + dataLength);

                if (dataLength > 0)
                {
                    for (int i = 0; i < dataLength; i++)
                    {
                        char c = Convert.ToChar(buffor[i]);

                        if (c == '\r' || c == '\n')
                        {
                            string data = stringBuilder.ToString();
                            Debug.WriteLine("data readed: " + data);

                            if (data.StartsWith("$GPGGA"))
                            {
                                this.OnLocationChanged(data);
                            }

                            stringBuilder.Length = 0;
                        }
                        else
                        {
                            stringBuilder.Append(c);
                        }

                        Debug.WriteLine("readed data: " + stringBuilder.ToString());
                    }

And here is sample value I get in return: xæææxfæ`æxæføøøxxxøx

I have also second device (Asus A636N), which return NMEA sentences in ASCII and my code works great.

What I have to do with Mio device to get NMEA sentences in ASCII? Or how I can get encoding for data returned by device? I try use all classes from System.Text.Encoding.xxx.GetString() to get string from readed bytes but it doesn't return right data - it returns data similar to sample above.


回答1:


You probably need to make sure the baud rate for your serial port is set to 4800 baud as required by the NMEA specification.




回答2:


see this code sample: https://code.google.com/p/avr-nmea-gps-library/

it also uses a 4800 baud rate.



来源:https://stackoverflow.com/questions/1287464/read-nmea-sentences-from-gps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!