Go to Post I hope FIRST hurries up and releases the regional schedule soon. I have a vacation schedule to plan. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-12-2008, 17:02
C222's Avatar
C222 C222 is offline
Computer Science Major
FRC #0852 (Athenian Robotics Collective)
Team Role: Alumni
 
Join Date: Mar 2007
Rookie Year: 2007
Location: California
Posts: 22
C222 is on a distinguished road
Decoding GPS with C#

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:
$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:
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?
__________________
--=====|-----====|-------====|-------====|----
--=|--------------==|----------==|---------==|---
--=|---------------==|----------==|---------==|--
--=|------------==|----------==|---------==|-----
--=====|-----======|-----======|----======|-
  #2   Spotlight this post!  
Unread 15-12-2008, 22:29
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Decoding GPS with C#

Your code to write to the serial port should work, though I recommend you pick Write or WriteLine, and not try to use both. There's a large number of reasons why this might not be working for you, though. If you don't have the communication parameters set correctly, you can end up receiving but sending gibberish to the GPS, or not sending anything at all. You also might not be sending the appropriate end of line characters in the appropriate sequence. Common options are "\x0A" (new line), "\x0D" (carriage return)(Ding!), "\x0D\x0A", and rarely "\x0A\x0D". Your GPS might use more exotic characters, however.

If you have it working over Tera Term, make sure you have ALL of the communication parameters the same, and then find out what end of line characters it's using. Once you make sure you're doing everything the same as Tera Term, it should work for you.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #3   Spotlight this post!  
Unread 15-12-2008, 23:57
daltore's Avatar
daltore daltore is offline
Electronics/programming/design
AKA: Aaron Osmer
FRC #3529 (ausTIN CANs)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2007
Location: San Antonio, TX
Posts: 272
daltore has a spectacular aura aboutdaltore has a spectacular aura aboutdaltore has a spectacular aura about
Send a message via AIM to daltore Send a message via MSN to daltore Send a message via Yahoo to daltore
Re: Decoding GPS with C#

You could always try good ol' "\n" and/or "\r". I'm not quite certain of the setup you have, but you might be able to use a system() command to pass the word "ASTRAL" through the echo command.

If nothing else works, there's always the down-and-dirty last-resort method of sending raw data to the serial port through "outb". This is a Linux C command, and I'm not sure if it works in any other OS's/C derivatives, but there's probably something similar. Note that this function only passes one byte on at a time, so you'd have to find something else that can pass whole strings at the correct baud rate.
  #4   Spotlight this post!  
Unread 16-12-2008, 13:16
C222's Avatar
C222 C222 is offline
Computer Science Major
FRC #0852 (Athenian Robotics Collective)
Team Role: Alumni
 
Join Date: Mar 2007
Rookie Year: 2007
Location: California
Posts: 22
C222 is on a distinguished road
Re: Decoding GPS with C#

It was only sending "ASTRAL"
However, I just tried "ASTRAL\n", "ASTRAL\r", "ASTRAL\n\r", "ASTRAL\r\n", "ASTRAL\x0A", "ASTRAL\x0D", "ASTRAL\x0A\x0D", and "ASTRAL\x0D\x0A".
None worked.
__________________
--=====|-----====|-------====|-------====|----
--=|--------------==|----------==|---------==|---
--=|---------------==|----------==|---------==|--
--=|------------==|----------==|---------==|-----
--=====|-----======|-----======|----======|-
  #5   Spotlight this post!  
Unread 16-12-2008, 14:37
ay2b's Avatar
ay2b ay2b is offline
Registered User
AKA: Andy
FRC #2928
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 1994
Location: Seattle, WA
Posts: 211
ay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant futureay2b has a brilliant future
Re: Decoding GPS with C#

You might try looking at the open source project, GPSd http://gpsd.berlios.de/. It runs on Linux and Macs. I haven't tried it under Windows, but I would guess it'll compile under cygwin and run fine. GPSd has support for reading gps data in a bunch of different formats, and then translates the data into a common, easier to use, format which is accessible either through a TCP (telnet) connection to the server running gpsd, or through the gpsd client (available for a number of different languages, including C, C++ and perl).
__________________

2011 - SD Quarterfinalists (980), LA Quarterfinalists (980)
2010 - LA (2404) Finalists (980), AZ Motorola Quality (980)
2009 - LA Semifinalists (980); Las Vegas Quarterfinalists (980); SD (2404); IRI #1 Seed, Finalist (980)
2008 - SD Quarterfinalists (980), LA Champions (980), LA Rookie Inspiration Award (2404); CalGames Finalists
2007 - So.Cal Finalists (980), SD Quarterfinalists (980); CalGames Finalists
2006 - So.Cal Regional Champion (4), Toronto Judge's Award Day 1 (4)
2005 - SVR Champions, Delphi "Driving Tomorrow's Technology" (980); AZ Xerox Creativity (980); So.Cal Finalists, RadioShack Innovation in Control (980); Championship Archimedes Division Semifinalists; IRI Finalists (980)
2004 - So.Cal Regional Champions, Leadership in Controls (980); AZ GM Industrial Design (980); Championship Galileo Division #2 Seed; IRI Champions
2003 - PNW Semi-finalists (488)
2002 - PNW Finalists (488)
2000 - X-bot / 488 - Mentor / Founder
1994 - Sunny Delight - Driver - champion
  #6   Spotlight this post!  
Unread 16-12-2008, 14:50
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Decoding GPS with C#

A thought came to mind... I believe the .NET framework works in Unicode by default, which means it's probably sending double-wide characters, and most serial devices expect single-wide (ASCII) characters. You'll need to use the the Encoding class to convert between them. There's plenty of examples on MSDN, I've also included one below:

using System;
using System.Text;

class ASCIIEncodingExample {
public static void Main() {
// The encoding.
ASCIIEncoding ascii = new ASCIIEncoding();

// A Unicode string
String unicodeString = "ASTRAL\n";

// Encode string.
Byte[] encodedBytes = ascii.GetBytes(unicodeString);

foreach (Byte b in encodedBytes)
{
Console.Write((char)b);
}

Console.ReadLine();
}
}
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
  #7   Spotlight this post!  
Unread 16-12-2008, 16:30
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Decoding GPS with C#

C# defaults to standard ASCII encoding for serial ports and suchlike. There's no need for re-encoding the string or anything like that. If you really think it's necessary, however, it's much much easier to do this in the port setting area before comport.Open():

comport.Encoding = Encoding.ASCII;

Also, thanks to a bit of googling to identify your odd GPS, I ran across your somewhat more informative post on XKCD. The nice webpage you link from there about your Delorme Tripmate actually tells you straight out that the string you should be attempting to send is "ASTRAL\r\n". So it's nice to have that confirmed, and you can stick with that as the string to send.

I assume that you've actually linked your button click function to your button's onClick event, but just for grins, you could try forcing your program to send "ASTRAL\r\n" as soon as it opens the comport. To wit:
Code:
                // Open the port
                comport.Open();
                button1.Text = "Close Port";
                comport.Write("ASTRAL\r\n");
That should guarantee that your string is getting sent at some point, since it has to call Write after successfully opening the port.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GPS chuckmerja Programming 12 27-03-2008 09:28
GPS michelita2607 Rules/Strategy 7 16-01-2008 11:07
GPS with VEX dasmoenator Technical Discussion 29 28-10-2007 23:56
Victor 884 output decoding / General question theshadow27 Electrical 7 01-03-2007 02:05
InfraRed = gps ? nzj1 General Forum 17 11-01-2004 16:58


All times are GMT -5. The time now is 19:26.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi