主题:VB串口通讯老卡死,如何解决?
VB串口通讯当串口数据意外中断时,电脑老卡死,有什么好的解决办法吗,谢谢!
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent '判断MSComm1 通信事件
Case comEvReceive '收到Rhtreshold 个字节后产生接收事件
Case comEvReceive '收到Rhtreshold 个字节后产生接收事件
'///////////////中断程序开始///////////////////////////////////////////////////////////////////////////////////
Static sz(900) As String
Static a As Integer
Static b As Integer
Static i As Integer
Static Temp As String
Static Temp1 As Integer
Static add As Double
Static pi_data As Integer
Static a As Integer
Static b As Integer
Static i As Integer
Static Temp As String
Static Temp1 As Integer
Static add As Double
Static pi_data As Integer
pi_data = 140
If MSComm1.CommEvent = comEvReceive Then Temp = MSComm1.Input
Temp1 = Asc(Temp)
If Temp = "$" Then
a = 0: MSComm1.InBufferCount = 0
a = 0: MSComm1.InBufferCount = 0
Text4.Text = "$"
Else
a = a + 1
Text4.Text = Text4.Text + Temp
sz(a) = Temp
Else
a = a + 1
Text4.Text = Text4.Text + Temp
sz(a) = Temp
End If
If Temp1 <> 13 And Temp1 <> 32 And Temp1 <> 36 Then
If Temp1 > 57 Or Temp1 < 48 Then a = 0
End If
If Temp1 > 57 Or Temp1 < 48 Then a = 0
End If
If a >= pi_data Then a = 0: Text3.Text = "": Text4.Text = ""
If a >= (pi_data - 1) And Temp = vbCr Then
Text3.Text = Text4.Text
If a >= (pi_data - 1) And Temp = vbCr Then
Text3.Text = Text4.Text
b = 0
For i = 1 To (pi_data - 8)
b = b Xor Val(sz(i))
For i = 1 To (pi_data - 8)
b = b Xor Val(sz(i))
If Val(Mid(Text3.Text, (pi_data - 7), 5)) = b Then
Text5.Text = Mid(Text3.Text, 2, 6)
End If
Next i
End If
End If
'///////////////中断程序结束///////////////////////////////////////////////////////////////////////////////////
End Select
End Sub
End Sub