Access your GPS Radio with VB.Net code

What follows is the code for a module that can be inserted into a VB.net project. Call the sub with the comm port that the GPS radio is on and you are set. Also add a Serial Port Control to your form and name it “serialPort”. Timeout is required in case an incorrect serial port has been specified.

Programming note: Even with the timeout set in the code, the application will lock up if an incorrect, but active comm port has been specified. If you know of a fix post it in the comments.

Imports System
Imports System.IO.Ports

Module gps

    Public strLatitude As String = ""
    Public strLongitude As String = ""

    Public Sub queryGPS(ByVal cPort As String)
        Dim loopCount As Integer = 0
        Dim GPSOutput As String = ""
        Dim GPSGPRMCStr As String = ""
        Dim newLineStr As String = "$"
        Dim aStrSplitItems() As String
        Dim NSHemi As String = ""
        Dim EWHemi As String = ""
        Dim EW As Integer = 0
        Dim NS As Integer = 0
        Dim commQuit As Boolean = False
        Dim portClosed As Boolean = False
        Dim dblLatitude As Double = 0
        Dim dblLongitude As Double = 0
        Dim wsLatitude As String = ""
        Dim wsLongitude As String = ""
        'Set sentence to parse from GPS Output. Use GPRMC GPGLL, or GPGGA
        Dim strSentence As String = "GPRMC"

        'Reset coordinate variables()
        strLatitude = ""
        strLongitude = ""

        On Error GoTo Errhandler

        'Calls Serial Port Control on main form. Add Serial Port Control to form and name it "serialPort"
        'Timeout is required in case an incorrect serial port has been specified. Application will freeze
        'if timeout is missing or too lengthy.
        frmMain.serialPort = New SerialPort("COM" & cPort, 4800, Parity.None, 8, StopBits.One)
        frmMain.serialPort.ReadTimeout = 5
        frmMain.serialPort.Open()

