vb读取几种导航仪表的方法集合
来源:岁月联盟
时间:2012-04-02
仪表主要有日本GP30,GP31,GP91,SAMYANG,另外还有国产的仪表,以供大家参考,这是本人为航务公司开发读取导航仪表的数据,数据主要有航速、经度、纬度和其它数据,但是其公司使用的导航仪有4种,每一种都写一个读数方法,所以是很郁闷的,好在最后都写出来了。
[vb]
Dim tmpStr As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim RetValue
On Error Resume Next
Dim TmpA As String
Dim TmpB As String
Dim TmpC As String
Dim TmpD As String
Dim TmpE As String
RetValue = MSCGps.Input
j = LenB(RetValue)
For i = 0 To j - 1
If RetValue(i) = &H24 And RetValue(i + 1) = &HA0 And j > 31 Then
For k = 0 To 3
TmpA = TmpA & Replace(Format(Hex(RetValue(i + 6 + k)), "@@"), " ", "0")
Next
LblInfo(0).Caption = Val(TmpA) / 1000 '经度
For k = 0 To 3
TmpB = TmpB & Replace(Format(Hex(RetValue(i + 10 + k)), "@@"), " ", "0")
Next
LblInfo(1).Caption = Val(TmpB) / 1000 '纬度
For k = 0 To 1
TmpC = TmpC & Replace(Format(Hex(RetValue(i + 14 + k)), "@@"), " ", "0")
Next
LblInfo(2).Caption = Val(TmpC) '速度
For k = 0 To 1
TmpD = TmpD & Replace(Format(Hex(RetValue(i + 16 + k)), "@@"), " ", "0")
Next
Label2(7).Caption = TmpD '方位
TmpE = TmpE & Replace(Format(Hex(RetValue(i + 18)), "@@"), " ", "0")
Label2(6).Caption = TmpE '状态
End If
Next
' tmpStr = MSCGps.Input
' StrBuf = tmpStr
'$GPRMC,055214,A,3158.0956,N,12024.4596,E,0.0,326,200511,5,W*68/CR/LF
' If UCase(Mode) = "GP31" Then
' i = InStr(1, tmpStr, "$GPRMC", vbTextCompare)
' If i Then
' LblInfo(0).Caption = Val(Mid(tmpStr, i + 16, 2)) & " " & Val(Mid(tmpStr, i + 18, 7)) '经度
' LblInfo(1).Caption = Mid(tmpStr, i + 28, 3) & " " & Mid(tmpStr, i + 31, 7) '纬度
' LblInfo(2).Caption = Val(Mid(tmpStr, i + 41, 4)) '速度
' LblInfo(3).Caption = Mid(tmpStr, i + 7, 2) & ":" & Mid(tmpStr, i + 9, 2) & ":" & Mid(tmpStr, i + 11, 2) '时间
' End If
'
' '$GPVTG,,T,302,M,0.0,N,0.0,K/CR/LF
' j = InStr(1, tmpStr, "$GPVTG", vbTextCompare)
' If j Then
' Label2(7).Caption = Val(Mid(tmpStr, j + 10, 5)) '方位
' Label2(6).Caption = Val(Mid(tmpStr, j + 24, 4)) '状态
' End If
'
' '$GPZDA,055217,20,05,2011,-8,0/CR/LF
' k = InStr(1, tmpStr, "$GPZDA", vbTextCompare)
' If k Then
' Label2(4).Caption = Mid(tmpStr, k + 20, 4) & "-" & Mid(tmpStr, k + 17, 2) & "-" & Mid(tmpStr, k + 14, 2) '日期
' End If
' End If
'
' If UCase(Mode) = "SAMYANG" Then
' i = InStr(1, tmpStr, "$GPRMC", vbTextCompare)
' If i Then
' LblInfo(0).Caption = Val(Mid(tmpStr, i + 19, 9)) '经度
' LblInfo(1).Caption = Mid(tmpStr, i + 31, 10) '纬度
' LblInfo(2).Caption = Val(Mid(tmpStr, i + 44, 4)) '速度
' LblInfo(3).Caption = Mid(tmpStr, i + 7, 2) & ":" & Mid(tmpStr, i + 9, 2) & ":" & Mid(tmpStr, i + 11, 2)
' End If
'
' j = InStr(1, tmpStr, "$GPVTG", vbTextCompare)
' If j Then
' Label2(7).Caption = Mid(tmpStr, j + 17, 4) ' Val(Mid(tmpStr, j + 12, 4))
' Label2(6).Caption = Mid(tmpStr, j + 24, 4)
' End If
'
' k = InStr(1, tmpStr, "$GPZDA", vbTextCompare)
' If k Then
' Label2(4).Caption = Mid(tmpStr, k + 20, 4) & "-" & Mid(tmpStr, k + 17, 2) & "-" & Mid(tmpStr, k + 14, 2)
' End If
' End If
'
' '$GPVTG,,T,153.6,M,11.9,N,22.0,K,A*05
' '$GPVTG,,T,147.8,M,11.8,N,21.9,K,A*05
' '$GPVTG,,T,124.9,M,11.4,N,21.1,K,A*05
' '$GPVTG,,T,168.7,M,8.0,N,14.8,K,A*30
' '$GPVTG,,T,166.7,M,9.4,N,17.4,K,A*34
' '$GPVTG,,T,88.0,M,9.4,N,17.4,K,A*02
' '$GPVTG,,T,251.7,M,0.1,N,0.2,K,A*0F
' '$GPVTG,,T,173.8,M,1.3,N,2.4,K,A*04
'
' If UCase(Mode) = "GP90" Then
' Shape1.FillColor = vbGreen
'
'
' i = InStr(1, tmpStr, "$GPGLL", vbTextCompare)
' If i Then
' LblInfo(0).Caption = Val(Mid(tmpStr, i + 19, 9))
' LblInfo(1).Caption = Mid(tmpStr, i + 7, 8)
' LblInfo(3).Caption = Mid(tmpStr, i + 32, 6)
'
' End If
'
' j = InStr(1, tmpStr, "$GPVTG", vbTextCompare)
' If j Then
' Dim TmpV As String
' TmpV = Mid(tmpStr, j + 6, 28)
'
' ' Debug.Print TmpV
' Dim m As Integer
' Dim n As Integer
' ' Dim k As Integer
'
' m = InStr(1, TmpV, "N")
' n = InStr(1, TmpV, "K")
'
' k = n - m - 3
'
' ' Debug.Print Mid(TmpV, m + 2, k)
' LblInfo(2).Caption = Val(Mid(TmpV, m + 2, k)) '速度
' 'LblInfo(2).Caption = Val(Mid(tmpStr, j + 24, 4)) '速度
'
' m = InStr(1, TmpV, "T")
' n = InStr(1, TmpV, "M")
' k = n - m - 3
' Label2(7).Caption = Val(Mid(TmpV, m + 2, k)) '方位
'
' ' Label2(7).Caption = Val(Mid(tmpStr, j + 10, 5))
'
' ' SaveInfo tmpStr
' End If
'
' k = InStr(1, tmpStr, "$GPZDA", vbTextCompare)
' If k Then
' Label2(4).Caption = Mid(tmpStr, k + 23, 4) & "-" & Mid(tmpStr, k + 20, 2) & "-" & Mid(tmpStr, k + 17, 2)
' End If
' l = InStr(1, tmpStr, "$GPRMB", vbTextCompare)
' Label2(6).Caption = Val(Mid(tmpStr, l + 56, 3))
' End If