av = MSComm1.Input '将串口数据取出来
For i = 0 To ReDataLen - 1
FGetData = FGetData & Right("00" & Hex(av(i)), 2)
Next i
End If
If Len(FGetData) >= 6 Then
If Len(FGetData) > Val("&H" & Mid(FGetData, 5, 2)) * 2 + 8 Then
IReceiveData = FGetData
Exit Function
End If
End If
If GetTickCount - t1 > 2000 Then '2秒没收完就不收了
IReceiveData = ""
Exit Function
End If
Loop
End Function
Private Function QReceiveData() As String '反回Q状态
Dim FGetData As String
Dim t1 As Long
Dim av As Variant
Dim i As Integer
Dim ReDataLen As Integer
FGetData = ""
t1 = GetTickCount() '取时间,做延时用
Do '循环等待接收数据
DoEvents
If MSComm1.InBufferCount > 0 Then '串口有数据了
ReDataLen = MSComm1.InBufferCount '取数据长度
av = MSComm1.Input '将串口数据取出来
For i = 0 To ReDataLen - 1
FGetData = FGetData & Right("00" & Hex(av(i)), 2)
Next i
End If
If Len(FGetData) >= 6 Then
If Len(FGetData) > Val("&H" & Mid(FGetData, 5, 2)) * 2 + 8 Then
QReceiveData = FGetData
Exit Function
End If
End If
If GetTickCount - t1 > 2000 Then '2秒没收完就不收了
QReceiveData = ""
Exit Function
End If
Loop
End Function
Private Sub Timer2_Timer()
x1 = x1 + 1
Text10.Text = str(x1)
Text1.Text = str(p11)
Text2.Text = str(p12)
Text3.Text = str(p13)
Text4.Text = str(p14)
Text7.Text = str(p15)
If Text7.Text = 1 Then Text7.BackColor = RGB(255, 0, 255)
If Text7.Text = 0 Then Text7.BackColor = RGB(0, 255, 255)
'Text6.Text = str(p16)
Text9.Text = str(p17)
If Text9.Text = 1 Then Text9.BackColor = RGB(255, 0, 255)
If Text9.Text = 0 Then Text9.BackColor = RGB(0, 255, 255)
'Text8.Text = str(p18)
End Sub