Share |

Building GPS applications using Visual Basic .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 Basic .Net and the Eye4Software GPS Component installed on your computer. We will use Visual Basic .Net in this document, but other versions from 2003 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 Basic .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 objGps          As Gps
Private objGpsConstants As GpsConstants

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 Basic .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.

Imports GpsToolkit

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents GroupBox5 As System.Windows.Forms.GroupBox
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents ColumnPrn As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnElevation As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnAzimuth As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnSignal As System.Windows.Forms.ColumnHeader
    Friend WithEvents ButtonStart As System.Windows.Forms.Button
    Friend WithEvents ButtonStop As System.Windows.Forms.Button
    Friend WithEvents CheckBoxCrc As System.Windows.Forms.CheckBox
    Friend WithEvents TextBoxLatitude As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxLongitude As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxSpeed As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxCourse As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxAltitude As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxTime As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxFix As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxSats As System.Windows.Forms.TextBox
    Friend WithEvents ComboBoxPort As System.Windows.Forms.ComboBox
    Friend WithEvents ComboBoxBaudrate As System.Windows.Forms.ComboBox
    Friend WithEvents TextBoxResult As System.Windows.Forms.TextBox
    Friend WithEvents TextBoxLogfile As System.Windows.Forms.TextBox
    Friend WithEvents CheckBoxLogData As System.Windows.Forms.CheckBox
    Friend WithEvents ButtonBrowse As System.Windows.Forms.Button
    Friend WithEvents ButtonView As System.Windows.Forms.Button
    Friend WithEvents Timer As System.Timers.Timer
    Friend WithEvents ListSats As System.Windows.Forms.ListView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.ComboBoxBaudrate = New System.Windows.Forms.ComboBox
        Me.ComboBoxPort = New System.Windows.Forms.ComboBox
        Me.CheckBoxCrc = New System.Windows.Forms.CheckBox
        Me.ButtonStop = New System.Windows.Forms.Button
        Me.ButtonStart = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.TextBoxSats = New System.Windows.Forms.TextBox
        Me.TextBoxFix = New System.Windows.Forms.TextBox
        Me.TextBoxTime = New System.Windows.Forms.TextBox
        Me.TextBoxAltitude = New System.Windows.Forms.TextBox
        Me.TextBoxCourse = New System.Windows.Forms.TextBox
        Me.TextBoxSpeed = New System.Windows.Forms.TextBox
        Me.TextBoxLongitude = New System.Windows.Forms.TextBox
        Me.TextBoxLatitude = New System.Windows.Forms.TextBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.Label9 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.ListSats = New System.Windows.Forms.ListView
        Me.ColumnPrn = New System.Windows.Forms.ColumnHeader
        Me.ColumnElevation = New System.Windows.Forms.ColumnHeader
        Me.ColumnAzimuth = New System.Windows.Forms.ColumnHeader
        Me.ColumnSignal = New System.Windows.Forms.ColumnHeader
        Me.GroupBox4 = New System.Windows.Forms.GroupBox
        Me.TextBoxResult = New System.Windows.Forms.TextBox
        Me.Label11 = New System.Windows.Forms.Label
        Me.GroupBox5 = New System.Windows.Forms.GroupBox
        Me.ButtonView = New System.Windows.Forms.Button
        Me.ButtonBrowse = New System.Windows.Forms.Button
        Me.CheckBoxLogData = New System.Windows.Forms.CheckBox
        Me.TextBoxLogfile = New System.Windows.Forms.TextBox
        Me.Label12 = New System.Windows.Forms.Label
        Me.Timer = New System.Timers.Timer
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.GroupBox5.SuspendLayout()
        CType(Me.Timer, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.ComboBoxBaudrate)
        Me.GroupBox1.Controls.Add(Me.ComboBoxPort)
        Me.GroupBox1.Controls.Add(Me.CheckBoxCrc)
        Me.GroupBox1.Controls.Add(Me.ButtonStop)
        Me.GroupBox1.Controls.Add(Me.ButtonStart)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 0)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(512, 80)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "GPS Device"
        '
        'ComboBoxBaudrate
        '
        Me.ComboBoxBaudrate.Location = New System.Drawing.Point(320, 24)
        Me.ComboBoxBaudrate.Name = "ComboBoxBaudrate"
        Me.ComboBoxBaudrate.Size = New System.Drawing.Size(104, 21)
        Me.ComboBoxBaudrate.TabIndex = 6
        '
        'ComboBoxPort
        '
        Me.ComboBoxPort.Location = New System.Drawing.Point(72, 24)
        Me.ComboBoxPort.Name = "ComboBoxPort"
        Me.ComboBoxPort.Size = New System.Drawing.Size(176, 21)
        Me.ComboBoxPort.TabIndex = 5
        '
        'CheckBoxCrc
        '
        Me.CheckBoxCrc.Location = New System.Drawing.Point(264, 48)
        Me.CheckBoxCrc.Name = "CheckBoxCrc"
        Me.CheckBoxCrc.Size = New System.Drawing.Size(152, 24)
        Me.CheckBoxCrc.TabIndex = 4
        Me.CheckBoxCrc.Text = "Enable &CRC Checking"
        '
        'ButtonStop
        '
        Me.ButtonStop.Location = New System.Drawing.Point(168, 48)
        Me.ButtonStop.Name = "ButtonStop"
        Me.ButtonStop.Size = New System.Drawing.Size(80, 20)
        Me.ButtonStop.TabIndex = 3
        Me.ButtonStop.Text = "S&top"
        '
        'ButtonStart
        '
        Me.ButtonStart.Location = New System.Drawing.Point(72, 48)
        Me.ButtonStart.Name = "ButtonStart"
        Me.ButtonStart.Size = New System.Drawing.Size(88, 20)
        Me.ButtonStart.TabIndex = 2
        Me.ButtonStart.Text = "&Start"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(264, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(88, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "&Baudrate:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "&Port:"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.TextBoxSats)
        Me.GroupBox2.Controls.Add(Me.TextBoxFix)
        Me.GroupBox2.Controls.Add(Me.TextBoxTime)
        Me.GroupBox2.Controls.Add(Me.TextBoxAltitude)
        Me.GroupBox2.Controls.Add(Me.TextBoxCourse)
        Me.GroupBox2.Controls.Add(Me.TextBoxSpeed)
        Me.GroupBox2.Controls.Add(Me.TextBoxLongitude)
        Me.GroupBox2.Controls.Add(Me.TextBoxLatitude)
        Me.GroupBox2.Controls.Add(Me.Label10)
        Me.GroupBox2.Controls.Add(Me.Label9)
        Me.GroupBox2.Controls.Add(Me.Label8)
        Me.GroupBox2.Controls.Add(Me.Label7)
        Me.GroupBox2.Controls.Add(Me.Label6)
        Me.GroupBox2.Controls.Add(Me.Label5)
        Me.GroupBox2.Controls.Add(Me.Label4)
        Me.GroupBox2.Controls.Add(Me.Label3)
        Me.GroupBox2.Location = New System.Drawing.Point(8, 88)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(512, 128)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "GPS position and information"
        '
        'TextBoxSats
        '
        Me.TextBoxSats.Location = New System.Drawing.Point(320, 96)
        Me.TextBoxSats.Name = "TextBoxSats"
        Me.TextBoxSats.ReadOnly = True
        Me.TextBoxSats.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxSats.TabIndex = 15
        Me.TextBoxSats.Text = ""
        '
        'TextBoxFix
        '
        Me.TextBoxFix.Location = New System.Drawing.Point(320, 72)
        Me.TextBoxFix.Name = "TextBoxFix"
        Me.TextBoxFix.ReadOnly = True
        Me.TextBoxFix.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxFix.TabIndex = 14
        Me.TextBoxFix.Text = ""
        '
        'TextBoxTime
        '
        Me.TextBoxTime.Location = New System.Drawing.Point(320, 48)
        Me.TextBoxTime.Name = "TextBoxTime"
        Me.TextBoxTime.ReadOnly = True
        Me.TextBoxTime.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxTime.TabIndex = 13
        Me.TextBoxTime.Text = ""
        '
        'TextBoxAltitude
        '
        Me.TextBoxAltitude.Location = New System.Drawing.Point(320, 24)
        Me.TextBoxAltitude.Name = "TextBoxAltitude"
        Me.TextBoxAltitude.ReadOnly = True
        Me.TextBoxAltitude.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxAltitude.TabIndex = 12
        Me.TextBoxAltitude.Text = ""
        '
        'TextBoxCourse
        '
        Me.TextBoxCourse.Location = New System.Drawing.Point(72, 96)
        Me.TextBoxCourse.Name = "TextBoxCourse"
        Me.TextBoxCourse.ReadOnly = True
        Me.TextBoxCourse.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxCourse.TabIndex = 11
        Me.TextBoxCourse.Text = ""
        '
        'TextBoxSpeed
        '
        Me.TextBoxSpeed.Location = New System.Drawing.Point(72, 72)
        Me.TextBoxSpeed.Name = "TextBoxSpeed"
        Me.TextBoxSpeed.ReadOnly = True
        Me.TextBoxSpeed.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxSpeed.TabIndex = 10
        Me.TextBoxSpeed.Text = ""
        '
        'TextBoxLongitude
        '
        Me.TextBoxLongitude.Location = New System.Drawing.Point(72, 48)
        Me.TextBoxLongitude.Name = "TextBoxLongitude"
        Me.TextBoxLongitude.ReadOnly = True
        Me.TextBoxLongitude.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxLongitude.TabIndex = 9
        Me.TextBoxLongitude.Text = ""
        '
        'TextBoxLatitude
        '
        Me.TextBoxLatitude.Location = New System.Drawing.Point(72, 24)
        Me.TextBoxLatitude.Name = "TextBoxLatitude"
        Me.TextBoxLatitude.ReadOnly = True
        Me.TextBoxLatitude.Size = New System.Drawing.Size(184, 20)
        Me.TextBoxLatitude.TabIndex = 8
        Me.TextBoxLatitude.Text = ""
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(264, 96)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(72, 16)
        Me.Label10.TabIndex = 7
        Me.Label10.Text = "Sats:"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(264, 72)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(72, 16)
        Me.Label9.TabIndex = 6
        Me.Label9.Text = "Fix:"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(264, 48)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(80, 16)
        Me.Label8.TabIndex = 5
        Me.Label8.Text = "Time:"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(264, 24)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(72, 16)
        Me.Label7.TabIndex = 4
        Me.Label7.Text = "Altitude:"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(16, 96)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(64, 16)
        Me.Label6.TabIndex = 3
        Me.Label6.Text = "Course:"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(16, 72)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(80, 16)
        Me.Label5.TabIndex = 2
        Me.Label5.Text = "Speed:"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 48)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(72, 16)
        Me.Label4.TabIndex = 1
        Me.Label4.Text = "Longitude:"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(88, 16)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "Latitude:"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.ListSats)
        Me.GroupBox3.Location = New System.Drawing.Point(8, 224)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(512, 176)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Satellites used for fix"
        '
        'ListSats
        '
        Me.ListSats.Columns.AddRange(New System.Windows.Forms.ColumnHeader() 
        {Me.ColumnPrn, Me.ColumnElevation, Me.ColumnAzimuth, Me.ColumnSignal})
        Me.ListSats.FullRowSelect = True
        Me.ListSats.GridLines = True
        Me.ListSats.Location = New System.Drawing.Point(8, 24)
        Me.ListSats.Name = "ListSats"
        Me.ListSats.Size = New System.Drawing.Size(496, 144)
        Me.ListSats.TabIndex = 0
        Me.ListSats.View = System.Windows.Forms.View.Details
        '
        'ColumnPrn
        '
        Me.ColumnPrn.Text = "PRN#"
        '
        'ColumnElevation
        '
        Me.ColumnElevation.Text = "Elevation"
        Me.ColumnElevation.Width = 88
        '
        'ColumnAzimuth
        '
        Me.ColumnAzimuth.Text = "Azimuth"
        Me.ColumnAzimuth.Width = 87
        '
        'ColumnSignal
        '
        Me.ColumnSignal.Text = "Signal (db)"
        Me.ColumnSignal.Width = 86
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.Add(Me.TextBoxResult)
        Me.GroupBox4.Controls.Add(Me.Label11)
        Me.GroupBox4.Location = New System.Drawing.Point(8, 496)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(512, 56)
        Me.GroupBox4.TabIndex = 3
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "Result of last operation"
        '
        'TextBoxResult
        '
        Me.TextBoxResult.Location = New System.Drawing.Point(72, 24)
        Me.TextBoxResult.Name = "TextBoxResult"
        Me.TextBoxResult.ReadOnly = True
        Me.TextBoxResult.Size = New System.Drawing.Size(432, 20)
        Me.TextBoxResult.TabIndex = 1
        Me.TextBoxResult.Text = ""
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(16, 24)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(88, 16)
        Me.Label11.TabIndex = 0
        Me.Label11.Text = "Result:"
        '
        'GroupBox5
        '
        Me.GroupBox5.Controls.Add(Me.ButtonView)
        Me.GroupBox5.Controls.Add(Me.ButtonBrowse)
        Me.GroupBox5.Controls.Add(Me.CheckBoxLogData)
        Me.GroupBox5.Controls.Add(Me.TextBoxLogfile)
        Me.GroupBox5.Controls.Add(Me.Label12)
        Me.GroupBox5.Location = New System.Drawing.Point(8, 408)
        Me.GroupBox5.Name = "GroupBox5"
        Me.GroupBox5.Size = New System.Drawing.Size(512, 80)
        Me.GroupBox5.TabIndex = 4
        Me.GroupBox5.TabStop = False
        Me.GroupBox5.Text = "Logging options"
        '
        'ButtonView
        '
        Me.ButtonView.Location = New System.Drawing.Point(416, 48)
        Me.ButtonView.Name = "ButtonView"
        Me.ButtonView.Size = New System.Drawing.Size(88, 20)
        Me.ButtonView.TabIndex = 4
        Me.ButtonView.Text = "&View..."
        '
        'ButtonBrowse
        '
        Me.ButtonBrowse.Location = New System.Drawing.Point(320, 48)
        Me.ButtonBrowse.Name = "ButtonBrowse"
        Me.ButtonBrowse.Size = New System.Drawing.Size(88, 20)
        Me.ButtonBrowse.TabIndex = 3
        Me.ButtonBrowse.Text = "Br&owse..."
        '
        'CheckBoxLogData
        '
        Me.CheckBoxLogData.Location = New System.Drawing.Point(72, 48)
        Me.CheckBoxLogData.Name = "CheckBoxLogData"
        Me.CheckBoxLogData.TabIndex = 2
        Me.CheckBoxLogData.Text = "Log NMEA data"
        '
        'TextBoxLogfile
        '
        Me.TextBoxLogfile.Location = New System.Drawing.Point(72, 24)
        Me.TextBoxLogfile.Name = "TextBoxLogfile"
        Me.TextBoxLogfile.Size = New System.Drawing.Size(432, 20)
        Me.TextBoxLogfile.TabIndex = 1
        Me.TextBoxLogfile.Text = ""
        '
        'Label12
        '
        Me.Label12.Location = New System.Drawing.Point(16, 24)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(48, 16)
        Me.Label12.TabIndex = 0
        Me.Label12.Text = "&LogFile:"
        '
        'Timer
        '
        Me.Timer.Enabled = True
        Me.Timer.Interval = 1000
        Me.Timer.SynchronizingObject = Me
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(528, 558)
        Me.Controls.Add(Me.GroupBox5)
        Me.Controls.Add(Me.GroupBox4)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.Text = "GPS Demo - Built with the Eye4Gps Toolkit"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox5.ResumeLayout(False)
        CType(Me.Timer, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private objGps As Gps
    Private objGpsConstants As GpsConstants
    Private bOpened As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles MyBase.Load
        Dim i As Int16

        objGps = New Gps
        objGpsConstants = New GpsConstants

        For i = 1 To 16
            ComboBoxPort.Items.Add("COM" & i)
        Next

        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()
    End Sub

    
    Private Sub ButtonStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles ButtonStart.Click
        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) Then
            bOpened = True
        End If

        EnableControls()
    End Sub

    Private Function GetLastResult()
        TextBoxResult.Text = objGps.LastError & " (" & objGps.LastErrorDescription & ")"
        GetLastResult = objGps.LastError
    End Function

    Private Sub EnableControls()
        ButtonStart.Enabled = Not bOpened
        ButtonStop.Enabled = bOpened
        ComboBoxPort.Enabled = Not bOpened
        ComboBoxBaudrate.Enabled = Not bOpened
        CheckBoxCrc.Enabled = Not bOpened
        CheckBoxLogData.Enabled = Not bOpened
    End Sub

    Private Sub Timer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) 
    Handles Timer.Elapsed
        Dim ListItem As ListViewItem
        Dim objSat As GpsSatelliteInfo

        If (bOpened = True) Then
            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 = objGps.GetFirstSatellite()

            While (objGps.LastError = 0)
                If (objSat.UsedForFix = True) Then

                    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())
                End If

                objSat = objGps.GetNextSatellite()
            End While

            ListSats.Visible = True

        End If
    End Sub

    Private Sub ButtonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles ButtonStop.Click
        objGps.Close()

        bOpened = False

        EnableControls()
    End Sub

    Private Sub ButtonView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles ButtonView.Click
        If (System.IO.File.Exists(TextBoxLogfile.Text)) Then
            System.Diagnostics.Process.Start(TextBoxLogfile.Text)
        End If
    End Sub

    Private Sub ButtonBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles ButtonBrowse.Click
        Dim SaveDialog As SaveFileDialog

        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) Then
            Exit Sub
        End If

        TextBoxLogfile.Text = SaveDialog.FileName
    End Sub
End Class