Decoding GPS with C#

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

C222
Posts: 7
Joined: Thu Nov 01, 2007 12:28 am UTC

Decoding GPS with C#

Postby C222 » Tue Dec 16, 2008 12:06 am UTC

I have a fairly old GPS receiver that communicates with my desktop through COM1.

I found some code on the internet to decode the strings i get from the receiver which look something like:

Code: Select all

$GPGSA,A,1,,,,,,,,,,,,,1.27,0.75,1.03*04
$GPRMC,215606,V,3511.1990,N,12904.2725,W,0.000,0.0,151208,15.0,E*45
$PRWIZCH,29,6,12,0,12,0,31,0,24,6,31,0,16,0,31,0,31,0,31,0,31,0,12,0*44
$GPGGA,,,,,,0,00,,,,,,,*66
$GPGSA,A,1,,,,,,,,,,,,,1.27,0.75,1.03*04
$GPGSV,3,1,12,29,70,024,34,24,70,006,39,30,50,190,,21,48,264,*79
$GPGSV,3,2,12,10,34,052,,05,28,173,,18,21,194,,12,20,163,*73
$GPGSV,3,3,12,16,11,321,,31,11,268,,15,09,124,,26,07,108,*73
$GPRMC,215607,V,3511.1990,N,12904.2725,W,0.000,0.0,151208,15.0,E*44
$PRWIZCH,29,6,12,0,12,0,31,0,24,6,31,0,16,0,31,0,31,0,31,0,31,0,12,0*44
$GPGGA,,,,,,0,00,,,,,,,*66


The code if found here.
Using a resource I found on the internet i can tell that the GPS is working and giving me a fairly accurate location (once i get a fix).
However, this is over a terminal application called Tera Term and my GPS requires me to broadcast the command "ASTRAL" before any useful data is sent. The problem is, the code from the link above has no command to submit the command "ASTRAL". I tried:


Code: Select all

private void button3_Click(object sender, EventArgs e)
        {
            if (comport.IsOpen)
            {
                //byte astral;
                //astral = Convert.ToByte("ASTRAL");
                comport.Write("ASTRAL");
                comport.WriteLine("ASTRAL");
            }
            else
            {
            }
        }


But that didn't work. Any suggestions?

User avatar
wing
the /b/slayer
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Decoding GPS with C#

Postby wing » Tue Dec 16, 2008 3:25 am UTC

NMEA 0813

That'll be your standard for GPS-over-serial (also GPS over USB - most USB GPS units just have a silly little USB=>Serial chip glued in them and will load up a virtual serial port driver)

The serial port library in .NET works great - I've used it several times (though not for GPS yet), go ahead and write your own device interaction layer. GPS isn't THAT hard.

http://www.kh-gps.de/nmea-faq.htm
A handy little resource for you to start with writing a parser.

Edit: Okay, I'm bored, I have a receiver, and I have a need to write this code for a project anyway. Give me a little bit and I'll post what I come up with.



I've never seen a GPS requiring you to send a command to start off the process - in fact, 0813 is technically unidirectional. Mine just spits out data, happy as can be, across the serial port even if there isn't anything bloody connected. Mind posting up some of the data that you see before sending the command? Your GPS may be trying to emulate another signaling method from older equipment, or something.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.

C222
Posts: 7
Joined: Thu Nov 01, 2007 12:28 am UTC

Re: Decoding GPS with C#

Postby C222 » Tue Dec 16, 2008 8:00 am UTC

Yes, my receiver is NMEA 0183 and yes, generally the data flow is one-way.
However, the Delorme Tripmate is weird. It will send the string "ASTRAL" until it runs out of power or receives the same string "ASTRAL".

My source:
http://bevhoward.com/TripMate.htm

User avatar
hotaru
Posts: 1015
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Decoding GPS with C#

Postby hotaru » Tue Dec 16, 2008 3:07 pm UTC

C222 wrote:

Code: Select all

                comport.Write("ASTRAL");
                comport.WriteLine("ASTRAL");

are you really writing "ASTRAL" and then "ASTRAL\n" to it? if so, are you supposed to be doing that?

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

C222
Posts: 7
Joined: Thu Nov 01, 2007 12:28 am UTC

Re: Decoding GPS with C#

Postby C222 » Tue Dec 16, 2008 6:14 pm UTC

It was only "ASTRAL"
However, I just tried "ASTRAL\n", "ASTRAL\r", "ASTRAL\n\r", and "ASTRAL\r\n"
None worked.

User avatar
wing
the /b/slayer
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: Decoding GPS with C#

Postby wing » Tue Dec 16, 2008 7:39 pm UTC

I don't see why it would, but C# may be trying to write Unicode to the serial port, which would be decidedly not-right. (this DOES work if you're using teraterm or hyperterm or some other direct ASCII-native serial app, right?)

Try sending the raw ASCII bits. Also, you need to terminate in CR/LF (both, not one or the other)
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.


Return to “Coding”

Who is online

Users browsing this forum: Bing [Bot] and 4 guests