Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've used a program I got to read the GPGGA string that gives me the geographical coordinates, the Dolphin PDA works well but I use the motorola MC65 PDA me an exception (OutOfMemoryException).
I have seen the configuration of the PDA and see everything in order.
Below I show the code, the line
VB
Dim datos As String = SerialPort1.ReadExisting()
is where the exception shows me thank you very much.

VB
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel

Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.IO.Ports
Imports System.IO
Public Class Form1
    Public Latitud As String
    Public Longitud As String
    Public Altitud As String
    Public Sub New()
        ' Esto es necesario
        InitializeComponent()
        ' Aqui intentamos abri el puerto
        Try
            SerialPort1.PortName = "COM7"
            SerialPort1.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Timer1.Enabled = False
            Button3.Text = "GPS"
            Return
        End Try
    End Sub
    Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If SerialPort1.IsOpen Then
            'En esta variable, insertamos todo lo leido del Puerto.
            Dim datos As String = SerialPort1.ReadExisting()
            'Aqui creamos las diferentes lineas, basandonos en el simbolo del dolar
            Dim strArr() As String = datos.Split("$")
            Dim i As Integer = 0
            'TextBox1.Text = strArr.Length
            If strArr.Length > 1 Then
                Try
                    For i = 0 To strArr.Length
                        'Ahora obtenemos los datos, separados por las comas.
                        Dim strTemp As String = strArr(i)
                        Dim lineArr() As String = strTemp.Split(",")


                        'Si la linea es GPGGA, cojemos los bloques de cadena 2 y 4 (latidud y longitud) y pasamos los datos obtenidos a coordenadas UTM.
                        If (lineArr(0) = "GPGGA") Then
                            Try
                                Dim dLat As Decimal
                                Dim dLon As Decimal
                                Dim dAlt As Decimal
                                Dim pla As String
                                Dim plo As String
                                Dim pAl As String



                                pla = lineArr(3)
                                plo = lineArr(5)
                                pAl = lineArr(10)


                                dLat = Convert.ToDecimal(lineArr(2))
                                dLat = dLat / 100
                                Dim lat() As String = dLat.ToString().Split(".")
                                Latitud = lat(0).ToString() + "." + ((Convert.ToDouble(lat(1)) / 0.6)).ToString("#####")
                                TextBox2.Text = pla + " " + Latitud

                                dLon = Convert.ToDecimal(lineArr(4))
                                dLon = dLon / 100
                                Dim lon() As String = dLon.ToString().Split(".")
                                Longitud = lon(0).ToString() + ".0" + ((Convert.ToDouble(lon(1)) / 0.6)).ToString("#####")
                                TextBox3.Text = plo + " " + Longitud

                                dAlt = Convert.ToDecimal(lineArr(9))
                                Dim alt() As String = dAlt.ToString().Split(".")
                                Altitud = alt(0).ToString() + "." + ((Convert.ToDouble(alt(1)) / 60)).ToString("#####")
                                TextBox4.Text = Altitud + " " + pAl

                            Catch
                                ' Si no podemos leer el GPS
                                TextBox2.Text = "Leyendo GPS"
                                TextBox3.Text = "Leyendo GPS"
                                TextBox4.Text = "Leyendo GPS"
                            End Try
                        End If
                    Next
                Catch
                    'No hacemos nada
                End Try
            End If
        Else
            TextBox2.Text = "Puerto COM Cerrado"
            TextBox3.Text = "Puerto COM Cerrado"
            TextBox4.Text = "Puerto COM Cerrado"
        End If

    End Sub

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Comprobamos el estado del timer y lo invertimos.
        If Timer1.Enabled = True Then
            Timer1.Enabled = False
        Else
            Timer1.Enabled = True
        End If
        If Button3.Text = "GPS" Then
            Button3.Text = "Parar"
        Else
            Button3.Text = "GPS"
        End If
    End Sub

    
End Class
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900