tags:

views:

597

answers:

1

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.

+4  A: 

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

Greg Hewgill
Thanks! That was this. I wonder now why everything on Asus device works great without setting baud rate in code.
GTD