Share |

Building GPS applications using Visual C# .Net

Download Eye4Software GPS Toolkit free trial Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free
Browse through the Eye4Software GPS Toolkit for Windows manual Browse through the Eye4Software GPS Toolkit manual

Introduction

The Eye4Software GPS toolkit allows software developers to add GPS functionality to their own programs without the need to have any knowledge on serial communications and GPS protocols like RS-232 and NMEA0183.

The product can be used in many programming environments, such as Visual Basic, Visual C++, Visual Studio.Net, Borland C++ Builder, Borland Delphi and VBA, but also web oriented applications such as ASP, ASP.NET and PHP, and all other programming environments that support ActiveX.

Prerequisites

First you must have Visual C# .Net and the Eye4Software GPS Component installed on your computer. We will use Visual C# .Net 2008 in this document, but other versions from 2002 and up can be used. You can download the Eye4Software GPS Component here.

Creating the project

Start the Visual Studio IDE, and select the "New" => "Project" option from the "File" menu. The "New Project" dialog now appears, select the "Windows Application" option to generate a Windows GUI application.

Add a reference to the ActiveX component

In order to declare and create the objects from your Visual C# .Net application, you need to add a reference to the ActiveX object, by choosing the "Add Reference..." option from the "Project" menu. A list of components installed on the system is displayed. Just select the "COM" tab, and select the "Eye4Software GPS Toolkit 2.2", click "Select" and finally click "OK".

Declare and create the object(s)

After adding the reference to the control, you can declare the objects like this:

private Gps          objGps;
private GpsConstants objGpsConstants;

The objects can be created in your code by double clicking on the Form you created, this will open the Formx_Load handler. Paste the following code in this function:

objGps          = new Gps ();
objGpsConstants = new GpsConstants ();

The source code

Below you can find the sourcecode from the Visual C# .Net demo as shipped with the project. Using this sample program, you can choose the serial port the GPS is connected to and start reading data from the GPS device. The software will display your current position, altitude, satellites in view, speed and course.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using GpsToolkit;

namespace Demo
{
   /// <summary>
   /// Summary description for Form1.
   /// </summary>
   public class Form1 : System.Windows.Forms.Form
   {
      internal System.Windows.Forms.GroupBox GroupBox5;
      internal System.Windows.Forms.Button ButtonView;
      internal System.Windows.Forms.Button ButtonBrowse;
      internal System.Windows.Forms.CheckBox CheckBoxLogData;
      internal System.Windows.Forms.TextBox TextBoxLogfile;
      internal System.Windows.Forms.Label Label12;
      internal System.Windows.Forms.GroupBox GroupBox4;
      internal System.Windows.Forms.TextBox TextBoxResult;
      internal System.Windows.Forms.Label Label11;
      internal System.Windows.Forms.GroupBox GroupBox3;
      internal System.Windows.Forms.ListView ListSats;
      internal System.Windows.Forms.ColumnHeader ColumnPrn;
      internal System.Windows.Forms.ColumnHeader ColumnElevation;
      internal System.Windows.Forms.ColumnHeader ColumnAzimuth;
      internal System.Windows.Forms.ColumnHeader ColumnSignal;
      internal System.Windows.Forms.GroupBox GroupBox2;
      internal System.Windows.Forms.TextBox TextBoxSats;
      internal System.Windows.Forms.TextBox TextBoxFix;
      internal System.Windows.Forms.TextBox TextBoxTime;
      internal System.Windows.Forms.TextBox TextBoxAltitude;
      internal System.Windows.Forms.TextBox TextBoxCourse;
      internal System.Windows.Forms.TextBox TextBoxSpeed;
      internal System.Windows.Forms.TextBox TextBoxLongitude;
      internal System.Windows.Forms.TextBox TextBoxLatitude;
      internal System.Windows.Forms.Label Label10;
      internal System.Windows.Forms.Label Label9;
      internal System.Windows.Forms.Label Label8;
      internal System.Windows.Forms.Label Label7;
      internal System.Windows.Forms.Label Label6;
      internal System.Windows.Forms.Label Label5;
      internal System.Windows.Forms.Label Label4;
      internal System.Windows.Forms.Label Label3;
      internal System.Windows.Forms.GroupBox GroupBox1;
      internal System.Windows.Forms.ComboBox ComboBoxBaudrate;
      internal System.Windows.Forms.ComboBox ComboBoxPort;
      internal System.Windows.Forms.CheckBox CheckBoxCrc;
      internal System.Windows.Forms.Button ButtonStop;
      internal System.Windows.Forms.Button ButtonStart;
      internal System.Windows.Forms.Label Label2;
      internal System.Windows.Forms.Label Label1;
      private System.Windows.Forms.Timer timerUpdate;
      private System.ComponentModel.IContainer components;

      public Form1()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

         //
         // TODO: Add any constructor code after InitializeComponent call
         //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null) 
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.components = new System.ComponentModel.Container();
         this.GroupBox5 = new System.Windows.Forms.GroupBox();
         this.ButtonView = new System.Windows.Forms.Button();
         this.ButtonBrowse = new System.Windows.Forms.Button();
         this.CheckBoxLogData = new System.Windows.Forms.CheckBox();
         this.TextBoxLogfile = new System.Windows.Forms.TextBox();
         this.Label12 = new System.Windows.Forms.Label();
         this.GroupBox4 = new System.Windows.Forms.GroupBox();
         this.TextBoxResult = new System.Windows.Forms.TextBox();
         this.Label11 = new System.Windows.Forms.Label();
         this.GroupBox3 = new System.Windows.Forms.GroupBox();
         this.ListSats = new System.Windows.Forms.ListView();
         this.ColumnPrn = new System.Windows.Forms.ColumnHeader();
         this.ColumnElevation = new System.Windows.Forms.ColumnHeader();
         this.ColumnAzimuth = new System.Windows.Forms.ColumnHeader();
         this.ColumnSignal = new System.Windows.Forms.ColumnHeader();
         this.GroupBox2 = new System.Windows.Forms.GroupBox();
         this.TextBoxSats = new System.Windows.Forms.TextBox();
         this.TextBoxFix = new System.Windows.Forms.TextBox();
         this.TextBoxTime = new System.Windows.Forms.TextBox();
         this.TextBoxAltitude = new System.Windows.Forms.TextBox();
         this.TextBoxCourse = new System.Windows.Forms.TextBox();
         this.TextBoxSpeed = new System.Windows.Forms.TextBox();
         this.TextBoxLongitude = new System.Windows.Forms.TextBox();
         this.TextBoxLatitude = new System.Windows.Forms.TextBox();
         this.Label10 = new System.Windows.Forms.Label();
         this.Label9 = new System.Windows.Forms.Label();
         this.Label8 = new System.Windows.Forms.Label();
         this.Label7 = new System.Windows.Forms.Label();
         this.Label6 = new System.Windows.Forms.Label();
         this.Label5 = new System.Windows.Forms.Label();
         this.Label4 = new System.Windows.Forms.Label();
         this.Label3 = new System.Windows.Forms.Label();
         this.GroupBox1 = new System.Windows.Forms.GroupBox();
         this.ComboBoxBaudrate = new System.Windows.Forms.ComboBox();
         this.ComboBoxPort = new System.Windows.Forms.ComboBox();
         this.CheckBoxCrc = new System.Windows.Forms.CheckBox();
         this.ButtonStop = new System.Windows.Forms.Button();
         this.ButtonStart = new System.Windows.Forms.Button();
         this.Label2 = new System.Windows.Forms.Label();
         this.Label1 = new System.Windows.Forms.Label();
         this.timerUpdate = new System.Windows.Forms.Timer(this.components);
         this.GroupBox5.SuspendLayout();
         this.GroupBox4.SuspendLayout();
         this.GroupBox3.SuspendLayout();
         this.GroupBox2.SuspendLayout();
         this.GroupBox1.SuspendLayout();
         this.SuspendLayout();
         // 
         // GroupBox5
         // 
         this.GroupBox5.Controls.Add(this.ButtonView);
         this.GroupBox5.Controls.Add(this.ButtonBrowse);
         this.GroupBox5.Controls.Add(this.CheckBoxLogData);
         this.GroupBox5.Controls.Add(this.TextBoxLogfile);
         this.GroupBox5.Controls.Add(this.Label12);
         this.GroupBox5.Location = new System.Drawing.Point(8, 416);
         this.GroupBox5.Name = "GroupBox5";
         this.GroupBox5.Size = new System.Drawing.Size(512, 80);
         this.GroupBox5.TabIndex = 9;
         this.GroupBox5.TabStop = false;
         this.GroupBox5.Text = "Logging options";
         // 
         // ButtonView
         // 
         this.ButtonView.Location = new System.Drawing.Point(416, 48);
         this.ButtonView.Name = "ButtonView";
         this.ButtonView.Size = new System.Drawing.Size(88, 20);
         this.ButtonView.TabIndex = 4;
         this.ButtonView.Text = "&View...";
         this.ButtonView.Click += new System.EventHandler(this.ButtonView_Click);
         // 
         // ButtonBrowse
         // 
         this.ButtonBrowse.Location = new System.Drawing.Point(320, 48);
         this.ButtonBrowse.Name = "ButtonBrowse";
         this.ButtonBrowse.Size = new System.Drawing.Size(88, 20);
         this.ButtonBrowse.TabIndex = 3;
         this.ButtonBrowse.Text = "Br&owse...";
         this.ButtonBrowse.Click += new System.EventHandler(this.ButtonBrowse_Click);
         // 
         // CheckBoxLogData
         // 
         this.CheckBoxLogData.Location = new System.Drawing.Point(72, 48);
         this.CheckBoxLogData.Name = "CheckBoxLogData";
         this.CheckBoxLogData.TabIndex = 2;
         this.CheckBoxLogData.Text = "Log NMEA data";
         // 
         // TextBoxLogfile
         // 
         this.TextBoxLogfile.Location = new System.Drawing.Point(72, 24);
         this.TextBoxLogfile.Name = "TextBoxLogfile";
         this.TextBoxLogfile.Size = new System.Drawing.Size(432, 20);
         this.TextBoxLogfile.TabIndex = 1;
         this.TextBoxLogfile.Text = "";
         // 
         // Label12
         // 
         this.Label12.Location = new System.Drawing.Point(16, 24);
         this.Label12.Name = "Label12";
         this.Label12.Size = new System.Drawing.Size(48, 16);
         this.Label12.TabIndex = 0;
         this.Label12.Text = "&LogFile:";
         // 
         // GroupBox4
         // 
         this.GroupBox4.Controls.Add(this.TextBoxResult);
         this.GroupBox4.Controls.Add(this.Label11);
         this.GroupBox4.Location = new System.Drawing.Point(8, 504);
         this.GroupBox4.Name = "GroupBox4";
         this.GroupBox4.Size = new System.Drawing.Size(512, 56);
         this.GroupBox4.TabIndex = 8;
         this.GroupBox4.TabStop = false;
         this.GroupBox4.Text = "Result of last operation";
         // 
         // TextBoxResult
         // 
         this.TextBoxResult.Location = new System.Drawing.Point(72, 24);
         this.TextBoxResult.Name = "TextBoxResult";
         this.TextBoxResult.ReadOnly = true;
         this.TextBoxResult.Size = new System.Drawing.Size(432, 20);
         this.TextBoxResult.TabIndex = 1;
         this.TextBoxResult.Text = "";
         // 
         // Label11
         // 
         this.Label11.Location = new System.Drawing.Point(16, 24);
         this.Label11.Name = "Label11";
         this.Label11.Size = new System.Drawing.Size(88, 16);
         this.Label11.TabIndex = 0;
         this.Label11.Text = "Result:";
         // 
         // GroupBox3
         // 
         this.GroupBox3.Controls.Add(this.ListSats);
         this.GroupBox3.Location = new System.Drawing.Point(8, 232);
         this.GroupBox3.Name = "GroupBox3";
         this.GroupBox3.Size = new System.Drawing.Size(512, 176);
         this.GroupBox3.TabIndex = 7;
         this.GroupBox3.TabStop = false;
         this.GroupBox3.Text = "Satellites used for fix";
         // 
         // ListSats
         // 
         this.ListSats.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                                                                  this.ColumnPrn,
                                                                  this.ColumnElevation,
                                                                  this.ColumnAzimuth,
                                                                  this.ColumnSignal});
         this.ListSats.FullRowSelect = true;
         this.ListSats.GridLines = true;
         this.ListSats.Location = new System.Drawing.Point(8, 24);
         this.ListSats.Name = "ListSats";
         this.ListSats.Size = new System.Drawing.Size(496, 144);
         this.ListSats.TabIndex = 0;
         this.ListSats.View = System.Windows.Forms.View.Details;
         // 
         // ColumnPrn
         // 
         this.ColumnPrn.Text = "PRN#";
         // 
         // ColumnElevation
         // 
         this.ColumnElevation.Text = "Elevation";
         this.ColumnElevation.Width = 88;
         // 
         // ColumnAzimuth
         // 
         this.ColumnAzimuth.Text = "Azimuth";
         this.ColumnAzimuth.Width = 87;
         // 
         // ColumnSignal
         // 
         this.ColumnSignal.Text = "Signal (db)";
         this.ColumnSignal.Width = 86;
         // 
         // GroupBox2
         // 
         this.GroupBox2.Controls.Add(this.TextBoxSats);
         this.GroupBox2.Controls.Add(this.TextBoxFix);
         this.GroupBox2.Controls.Add(this.TextBoxTime);
         this.GroupBox2.Controls.Add(this.TextBoxAltitude);
         this.GroupBox2.Controls.Add(this.TextBoxCourse);
         this.GroupBox2.Controls.Add(this.TextBoxSpeed);
         this.GroupBox2.Controls.Add(this.TextBoxLongitude);
         this.GroupBox2.Controls.Add(this.TextBoxLatitude);
         this.GroupBox2.Controls.Add(this.Label10);
         this.GroupBox2.Controls.Add(this.Label9);
         this.GroupBox2.Controls.Add(this.Label8);
         this.GroupBox2.Controls.Add(this.Label7);
         this.GroupBox2.Controls.Add(this.Label6);
         this.GroupBox2.Controls.Add(this.Label5);
         this.GroupBox2.Controls.Add(this.Label4);
         this.GroupBox2.Controls.Add(this.Label3);
         this.GroupBox2.Location = new System.Drawing.Point(8, 96);
         this.GroupBox2.Name = "GroupBox2";
         this.GroupBox2.Size = new System.Drawing.Size(512, 128);
         this.GroupBox2.TabIndex = 6;
         this.GroupBox2.TabStop = false;
         this.GroupBox2.Text = "GPS position and information";
         // 
         // TextBoxSats
         // 
         this.TextBoxSats.Location = new System.Drawing.Point(320, 96);
         this.TextBoxSats.Name = "TextBoxSats";
         this.TextBoxSats.ReadOnly = true;
         this.TextBoxSats.Size = new System.Drawing.Size(184, 20);
         this.TextBoxSats.TabIndex = 15;
         this.TextBoxSats.Text = "";
         // 
         // TextBoxFix
         // 
         this.TextBoxFix.Location = new System.Drawing.Point(320, 72);
         this.TextBoxFix.Name = "TextBoxFix";
         this.TextBoxFix.ReadOnly = true;
         this.TextBoxFix.Size = new System.Drawing.Size(184, 20);
         this.TextBoxFix.TabIndex = 14;
         this.TextBoxFix.Text = "";
         // 
         // TextBoxTime
         // 
         this.TextBoxTime.Location = new System.Drawing.Point(320, 48);
         this.TextBoxTime.Name = "TextBoxTime";
         this.TextBoxTime.ReadOnly = true;
         this.TextBoxTime.Size = new System.Drawing.Size(184, 20);
         this.TextBoxTime.TabIndex = 13;
         this.TextBoxTime.Text = "";
         // 
         // TextBoxAltitude
         // 
         this.TextBoxAltitude.Location = new System.Drawing.Point(320, 24);
         this.TextBoxAltitude.Name = "TextBoxAltitude";
         this.TextBoxAltitude.ReadOnly = true;
         this.TextBoxAltitude.Size = new System.Drawing.Size(184, 20);
         this.TextBoxAltitude.TabIndex = 12;
         this.TextBoxAltitude.Text = "";
         // 
         // TextBoxCourse
         // 
         this.TextBoxCourse.Location = new System.Drawing.Point(72, 96);
         this.TextBoxCourse.Name = "TextBoxCourse";
         this.TextBoxCourse.ReadOnly = true;
         this.TextBoxCourse.Size = new System.Drawing.Size(184, 20);
         this.TextBoxCourse.TabIndex = 11;
         this.TextBoxCourse.Text = "";
         // 
         // TextBoxSpeed
         // 
         this.TextBoxSpeed.Location = new System.Drawing.Point(72, 72);
         this.TextBoxSpeed.Name = "TextBoxSpeed";
         this.TextBoxSpeed.ReadOnly = true;
         this.TextBoxSpeed.Size = new System.Drawing.Size(184, 20);
         this.TextBoxSpeed.TabIndex = 10;
         this.TextBoxSpeed.Text = "";
         // 
         // TextBoxLongitude
         // 
         this.TextBoxLongitude.Location = new System.Drawing.Point(72, 48);
         this.TextBoxLongitude.Name = "TextBoxLongitude";
         this.TextBoxLongitude.ReadOnly = true;
         this.TextBoxLongitude.Size = new System.Drawing.Size(184, 20);
         this.TextBoxLongitude.TabIndex = 9;
         this.TextBoxLongitude.Text = "";
         // 
         // TextBoxLatitude
         // 
         this.TextBoxLatitude.Location = new System.Drawing.Point(72, 24);
         this.TextBoxLatitude.Name = "TextBoxLatitude";
         this.TextBoxLatitude.ReadOnly = true;
         this.TextBoxLatitude.Size = new System.Drawing.Size(184, 20);
         this.TextBoxLatitude.TabIndex = 8;
         this.TextBoxLatitude.Text = "";
         // 
         // Label10
         // 
         this.Label10.Location = new System.Drawing.Point(264, 96);
         this.Label10.Name = "Label10";
         this.Label10.Size = new System.Drawing.Size(72, 16);
         this.Label10.TabIndex = 7;
         this.Label10.Text = "Sats:";
         // 
         // Label9
         // 
         this.Label9.Location = new System.Drawing.Point(264, 72);
         this.Label9.Name = "Label9";
         this.Label9.Size = new System.Drawing.Size(72, 16);
         this.Label9.TabIndex = 6;
         this.Label9.Text = "Fix:";
         // 
         // Label8
         // 
         this.Label8.Location = new System.Drawing.Point(264, 48);
         this.Label8.Name = "Label8";
         this.Label8.Size = new System.Drawing.Size(80, 16);
         this.Label8.TabIndex = 5;
         this.Label8.Text = "Time:";
         // 
         // Label7
         // 
         this.Label7.Location = new System.Drawing.Point(264, 24);
         this.Label7.Name = "Label7";
         this.Label7.Size = new System.Drawing.Size(72, 16);
         this.Label7.TabIndex = 4;
         this.Label7.Text = "Altitude:";
         // 
         // Label6
         // 
         this.Label6.Location = new System.Drawing.Point(16, 96);
         this.Label6.Name = "Label6";
         this.Label6.Size = new System.Drawing.Size(64, 16);
         this.Label6.TabIndex = 3;
         this.Label6.Text = "Course:";
         // 
         // Label5
         // 
         this.Label5.Location = new System.Drawing.Point(16, 72);
         this.Label5.Name = "Label5";
         this.Label5.Size = new System.Drawing.Size(80, 16);
         this.Label5.TabIndex = 2;
         this.Label5.Text = "Speed:";
         // 
         // Label4
         // 
         this.Label4.Location = new System.Drawing.Point(16, 48);
         this.Label4.Name = "Label4";
         this.Label4.Size = new System.Drawing.Size(72, 16);
         this.Label4.TabIndex = 1;
         this.Label4.Text = "Longitude:";
         // 
         // Label3
         // 
         this.Label3.Location = new System.Drawing.Point(16, 24);
         this.Label3.Name = "Label3";
         this.Label3.Size = new System.Drawing.Size(88, 16);
         this.Label3.TabIndex = 0;
         this.Label3.Text = "Latitude:";
         // 
         // GroupBox1
         // 
         this.GroupBox1.Controls.Add(this.ComboBoxBaudrate);
         this.GroupBox1.Controls.Add(this.ComboBoxPort);
         this.GroupBox1.Controls.Add(this.CheckBoxCrc);
         this.GroupBox1.Controls.Add(this.ButtonStop);
         this.GroupBox1.Controls.Add(this.ButtonStart);
         this.GroupBox1.Controls.Add(this.Label2);
         this.GroupBox1.Controls.Add(this.Label1);
         this.GroupBox1.Location = new System.Drawing.Point(8, 8);
         this.GroupBox1.Name = "GroupBox1";
         this.GroupBox1.Size = new System.Drawing.Size(512, 80);
         this.GroupBox1.TabIndex = 5;
         this.GroupBox1.TabStop = false;
         this.GroupBox1.Text = "GPS Device";
         // 
         // ComboBoxBaudrate
         // 
         this.ComboBoxBaudrate.Location = new System.Drawing.Point(320, 24);
         this.ComboBoxBaudrate.Name = "ComboBoxBaudrate";
         this.ComboBoxBaudrate.Size = new System.Drawing.Size(104, 21);
         this.ComboBoxBaudrate.TabIndex = 6;
         // 
         // ComboBoxPort
         // 
         this.ComboBoxPort.Location = new System.Drawing.Point(72, 24);
         this.ComboBoxPort.Name = "ComboBoxPort";
         this.ComboBoxPort.Size = new System.Drawing.Size(176, 21);
         this.ComboBoxPort.TabIndex = 5;
         // 
         // CheckBoxCrc
         // 
         this.CheckBoxCrc.Location = new System.Drawing.Point(264, 48);
         this.CheckBoxCrc.Name = "CheckBoxCrc";
         this.CheckBoxCrc.Size = new System.Drawing.Size(152, 24);
         this.CheckBoxCrc.TabIndex = 4;
         this.CheckBoxCrc.Text = "Enable &CRC Checking";
         // 
         // ButtonStop
         // 
         this.ButtonStop.Location = new System.Drawing.Point(168, 48);
         this.ButtonStop.Name = "ButtonStop";
         this.ButtonStop.Size = new System.Drawing.Size(80, 20);
         this.ButtonStop.TabIndex = 3;
         this.ButtonStop.Text = "S&top";
         this.ButtonStop.Click += new System.EventHandler(this.ButtonStop_Click);
         // 
         // ButtonStart
         // 
         this.ButtonStart.Location = new System.Drawing.Point(72, 48);
         this.ButtonStart.Name = "ButtonStart";
         this.ButtonStart.Size = new System.Drawing.Size(88, 20);
         this.ButtonStart.TabIndex = 2;
         this.ButtonStart.Text = "&Start";
         this.ButtonStart.Click += new System.EventHandler(this.ButtonStart_Click);
         // 
         // Label2
         // 
         this.Label2.Location = new System.Drawing.Point(264, 24);
         this.Label2.Name = "Label2";
         this.Label2.Size = new System.Drawing.Size(88, 16);
         this.Label2.TabIndex = 1;
         this.Label2.Text = "&Baudrate:";
         // 
         // Label1
         // 
         this.Label1.Location = new System.Drawing.Point(16, 24);
         this.Label1.Name = "Label1";
         this.Label1.Size = new System.Drawing.Size(72, 16);
         this.Label1.TabIndex = 0;
         this.Label1.Text = "&Port:";
         // 
         // timerUpdate
         // 
         this.timerUpdate.Enabled = true;
         this.timerUpdate.Interval = 1000;
         this.timerUpdate.Tick += new System.EventHandler(this.timerUpdate_Tick);
         // 
         // Form1
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(528, 566);
         this.Controls.Add(this.GroupBox5);
         this.Controls.Add(this.GroupBox4);
         this.Controls.Add(this.GroupBox3);
         this.Controls.Add(this.GroupBox2);
         this.Controls.Add(this.GroupBox1);
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
         this.MaximizeBox = false;
         this.MinimizeBox = false;
         this.Name = "Form1";
         this.Text = "GPS Demo - Built with the Eye4Gps Toolkit";
         this.Load += new System.EventHandler(this.Form1_Load);
         this.GroupBox5.ResumeLayout(false);
         this.GroupBox4.ResumeLayout(false);
         this.GroupBox3.ResumeLayout(false);
         this.GroupBox2.ResumeLayout(false);
         this.GroupBox1.ResumeLayout(false);
         this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
         
      /*********************************************************************************/

      private Gps objGps;
      private GpsConstants objGpsConstants;
      private Boolean bOpened;
      
      /*********************************************************************************/
      [STAThread] 
      static void Main() 
      {
         Application.Run(new Form1());
      }

      /*********************************************************************************/

      private void Form1_Load(object sender, System.EventArgs e)
      {
         Int16 i;
         
         objGps = new Gps ();
         objGpsConstants = new GpsConstants ();

         for ( i = 1 ; i <= 16 ; i++ )
         {
            ComboBoxPort.Items.Add("COM" + i);
         }

         ComboBoxPort.SelectedIndex = 0;

         ComboBoxBaudrate.Items.Add("1200");
         ComboBoxBaudrate.Items.Add("2400");
         ComboBoxBaudrate.Items.Add("4800");
         ComboBoxBaudrate.Items.Add("9600");
         ComboBoxBaudrate.Items.Add("19200");
         ComboBoxBaudrate.Items.Add("38400");
         ComboBoxBaudrate.Items.Add("57600");
         ComboBoxBaudrate.Items.Add("115200");

         ComboBoxBaudrate.SelectedIndex = 2;

         TextBoxLogfile.Text = System.IO.Path.GetTempPath() + "GpsLog.txt";

           EnableControls();
      }

      /*********************************************************************************/

      private void EnableControls ()
      {
         ButtonStart.Enabled = !bOpened;
         ButtonStop.Enabled = bOpened;
         ComboBoxPort.Enabled = !bOpened;
         ComboBoxBaudrate.Enabled = !bOpened;
         CheckBoxCrc.Enabled = !bOpened;
         CheckBoxLogData.Enabled = !bOpened;
      }

      /*********************************************************************************/

      private void ButtonStart_Click(object sender, System.EventArgs e)
      {
         objGps.DeviceSerialPort = ComboBoxPort.SelectedIndex + 1;
         objGps.DeviceBaudrate = Int32.Parse(ComboBoxBaudrate.Text);
         objGps.EnableChecksum = CheckBoxCrc.Checked;
         objGps.DeviceTimeout = 2000;
         objGps.LogGpsData = CheckBoxLogData.Checked;
         objGps.LogFile = TextBoxLogfile.Text;

         objGps.UnitsAltitude = objGpsConstants.GPS_ALTITUDE_FEET;
         objGps.UnitsSpeed = objGpsConstants.GPS_SPEED_KNOTS;
         objGps.LatLonStringFormat = objGpsConstants.GPS_LATLONFORMAT_DM;

         objGps.Open();

         if (GetLastResult() == 0)
         {
            bOpened = true;
         }
         
         EnableControls();
      }

      /*********************************************************************************/

      private void ButtonStop_Click(object sender, System.EventArgs e)
      {
         objGps.Close();

         bOpened = false;

         EnableControls();
      }

      /*********************************************************************************/

      private void ButtonView_Click(object sender, System.EventArgs e)
      {
         if (System.IO.File.Exists(TextBoxLogfile.Text))
         {
            System.Diagnostics.Process.Start(TextBoxLogfile.Text);
         }
      }

      /*********************************************************************************/

      private void ButtonBrowse_Click(object sender, System.EventArgs e)
      {
         SaveFileDialog SaveDialog;
         
         SaveDialog = new SaveFileDialog ();
         SaveDialog.Title = "Select Logfile";
         SaveDialog.InitialDirectory = TextBoxLogfile.Text;
         SaveDialog.Filter = "All Files (*.*)|*.*|All files (*.*)|*.*";
         SaveDialog.FilterIndex = 1;
         SaveDialog.RestoreDirectory = true;

         if ( SaveDialog.ShowDialog () == DialogResult.OK )
         {
            TextBoxLogfile.Text = SaveDialog.FileName;
         }
      }

      /*********************************************************************************/
      
      private Int32 GetLastResult ()
      {
         Int32 nResult = objGps.LastError;

         TextBoxResult.Text = nResult.ToString () + " (" + objGps.LastErrorDescription + ")";

         return nResult;
      }
      
      /*********************************************************************************/
      
      private void timerUpdate_Tick(object sender, System.EventArgs e)
      {
         ListViewItem      ListItem;
         GpsSatelliteInfo  objSat;

         if ( bOpened == true )
         {
            TextBoxLongitude.Text = objGps.gpsLongitudeString;
            TextBoxLatitude.Text = objGps.gpsLatitudeString;
            TextBoxAltitude.Text = objGps.gpsAltitude.ToString() + " feet";
            TextBoxSpeed.Text = objGps.gpsSpeed.ToString() + " knots";
            TextBoxCourse.Text = objGps.gpsCourse.ToString() + " degrees";
            TextBoxTime.Text = objGps.gpsTimeString;
            TextBoxSats.Text = objGps.gpsSatellites.ToString();
            TextBoxFix.Text = objGps.gpsQuality.ToString();

            ListSats.Visible = false;

            ListSats.Items.Clear();

            objSat = ( GpsSatelliteInfo ) objGps.GetFirstSatellite();

            while (objGps.LastError == 0)
            {
               if (objSat.UsedForFix != 0)
               {
                  ListItem = ListSats.Items.Add(objSat.ID.ToString());

                  ListItem.SubItems.Add(objSat.Elevation.ToString());
                  ListItem.SubItems.Add(objSat.Azimuth.ToString());
                  ListItem.SubItems.Add(objSat.SignalNoiseRatio.ToString());
               }

               objSat = ( GpsSatelliteInfo ) objGps.GetNextSatellite();
            }

            ListSats.Visible = true;
         }
      }

      /*********************************************************************************/


   }
}