PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 26, 2022

[FIXED] How to read GPS data from serial port

 September 26, 2022     c#, gps, serial-port     No comments   

Issue

I'm trying to read the data coming in on a serial port from a BU-353S4 USB GPS. I'm getting nothing as far as readable NMEA sentences. The GPS works perfectly with a Raspberry Pi.

This is for a .NET console application. There are similar questions all over the web, but none of the samples seem to work.

var port = new SerialPort
{
    PortName = "COM5",
    BaudRate = 4800,
    Parity = Parity.None,
    DataBits = 8,
    StopBits = StopBits.One,
};
port.DataReceived += Port_DataReceived;


private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    string line = "";
    SerialPort port = (SerialPort)sender;
    line = port.ReadExisting();
    Console.Write(line);
}

and...

private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort port = (SerialPort)sender;
    var count = port.BytesToRead;
    var buffer = new byte[count];
    port.Read(buffer, 0, count);
    var line = Encoding.ASCII.GetString(buffer);
    Console.Write(line);
}

No matter what I try, I end up with something like:

?)))))(((((#Y ?""!!!!!!!? ??z ?----------?D? ?

?J ?&%%%%%%%%%?? ?%$$$$$$$$$f Qx ?++++****** ?! ? ? #???? ) xm???? =?? ? ????? ???? ]? t? D0?? ????? 3 4???? 2\


Solution

Turns out the GPS was sending SiRF instead of NMEA. Once I followed the steps in this SuperUser post to switch it to NMEA, everything worked perfectly!



Answered By - tallman
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing