PDA

Click to See Complete Forum and Search --> : MSComm and Hyperterminal


Dinamita
Nov 13th, 1999, 01:17 AM
I am trying to use the MSComm function on VB6.0 to receive some GPS information into a hyperterminal I created. The data that I am receiving looks as follows:
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPZDA,190607.00,,,,00,00*6F
$GPGSV,2,1,08,01,49,328,,03,16,165,,06,09,051,,14,48,277,*71
$GPGSV,2,2,08,16,19,314,,22,88,154,,25,48,036,,29,15,124,*7E
$GPRMC,190608.00,V,2834.4610,N,08115.4043,W,,,,,*30
$GPGGA,190608.00,2834.4610,N,08115.4043,W,0,00,,-95.8,M,,M,,*50
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPZDA,190608.00,,,,00,00*60
$GPGSV,2,1,08,01,49,328,,03,16,165,,06,09,051,,14,48,277,*71
$GPGSV,2,2,08,16,19,314,,22,88,154,,25,48,036,,29,15,124,*7E

The problem is that I need to strip some of this data away, and I do not know how to. I believe that it has to do with the MSComm.input. Can someone give me some input on this matter? I appreciate it.

Wayne Muzzy
Nov 13th, 1999, 07:21 AM
What do you need to parse out?

Dinamita
Nov 13th, 1999, 10:15 AM
Out of these commands, I need to use the command string that begins with $GPRMC. If you look at this string closely, it tells a latitude, a longitude, and a time. In this case the lat is 28.34.., the long. is 81.15.. and the time is 19:06. This data is the one that I need to parse out from that whole set of strings. Thank you, and your help will be greatly appreciated...

Wayne Muzzy
Nov 15th, 1999, 11:52 AM
Try this in a form. 1 Textbox, 6 Labels 1 Cmd Button:
****start code****
Option Explicit

Private Sub cmdParse_Click()
'start parsing
sParse txtText.Text
End Sub

Private Sub Form_Load()
'laods text into textbox
txtText = "$GPRMC,190608.00,V,2834.4610,N,08115.4043,W,,,,,*30"
End Sub

Private Sub sParse(sText As String)
Dim iCounter As Integer
Dim iCounter2 As Integer
Dim iPos As Integer
Dim sTime As String
Dim sLat As String
Dim sLag As String
Dim iLen As Integer

'what you want to parse on
Const PARSECHAR = ","

'get out if no text
If Len(sText) = 0 Then Exit Sub

'start counters
iCounter = 1
iCounter2 = 1

'get the sections
iPos = InStr(iCounter, sText, PARSECHAR)

While iPos <> 0

Select Case iCounter2
Case "2" 'section 2 is the time
sTime = Mid$(sText, iCounter, iPos - iCounter)
sTime = Left(sTime, 6)
sTime = Format(sTime, "##:##:##")
lblTime.Caption = sTime
Case "4" 'section 4 is Lat
sLat = Mid$(sText, iCounter, iPos - iCounter)
iLen = Len(sLat) - 5
sLat = Left(sLat, iLen)
sLat = FixNum(sLat) 'fix number to read ##.## or ###.##
lblLat.Caption = sLat
Case "6" 'section 6 is Lag
sLag = Mid$(sText, iCounter, iPos - iCounter)
sLag = Left(sLag, 4)
sLag = FixNum(sLag) 'fix number to read ##.## or ###.##
lblLag.Caption = sLag
End Select
iCounter = iPos + 1 'inc counter
iCounter2 = iCounter2 + 1 'inc counter
iPos = InStr(iCounter, sText, PARSECHAR) 'next section
Wend

End Sub
Private Function FixNum(sNum As String) As String
Dim sOne As String
Dim sTwo As String
Dim iLen As Integer

'get number length minus 2 for the .##
iLen = Len(sNum) - 2

'get the first half of the number
sOne = Left(sNum, 2)
'get the second half of the number
sTwo = Right(sNum, iLen)
'put them together
FixNum = sOne & "." & sTwo

End Function
****end code****