本设计课题将VB语言与测量程序设计进行了有机结合。本论文的主要目的是使我们在学习VB语言编程的同时,能够结合测绘专业的例子,一方面可以巩固测绘专业知识,另一方面可以掌握运用VB语言编写程序解决测绘专业问题的能力。
代码未考虑校验和:Option Explicit
Dim strdata As String
Dim bytInput() As Byte
Dim sj(1) As Double
Dim sjData(1) As String
Dim xswz As Integer
Dim xswz1 As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub MsComm1_OnComm()
Dim intInputLen As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
'接收代码
While MSComm1.InBufferCount
intInputLen = MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = MSComm1.Input
jieshou
'数据处理
If Mid(strdata, 1, 2) = "AA" And Len(strdata) = 32 Then
Dim j As Integer
Dim binsj As Integer
'For j = 1 To Len(strdata) - 2 Step 2
'binsj = binsj + Val("&H" &Mid(strdata, j, 2))
'Next
'Print Hex(binsj Mod 256)
Text1 = strdata
xswz = Val("&H" &Mid(strdata, 15, 2))
xswz1 = Val("&H" &Mid(strdata, 29, 2))
sj(0) = Val(Mid(strdata, 5, 10)) / (10 ^ xswz)
sj(1) = Val(Mid(strdata, 19, 10)) / (10 ^ xswz1)
sjData(0) = Format(sj(0), "0.0000000")
sjData(1) = Format(sj(1), "0.0000000")
If Mid(strdata, 4, 1) = "0" Then
Text2 = sjData(0)
Else
Text2 = "-" &sjData(0)
End If
If Mid(strdata, 18, 1) = "0" Then
Text3 = sjData(1)
Else
Text3 = "-" &sjData(1)
End If
Timer1.Enabled = False
strdata = ""
ElseIf Mid(strdata, 1, 2) <>"AA" Then
strdata = ""
End If
Wend
End Select
End Sub
Public Function jieshou() '接收数据处理为16进制
Dim i As Integer
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strdata = strdata &"0" &Hex(bytInput(i))
Else
strdata = strdata &Hex(bytInput(i))
End If
Next
End Function
Private Sub Form_Load()
MSComm1.Settings = "2400,n,8,1"
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.SThreshold = 0
MSComm1.PortOpen = True
Timer1 = 200
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim send(0) As Byte
send(0) = &H55
MSComm1.Output = send
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)