readLine:
        Dim cCount As Integer = 0

        If portClosed = True Then
            frmMain.serialPort.Open()
            portClosed = False
        End If
        'Read GPS data from Device - Geographic Position, Latitude/Longitude
        GPSOutput = frmMain.serialPort.ReadLine.ToString
        GPSGPRMCStr = GPSOutput

        'Test string for debugging without a good GPS signal
        'GPSGPRMCStr = "GPRMC,174607.000,A,3411.3450,N,07946.0365,W,0.44,160.26,020910,,*12"

        If GPSGPRMCStr.Contains(strSentence) Then
            commQuit = True

            For i = 1 To Len(GPSGPRMCStr.ToString)
                If Mid$(GPSGPRMCStr.ToString, i, 1) = "," Then cCount = cCount + 1

                Select Case strSentence 'Set the line the program reads in the DIM statement above
                    Case "GPRMC"
                        Select Case cCount
                            Case 3 'Start collecting latitude
                                strLatitude = strLatitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 4 'Get Hemisphere
                                NSHemi = NSHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 5 'Start Collecting longitude
                                strLongitude = strLongitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 6 'Get Hemisphere
                                EWHemi = EWHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                        End Select
                    Case "GPGGA"
                        Select Case cCount
                            Case 2 'Start collecting latitude
                                strLatitude = strLatitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 3 'Get Hemisphere
                                NSHemi = NSHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 4 'Start Collecting longitude
                                strLongitude = strLongitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 5 'Get Hemisphere
                                EWHemi = EWHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                        End Select
                    Case "GPGLL"
                        Select Case cCount
                            Case 1 'Start collecting latitude
                                strLatitude = strLatitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 2 'Get Hemisphere
                                NSHemi = NSHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 3 'Start Collecting longitude
                                strLongitude = strLongitude & Mid$(GPSGPRMCStr.ToString, i, 1)
                            Case 4 'Get Hemisphere
                                EWHemi = EWHemi & Mid$(GPSGPRMCStr.ToString, i, 1)
                        End Select
                End Select
            Next
        Else
            GoTo readLine
        End If
        strLatitude = Microsoft.VisualBasic.Right(strLatitude, Len(strLatitude) - 1)
        NSHemi = Microsoft.VisualBasic.Right(NSHemi, Len(NSHemi) - 1)
        strLongitude = Microsoft.VisualBasic.Right(strLongitude, Len(strLongitude) - 1)
        EWHemi = Microsoft.VisualBasic.Right(EWHemi, Len(EWHemi) - 1)

        If NSHemi <> "" Then
            If NSHemi = "N" Then NSHemi = "" Else NSHemi = "-"
            If EWHemi = "E" Then EWHemi = "" Else EWHemi = "-"
        End If

        'Convert Lat and Long to decimel
        '********************************************************************
        'Strip leading Zeros
        dblLatitude = CDbl(strLatitude.ToString)
        dblLongitude = CDbl(strLongitude.ToString)
        'Add polarity
        If NSHemi = "-" Then
            dblLatitude = dblLatitude * -1
            NS = -1
        Else
            NS = 1
        End If
        If EWHemi = "-" Then
            dblLongitude = dblLongitude * -1
            EW = -1
        Else
            EW = 1
        End If

        'Move decimel place two places to the left
        dblLatitude = dblLatitude / 100
        dblLongitude = dblLongitude / 100

        'Get values left of decimel
        Dim leftLat As Integer = Math.Abs(dblLatitude)
        Dim leftLong As Integer = Math.Abs(dblLongitude)

        'Get values right of decimel
        Dim rightLat As Double = Math.Abs(dblLatitude) - Math.Abs(leftLat)
        Dim rightLong As Double = Math.Abs(dblLongitude) - Math.Abs(leftLong)

        'Convert to minutes
        rightLat = (rightLat * 100) / 60
        rightLong = (rightLong * 100) / 60

        'Lat/Long in decimel, in case you need decimel degrees instead of degrees/minutes/seconds.
        wsLatitude = Trim(Str(CDbl(strLatitude) * NS))
        wsLongitude = Trim(Str(CDbl(strLongitude) * EW))

        'Lat/long in Degrees/Minutes/Seconds in decimel form
        strLatitude = Trim(Str((leftLat + rightLat) * NS))
        strLongitude = Trim(Str((leftLong + rightLong) * EW))

        frmMain.serialPort.ReadBufferSize = 0
        frmMain.serialPort.Close()
        portClosed = True

        '*********************************************************************
        'Comment out else section when deployed. Work with results in main sub
        '*********************************************************************
        'Sometimes reception is poor and it takes more than one pass of the data to get a fix
        'This section forces another read of the GPS device when the coordinates are null or
        'contain zeros. Note: The application as written will fail on the prime meridian when
        'at the equator.
        If strLatitude = "" Or strLongitude = "" Or strLatitude = "0" Or strLongitude = "0" And commQuit = True Then
            loopCount = loopCount + 1
            If loopCount > 10 Then
                MsgBox("The GPS device is currently not getting a fix, please try again later." _
                      & Chr(10) & GPSOutput, vbOKOnly, "Satellite Communication Unavailable")
                Exit Sub
            Else
                GoTo readLine
            End If
        Else
            'Access web service from arc to return a list of addresses within a certain range of the inspector's location.
            'Web Service is currently in SC stateplane.

            'A google test.
            'System.Diagnostics.Process.Start("http://maps.google.com/maps?q=" & strLatitude & "%2C" & strLongitude)
        End If
        '********************************************************************
        Exit Sub
Errhandler:

        Select Case Err.Number
            Case 5
                Resume Next
            Case 13
                'MsgBox(Err.Number & " " & Err.Description)
                Resume Next
            Case 57
                'MsgBox(Err.Number & " " & Err.Description)
                MsgBox("Comm Port not available", MsgBoxStyle.Exclamation, "Communication Error.")
                Exit Sub
            Case 91
                'MsgBox(Err.Number & " " & Err.Description)
                Resume Next
            Case 8002
                'GPSComm.PortOpen = False
                MsgBox("Comm Port not available", MsgBoxStyle.Exclamation, "Communication Error.")
                'GPSComm.PortOpen = True
                Resume Next
                Exit Sub
            Case Else
                MsgBox(Err.Number & " " & Err.Description)
                Resume
                Resume Next
        End Select
    End Sub
End Module

 

Advertisements

ARCGIS 10.0 and 10.1 Deprecation Document

ESRI has released this deprecation document. If you haven’t already seen it this will inform you of the items that ARC will be discontinuing in the current and future releases of their products.

ARCGIS 10

ARCGIS DESKTOP 10.0

  • ArcGIS 10.0 is the last release of Microsoft Visual Basic for Applications (VBA); we will no longer support VBA beyond the ArcGIS 10.0 release. Microsoft no longer promotes or updates VBA. ESRI strongly recommends that no further development occur on this platform. Beyond ArcGIS 10.0, ESRI will no longer be able to support VBA as a development platform. Users who have custom functionality built using VBA should actively plan strategies to rewrite their applications using a supported development language such as Python, VB.NET, or C# so their applications continue to be operational and supported in future releases of ArcGIS.
  • ArcGIS 10.0 is the last release of Solaris support for ArcReader and ArcGIS Engine; we will no longer support the Solaris platform for this functionality beyond ArcGIS 10.0 due to limited demand for this platform.

ARCINFO WORKSTATION 10.0

  • ArcGIS 10.0 is the last planned release of ArcInfo Workstation. However, ArcInfo Workstation 10.0 can be used in conjunction with newer versions of ArcGIS Desktop; known issues are that ArcDoc will not open in Windows versions that do not include legacy Windows Help support, and that the SDE layer and DBMS connect functionality will not be upgraded beyond the versions supported at ArcGIS 10. Users will continue to be able to use their existing ArcInfo Workstation 10 version as the rest of the ArcGIS products and technologies evolve, but we will not release newer versions of ArcInfo Workstation.

ARCIMS 10.0

  • ArcGIS 10.0 is the last release of ArcIMS on Solaris; we will no longer support ArcIMS on the Solaris Platform after ArcGIS 10.0. We feel the demand for the Solaris platform has diminished significantly and plan on ArcGIS 10.0 being the final release of Solaris support for all products, with the exception of SDE technology, which will continue to be supported on this platform.
  • ArcGIS 10.0 is the last release of the ArcIMS Metadata Server; we will no longer support this functionality after ArcGIS 10.0. With the advent of the new search technology in the ArcGIS Geoportal Extension 9.3.1, and in ArcGIS Server 10.0, we no longer see a need to maintain this technology.
  • The next major release after ArcGIS 10.0 will be the last planned release for ArcIMS. Users can continue to use existing versions of ArcIMS after this time; however, we will no longer provide new releases.

ARCGIS SERVER 10.0

  • ArcGIS 10.0 is the last ArcGIS Server release with support for Solaris (with the exception of the ArcSDE technology component); we will not support this platform after ArcGIS 10.0 due to limited demand for the Solaris server platform. We will continue to support the ArcSDE component of ArcGIS Server on the Solaris platform beyond the ArcGIS 10.0 release.
  • ArcGIS Server 10.0 is the last ArcGIS Server release with support for local connections from Web ADF applications. The 10.1 Web ADF applications will only support local connections to Server versions prior to 10.1. We recommend developers using local connections for accessing fine-grained ArcObjects migrate their business logic to Server Object Extensions. For Web ADF based editing applications (all of which use Local connections), we urge users to look at alternative web editing tools based in the ArcGIS Web Mapping APIs.
  • ArcGIS Server 10.0 is the last release with support for 32-bit operating systems. The next release of ArcGIS Server (10.1) will run natively as a 64-bit application, requiring 64-bit operating systems.
  • ArcGIS Server 10.0 is the last release with support for VBScript or JScript on ArcGIS Server for Linux. VBScript and JScript will continue to be supported on ArcGIS Server for Microsoft Windows. Python scripting will be added as a replacement for these scripting languages and ArcGIS Desktop will support authoring Python scripts in areas where VBScript and JScript are presently used.
  • ArcGIS Server 10.0 is the last release supporting publishing non-optimized map documents (MXD files). The next major release will only support publishing optimized maps (MSDs) as that is the best practice for map publishing.

