An open source .NET GPS class library (MIT License)
WARNING: USE AT YOUR OWN RISK! This application has NOT been tested
with all GPS devices and could destroy data in your GPS device. At worse,
it could destroy your GPS device.
If you need commercial quality supported GPS software, please see:
Talking to a GPS device via a serial connection
Basic parsing of NMEA sentences providing the following events:
Date and Time
Partial Garmin protocol support for Garmin devices including the ability to:
Monitor Position, Velocity, and Time.
Transfer Track Logs
Acquire device capability (incomplete)
GPX XSD definitions and DataSets (modified as needed to support Microsoft's
DataSet implementation's limitations).
This section is woefully incomplete... Please post to the forums to get
help from other users.
Modes of operation (NMEA vs Garmin)
There are two main modes of operation, NMEA and Garmin:
NMEA - Most GPS receivers support output of
sentences. Usually, these are output at regular intervals on a serial
connection at a 4800 baud rate. No interation with the GPS is required,
and this particular library does not even support such interaction.
Garmin - most Garmin GPS receivers support the
Garmin Protocol. Sometimes, you manually have to tell your GPS to
switch into Garmin mode.
Using NMEA mode
AutoFindDetector - to automatically find a GPS device that is emitting GPS
sentences on a COM port.
NMEAReceiver - use this directly on a COM port
const int COMPort = 4;
NMEAReceiver n = new NMEAReceiver(COMPort);
if ( n != null )
n.PositionReceived += new PositionReceivedEventHandler( YourMethodHere );
// TODO: hook in other event handlers here
// do something (exit to UI message loop) your event handler will get
// called whenever NMEA events occur
// at some point, be sure you dispose of this.
Using the Garmin protocol
Example of how to download track logs:
const int COMPort = 4;
using ( SerialStream ss = GarminStreamConfig.Open(COMPort) )
GarminCommandTransferTracks gc = new GarminCommandTransferTracks( ss );
GarminGPXWriter w = new GarminGPXWriter( gc );
w.Data.WriteXml( "outputFile.gpx" );
NOTE: When using GarminCommandMonitorPositionVelocityTime, if
the device doesn't have a lock, this command will fail after a timeout period
of 5 seconds.
EXTENDING THE LIBRARY:
To do a proper build, you'll need NAnt, NAntContrib
(with patches), NUnit 2.2 or better, and
access to the OpenGPS Perforce
repository (see below on Perforce notes). Although to simply work on the library, you'll only need Visual
Please refer to Garmin's protocol spec for extending the Garmin
GarminTransaction is the base class for any Garmin
protocol transaction. It implements checksums and error checking as
specified by the Garmin protocol spec, serial protocol, section 3.1.
It essentially encapsulates and handles L000, L001, L002. GarminDeviceCommand
inherits from GarminTransaction and implements A010, Pid_Command_Data.
You should be able to inherit from either of these two classes to implement any
transactional commands on Garmin GPS devices.
PVT Implementation information: Garmin's documentation states
Cmnd_Start_Pvt_Data/Cmnd_Stop_Pvt_Data tells the device to start sending
Position/Velocity/Time data to the system at regular intervals. Garmin
devices support PVT data that is interspersed with other commands. Due to
the transactional nature of my Garmin protocol implementation, this is not
supported. PVT is turned on when you tell the object to Start() and
is turned off when you tell the object to Stop(); if PVT is on, then no other
commands can be issued.
Perforce notes: When SourceForge
[supposedly sometime this year], I'll put the repository online in
subversion, but I really don't want to put it in CVS right now if I can
avoid it. Once you get used to a real version control system, you
find things like CVS pretty limiting. For right now, I run the
Perforce server on my own machine and it is inaccessible from the
outside work. For now, I'll take e-mail code submissions for
OpenGPS.NET to andrewk_AT_koransky_dot_com. If this becomes too
much of a pain, I'll find a way to open it up. Thanks for your
TO DO (the never ending list):
Make PVT abort command Cmnd_Stop_Pvt_Data instead.
Better error handling.
Test WinCE support (should basically work as is, but device enumeration in
AutoFindDetector will not work.)
Cmnd_Transfer_Wpt - waypoint transfer
Cmnd_Transfer_Rte - route transfer
Cmnd_Transfer_Laps - lap transfer (fortrex?)
Cmnd_Transfer_Prx - Proximity waypoints
Cmnd_Transfer_Alm - Satellite Almanac
Cmnd_FlightBook_Transfer - FlightBook transfer
Cmnd_Transfer_Wpt_Cats - Waypoint Categories
Transcoding between different geometries (IE WGS84 to UTM and
back). Only WGS84 is handled now.
I wrote this library to talk to grab the track logs and get position
information so I could geocode photos. I noted that on the internet,
there were code snippets for
parsing NMEA sentences and performing serial
communication. I found it amazing that no one had pieced this
code together, so that was my first step. I took me less than 2 hours to
have a working NMEA interpreter. Many, many thanks go Jon Person (author
of GPS.NET) and
Marcus Lorentzon. AutoFindDetector and
Garmin protocol implementation took a bit longer... :-)
I will likely not have much time to work on this. I therefore release this
in open source form to the public domain in hopes that its development will
continue such that this library becomes fully documented and a useful piece of
software to anyone who needs their software to talk to a GPS.
Last updated 07/03/2005 12:04:05 PM