VB菜鸟求助串口问题
本帖最后由 bcrun 于 2013-03-31 09:36:53 编辑 求教:我用单片机模拟一个字符串数据发送到串口,由VB上位机接受,这里是我的上位机串口设置:
MSComm2.Settings = "2400,n,8,1"
MSComm2.CommPort = 3
MSComm2.InputMode = comInputModeBinary '采用二进制传输
MSComm2.InBufferCount = 0 '清空接受缓冲区
MSComm2.OutBufferCount = 0 '清空传输缓冲区
MSComm2.RThreshold = 0 '产生MSComm事件
MSComm2.InputLen = 0
MSComm2.InBufferSize = 1024
MSComm2.PortOpen = True
Private Sub Timer4_Timer()
Dim strTemp1 As String
Timer4.Enabled = False '关闭定时器
If MSComm2.InBufferCount > 0 Then 'InBufferCount=0为清除当前已收到的数据
ReceivedLen = MSComm2.InBufferCount 'InBufferCount接收缓冲区
inx = MSComm2.Input
For i = 0 To UBound(inx)
strTemp1 = strTemp1 & Chr$(inx(i))
Next i
End If
Timer4.Enabled = True '打开定时器
Select Case strTemp1
Case "3EF5C9B"
If numone.Caption = "" Then '判断汽车驶入记录还是驶出收费
Frame21.Caption = "ID:" & strTemp1
Dim T1 As Date
T1 = Now
numone.Caption = Format(T1, "yyyy-mm-dd HH:MM:SS")
onetime = numone.Caption '记录驶入时间
cl = cl + 1 'cl为当前车辆数
Form2.label0.Caption = cl
End Select
MSComm2.InBufferCount = 0 '清空接受缓冲区
End Sub