ARCGIS IMAGE SERVER 10.0

  • ArcGIS 10.0 is the last release of the stand-alone ArcGIS Image Server product. This product has been replaced with the ArcGIS Server Image Extension. Any existing users of the stand-alone Image Server product or technology (using ISDef files), should plan their migration to the ArcGIS Server Image extension. Existing ArcGIS Image Server users should migrate from using ISDef file to using the Mosaic Datasets, a new data model in the geodatabase for managing collections of imagery and rasters. Mosaic Datasets are created and edited with ArcGIS Desktop (ArcEditor and ArcInfo) and published using ArcGIS Server with the Image Extension. Existing ISDef files can be added to Mosaic Datasets for conversion.

ARCGIS 10.1

ARCGIS DESKTOP 10.1

  • ArcGIS 10.1 will no longer support Microsoft Visual Basic for Applications (VBA).
  • ArcGIS 10.1 will no longer support the Solaris versions of ArcReader and ArcGIS Engine.
  • ArcGIS 10.1 will be the last release supporting ArcReader for Linux. We will no longer support ArcReader on Linux after the ArcGIS 10.1 release.

ARCINFO WORKSTATION 10.1

  • There are no plans to release a new version of ArcInfo Workstation at ArcGIS 10.1. However, ArcInfo Workstation 10.0 will be able to be used in conjunction with newer versions of ArcGIS Desktop. Users will continue to be able to use their existing ArcGIS 10.0 version, but we will not release newer versions.

ARCIMS 10.1

  • ArcGIS 10.1 will be the last planned release for ArcIMS,. At ArcGIS 10.1 ArcIMS will more to the “Mature” phase in the Product Lifecycle. Users can continue to use existing versions of ArcIMS after this time; however, we will no longer provide new releases. Users should develop a plan and migrate to the ArcGIS Server and Web API technology.

