'开始接收数据
Private Sub BeginCommand_Click()
Dim InDataBuf(0 To 27) As Byte
Dim InData As Variant '定义变量
Dim Thermo As Double
Dim InDataP As Long
Dim InDataPSum As Long
Dim Pitch As Double
Dim InDataR As Long
Dim InDataRSum As Long
Dim Roll As Double
Dim InDataY As Long
Dim InDataYSum As Long
Dim Yaw As Double
Dim InDataGX As Long
Dim InDataGXSum As Long
Dim InDataGY As Long
Dim InDataGYSum As Long
Dim InDataGZ As Long
Dim InDataGZSum As Long
Dim GyroX As Double
Dim GyroY As Double
Dim GyroZ As Double
Dim InDataAX As Long
Dim InDataAXSum As Long
Dim InDataAY As Long
Dim InDataAYSum As Long
Dim InDataAZ As Long
Dim InDataAZSum As Long
Dim AccX As Double
Dim AccY As Double
Dim AccZ As Double
Dim InDataLongg As Long
Dim InDataLat As Long
Dim longg As Double
Dim Lat As Double
Dim InDataSize As Integer
Dim SumData As Variant
Dim ThermoStr As String * 10
Dim GyroXStr As String * 10
Dim GyroYStr As String * 10
Dim GyroZStr As String * 10
Dim AccXStr As String * 10
Dim AccYStr As String * 10
Dim AccZStr As String * 10
Dim PitchStr As String * 10
Dim RollStr As String * 10
Dim YawStr As String * 10
Dim LatStr As String * 10
Dim LongStr As String * 10
Dim lineNum As Long
Dim modNum As Long
Dim DataNum As Variant
Dim LineNumStr As String * 10
Dim intFileNum As Integer
Dim tempFileName As String
Dim SumAdd As Long
Dim InDataOne As Long
'MSComm1.PortOpen = False
If ComPort(0).Value = True Then MSComm1.CommPort = 1
If ComPort(1).Value = True Then MSComm1.CommPort = 2
If ComPort(2).Value = True Then MSComm1.CommPort = 3
If ComPort(3).Value = True Then MSComm1.CommPort = 4 '设置端口
If FreComm(0).Value = True Then MSComm1.Settings = "4800,n,8,1"
If FreComm(1).Value = True Then MSComm1.Settings = "9600,n,8,1"
If FreComm(2).Value = True Then MSComm1.Settings = "14400,n,8,1"
If FreComm(3).Value = True Then MSComm1.Settings = "19200,n,8,1" '设置采样率
If FreComm(4).Value = True Then MSComm1.Settings = "115200,n,8,1"
If commSelect.MSComm1.PortOpen = True Then MsgBox "端口已打开!", vbOKOnly + vbCritical, "错误信息"
If commSelect.MSComm1.PortOpen = False Then commSelect.MSComm1.PortOpen = True
Close
Dim buf$
buf = Trim(commSelect.MSComm1.Input)
txtReceive.Text = ""
If Len(buf) = 0 Then
txtReceive.Text = "Empty Empty Empty" & vbCrLf
End If
tempFileName = "C:\temp.txt"
Open tempFileName For Output As #1
commSelect.MSComm1.InBufferCount = 0
commSelect.MSComm1.OutBufferCount = 0
commSelect.MSComm1.RThreshold = 0
commSelect.MSComm1.SThreshold = 0
commSelect.MSComm1.InputMode = comInputModeBinary
lineNum = 0
'On Error Resume Next
'' TimeDelay 10
Do While InDataSize = 0
DoEvents
'' TimeDelay 1
commSelect.MSComm1.InputLen = 1
InData = commSelect.MSComm1.Input
InDataBuf(0) = InData(0) '提示下标越界
If InDataBuf(0) = &HD Then
InData = commSelect.MSComm1.Input
InDataBuf(1) = InData(0)
If InDataBuf(1) = &HDA Then
InDataSize = 0
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(2) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(3) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(4) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(5) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(6) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(7) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(8) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(9) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(10) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(11) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(12) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(13) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(14) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(15) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(16) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(17) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(18) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(19) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(20) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(21) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(22) = InData(0)
InData = commSelect.MSComm1.Input
InDataSize = InDataSize + 1
InDataBuf(23) = InData(0)
SumData = CLng(InDataBuf(2)) + CLng(InDataBuf(3)) + CLng(InDataBuf(4)) + CLng(InDataBuf(5)) + CLng(InDataBuf(6)) + CLng(InDataBuf(7)) + CLng(InDataBuf(8)) + CLng(InDataBuf(9)) + CLng(InDataBuf(10)) + CLng(InDataBuf(11)) + CLng(InDataBuf(12)) + CLng(InDataBuf(13)) + CLng(InDataBuf(14)) + CLng(InDataBuf(15)) + CLng(InDataBuf(16)) + CLng(InDataBuf(17)) + CLng(InDataBuf(18)) + CLng(InDataBuf(19)) + CLng(InDataBuf(20)) + CLng(InDataBuf(21)) + CLng(InDataBuf(22))
If (SumData And 255) = InDataBuf(23) Then
InDataGX = CLng(InDataBuf(6)) * 16 * 16 + InDataBuf(5)
If (InDataGX > 32768) Then GyroX = (InDataGX - 65536)
If (InDataGX <= 32768) Then GyroX = InDataGX
GyroXStr = Format(GyroX, "#####")
InDataGY = CLng(InDataBuf(8)) * 16 * 16 + InDataBuf(7)
If (InDataGY > 32768) Then GyroY = (InDataGY - 65536)
If (InDataGY <= 32768) Then GyroY = InDataGY
GyroYStr = Format(GyroY, "#####")
InDataGZ = CLng(InDataBuf(10)) * 16 * 16 + InDataBuf(9)
If (InDataGZ > 32768) Then GyroZ = (InDataGZ - 65536)
If (InDataGZ <= 32768) Then GyroZ = InDataGZ
GyroZStr = Format(GyroZ, "#####")
InDataAX = CLng(InDataBuf(12)) * 16 * 16 + InDataBuf(11)
If (InDataAX > 32768) Then AccX = (InDataAX - 65536)
If (InDataAX <= 32768) Then AccX = InDataAX
AccXStr = Format(AccX, "#####")
InDataAY = CLng(InDataBuf(14)) * 16 * 16 + InDataBuf(13)
If (InDataAY > 32768) Then AccY = (InDataAY - 65536)
If (InDataAY <= 32768) Then AccY = InDataAY
AccYStr = Format(AccY, "#####")
InDataAZ = CLng(InDataBuf(16)) * 16 * 16 + InDataBuf(15)
If (InDataAZ > 32768) Then AccZ = (InDataAZ - 65536)
If (InDataAZ <= 32768) Then AccZ = InDataAZ
AccZStr = Format(AccZ, "#####")
InDataP = CLng(InDataBuf(18)) * 16 * 16 + InDataBuf(17)
If (InDataP > 32768) Then Pitch = (InDataP - 65536) * 360 / 65536
If (InDataP <= 32768) Then Pitch = InDataP * 360 / 65536
PitchStr = Format(Pitch, "###0.0000")
InDataR = CLng(InDataBuf(20)) * 16 * 16 + InDataBuf(19)
If (InDataR > 32768) Then Roll = (InDataR - 65536) * 360 / 65536
If (InDataR <= 32768) Then Roll = InDataR * 360 / 65536
RollStr = Format(Roll, "###0.0000")
InDataY = CLng(InDataBuf(22)) * 16 * 16 + InDataBuf(21)
Yaw = InDataY * 360 / 65536
YawStr = Format(Yaw, "###0.0000")
Dim A As Long
lineNum = lineNum + 1
LineNumStr = Format(lineNum, "######")
txtReceive.Text = LineNumStr + CStr(InDataBuf(5)) + " " + CStr(InDataBuf(6)) + " " + CStr(InDataBuf(7)) + " " + CStr(InDataBuf(8)) + " " + CStr(InDataBuf(9)) + " " + CStr(InDataBuf(10)) + " " + CStr(InDataBuf(11)) + " " + CStr(InDataBuf(12)) + " " + CStr(InDataBuf(13)) + " " + CStr(InDataBuf(14)) + " " + CStr(InDataBuf(15)) + " " + CStr(InDataBuf(16)) + " " + CStr(InDataBuf(17)) + " " + CStr(InDataBuf(18)) + " " + CStr(InDataBuf(19)) + " " + CStr(InDataBuf(20)) + " " + CStr(InDataBuf(21)) + " " + CStr(InDataBuf(22)) & vbCrLf + txtReceive.Text
txtChange.Text = LineNumStr + GyroneStr + GyroXStr + GyroYStr + GyroZStr + PitchStr + RollStr + YawStr & vbCrLf + txtChange.Text
''+ AccXStr + AccYStr + AccZStr & vbCrLf
'SumAdd = SumAdd + A
InDataPSum = InDataPSum + InDataP
InDataRSum = InDataRSum + InDataR
InDataYSum = InDataYSum + InDataY
InDataGXSum = InDataGXSum + InDataGX
InDataGYSum = InDataGYSum + InDataGY
InDataGZSum = InDataGZSum + InDataGZ
InDataAXSum = InDataAXSum + InDataAX
InDataAYSum = InDataAYSum + InDataAY
InDataAZSum = InDataAZSum + InDataAZ
End If
End If
End If
'If (lineNum Mod 300 = 0) Then
txtReceive.Text = ""
' End If
InDataSize = 0 '数据个数计数器清零
'modNum = lineNum Mod 6500
' testPic (0)
Loop