本文介绍了读取GPS NMEA语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个神达P550设备,它具有GPS包括在内。我尝试使用的SerialPort得到NMEA句子,通过简单地使用SerialPort.Read()。数据在一些奇怪的编码返回。 GPS应返回NMEA句子的ASCII,但事实并非如此。这里是我的代码阅读:

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());
                    }



这里是样本值我得到的回报:
xæææxfæ` æxæføøøxxxøx

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

我也有第二个设备(华硕A636N),在ASCII返回NMEA句子和我的代码的伟大工程。

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

我有什么用神达设备做的就是NMEA句子的ASCII?或如何,我可以得到由设备返回的数据编码?我尝试使用来自System.Text.Encoding.xxx.GetString()的所有类摆脱readed字节字符串,但它不会返回正确的数据 - 它返回类似于上述采样数据

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.

推荐答案

您可能需要确保波特率为您的串行端口设置为的所要求的NMEA规范。

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

这篇关于读取GPS NMEA语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:57