mscomm1.settings = "9600,n,8,1"
mscomm1.rthreshold = 1
mscomm1.inputmode = cominputmodebinary
mscomm1.inputlen = 0
if mscomm1.portopen = false then mscomm1.portopen = true
private sub mscomm1_oncomm()
dim receive_data() as byte
dim inbuffer as variant
if flag1 = true then '输入的是数据个数
select case mscomm1.commevent
case comevreceive
inbuffer = " "
receive_data() = " "
inbuffer = mscomm1.input
receive_data() = inbuffer
text1.text = text1.text + str(receive_data(0))
end select
end if
mscomm1.inbuffercount = 0
end sub
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True '打开通信口
End If
MSComm1.InputMode = comInputModeBinary '设置接收数据模式为二进制形式
MSComm1.SThreshold = 1 '设置Output 一次从发送缓冲读取字节数为1
MSComm1.RThreshold = 1 '设置接收一个字节产生OnComm事件
MSComm1.RTSEnable = False
With MSComm1
Select Case .CommEvent '判断MSComm1通讯事件
Case comEvReceive '收到Rthreshold个字节产生的接收事件
If Len(JS.Text) > 100 Then
JS.Text = ""
End If
1111:
m_zichuan = MSComm1.Input '读取一个接收字节
For i = 1 To LenB(m_zichuan)
JS.Text = JS.Text + Hex(AscB(MidB(m_zichuan, i, 1))) + ","
Next i
If MSComm1.InBufferCount > 0 Then GoTo 1111
m_zichuan = ""
End Select
End With
End Sub
你在读input前加上这句看看!