vb串口通讯接收数据问题
代码如下:Option Explicit
'********打开关闭按钮
Private Sub CmdOpen_Click()
If CmdOpen.Caption = "Open" Then
CmdOpen.Caption = "Close"
MSComm.PortOpen = True
Exit Sub
End If
If CmdOpen.Caption = "Close" Then
CmdOpen.Caption = "Open"
MSComm.PortOpen = False
End If
End Sub
'********初始化
Private Sub Form_Load()
Dim CardNameLen As Long
= 3 '使用com3口
MSComm.InputMode = comInputModeText '文本方式读入
MSComm.RThreshold = 1 '每到一个字节就触发一个comEvReceive事件
MSComm.Settings = "9600,n,8,1" '设置并返回波特率、奇偶校验、数据位、停止位参数
CardNameLen = Len("S012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789DA") '设置一次读入整个卡号长度
MSComm.InputLen = CardNameLen
End Sub
Private Sub MSComm_OnComm()
Select Case
Case comEvReceive
Call ReceiveDataFromCom
End Select
End Sub
Sub ReceiveDataFromCom()
Dim ComTemp As Variant
Dim ReadData() As Byte
Dim InbufferCount As Long
Dim i As Integer
Dim Str As String
Str = ""
InbufferCount = MSComm.InbufferCount '察看接收缓冲区的字节数量
If InbufferCount < MSComm.InputLen Then '若接收缓冲区的字节数量小于卡号的长度,退出,什么都不做
Exit Sub
End If
If InbufferCount >= MSComm.InputLen Then '若接收缓冲区的字节数量大于等于卡号的长度,读取
ComTemp = MSComm.Input '先读入一个变体中
ReadData() = ComTemp '然后将变体赋给一个字节型数组
For i = LBound(ReadData) To UBound(ReadData)
Str = Str & ChrB(ReadData(i))
Next i
MsgBox "数据:" & vbCrLf & Str
End If
End Sub
问题貌似出在程序无法跳至mscomm1_oncomm内
跪求大神