ARCGIS SERVER 10.1

  • ArcGIS Server 10.1 will be the last planned release for the ArcGIS Server Web ADFs (Application Developer Framework) for both Microsoft .NET and Java. ESRI will continue supporting the Web ADFs during the 10.1 release cycle but only fixes to critical issues will be addressed. No new functionality or enhancement requests will be addressed for the Web ADFs. Web application developers are encouraged to move to a web services based pattern with the ArcGIS Web Mapping APIs for JavaScript, Flex, or Silverlight.
  • ArcGIS Server 10.1 will no longer support local connections (DCOM connections) from Web ADF applications. ArcGIS Server 10.1 will be a web services (REST and SOAP) server only. This will have an impact on:
    • The web editing functionality of default Web ADF will no longer be supported. ArcGIS 10.1 will continue evolving and enhancing its web editing capabilities on top of the new ‘Feature Service’ (new in ArcGIS 10) and the ArcGIS Web Mapping APIs.
    • Custom developed applications from business partners and users using fine grained ArcObjects will not be supported. Thanks to the recent enhancements in Server Object Extensions, developers can now migrate custom business logic written at the web application (Web ADF) level to custom ArcGIS Server services. Developers will need to migrate existing application logic to this web services based pattern. ESRI has been recommending this approach for some time already, due to its simplicity and improved performance.
    • Web ADF applications using non-pooled services will not be supported. Over the years, some customers have adopted a pattern for their ArcGIS Server applications that use non-pooled services. This pattern has been shown not to scale.
  • ArcGIS Server 10.1 will be the last planned release for the ArcGIS Server Manager Web Mapping Application (Microsoft .Net and Java). ArcGIS Server Manager includes a wizard for configuring out of the box web mapping applications based on Web ADF technology. ArcGIS Server 10.1 is the last release of the Web Mapping Application wizard in Manager. ESRI will continue supporting the ArcGIS Server Manager Application Wizard and Web Applications created with it during the 10.1 release cycle, but only fixes to critical issues will be addressed. New out of the box applications based on the ArcGIS Web Mapping APIs, as well as a new experience for configuring them, will be offered as part of the ArcGIS Server 10.1 release.
  • ArcGIS Server 10.1 will no longer support 32-bit operating systems. ArcGIS 10.1 will exclusively support 64-bit operating systems. Support for 64-bit native execution across all the tiers of ArcGIS Server has been a long awaited feature by many of our customers. 64-bit hardware is the norm in today’s market and most modern ArcGIS Server deployments do in fact run on 64-bit hardware. ArcGIS Server 10.1 will run as a native 64-bit application exclusively requiring 64-bit capable hardware.
  • ArcGIS 10.1 will no longer support the Solaris versions of ArcGIS Server (with the exception of the ArcSDE technology component). We will continue to support the ArcSDE component of ArcGIS Server on the Solaris platform beyond the ArcGIS 10.1 release.
  • ArcGIS Server 10.1 is no longer support VBScript or JScript on ArcGIS Server for Linux. VBScript and JScript will continue to be supported on ArcGIS Server for Microsoft Windows. Python scripting will be added as a replacement for these scripting languages and ArcGIS Desktop will support authoring Python scripts in areas where VBScript and JScript are presently used.
  • ArcGIS Server 10.1 will no longer support publishing non-optimized map documents (MXD files). ArcGIS 10.1 will only support publishing optimized maps (MSDs) as that is the best practice for map publishing. At ArcGIS Server 10.1, optimized map services (MSDs) will be enhanced to support many of the capabilities that are currently only available through MXD-based map services.

ARCGIS IMAGE SERVER 10.1

  • ArcGIS 10.1 will no longer support a stand-alone ArcGIS Image Server product. This product will be replaced with the ArcGIS Server Image Extension.

The official ArcGIS 10 and 10.1 Deprecation Plan is available for download as well.

E-mail Alerts from VB application

Sending an e-mail via VB.Net can be done easily with the following code. You can also modify the code to send e-mail via an ASP web page.
Add this line in your declarations area.
Imports System.Net.Mail
Next, create a subroutine by entering the following code:
Public Sub SendEmail(ByVal strTo As String, ByVal strSubject As String, ByVal strMessage As String)

On Error GoTo SEerrTrap
Dim emailMsg As New MailMessage("fromEmail@wherever.com", strTo, strSubject, strMessage)

'Settings for using G-mail. Replace the url with the url or IP address of your mail server
'and the port number with "25" for an inhouse mail server.
Dim emailclient As New SmtpClient("smtp.gmail.com", "587") 

emailclient.EnableSsl = True 'Enables SSL. You likely will not need this unless you are using a G-Mail account to send mail.
emailMsg.IsBodyHtml = True 'Enables HTML e-mail bodies
emailMsg.Priority = MailPriority.High 'Sets the priority of the e-mail and how it appears on the recipients PC.
emailMsg.CC.Add("otherEmail@whereever.com")
emailMsg.Bcc.Add("BccOtherEmail@whereever.com")
emailclient.Credentials = New System.Net.NetworkCredential("userID", "password") 'User ID and password for the SMTP mail server
emailclient.Send(emailMsg)

Exit Sub
SEerrTrap:
     MsgBox(Now & " Error " & Err.Number & " " & Err.Description & " in SendEmail")
End Sub

Calling the subroutine with the appropriate variables included will send the e-mail via your SMTP server specified in the code.