Have you ever wanted to connect to a GPS device within your own custom application? In the past, this was a difficult task for the average programmer using languages like C++. Fortunately, Microsoft’s .NET framework along with the C# programming language has made this task much easier.
Recently I came across a tutorial on Microsoft’s Coding for Fun site that showed how to connect and read data from a GPS device. I encourage you to read the article, download the source code, and experiment with their solution. It works great although I did come across a math error in their code that I will discuss in a future post.
In order to test the application, you should connect a GPS device to one of your USB ports. Any GPS-enabled device that can export data in the NMEA format will work. Older GPS devices that use a serial port connection will need a Serial to USB adapter. For example, I have a Garmin eTrex Vista along with a Serial to USB adapter that works fine. Recently though I purchased a Pharos iGPS-500 receiver and that functions even better. Since it is powered through the computer, you can leave it run for hours while testing the application and not waste batteries.
The application should compile error free and display a form with four tabs. First chose which COM port your GPS device is connected to under the Set Up tab. If you are unsure, right-click on My Computer and chose Manage. This brings up the Computer Management menu where you can select the Device Manager and navigate to the Ports item on the right-hand list. Here your GPS device will be represented by whatever connector you are using (note the COM port in the parenthesis).
Press the Connect button and wait several seconds. If everything is working right, your current location should be displayed in the Summary tab. To see the actual NMEA data, look at the Raw NMEA Data tab.
As I mentioned above, I believe there is a math error in their code so the latitude location is slightly off. But for now we just want to make sure the overall setup is functioning properly.
Hopefully this introduction will show you how easy it is to read from a GPS device. In the next post, we will breakdown their code, make some changes, and work on producing a DLL that can used in any project requiring GPS input.