Private Sub Command3_Click()
MSComm1.InBufferCount = 0 '...清空输入寄存器
Text1.Text = ""
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 6 '...使用Com1口根据自己的串口来设置
MSComm1.Settings = "9600,n,8,1" '...设置通讯参数
MSComm1.PortOpen = True '...打开串口
MSComm1.RThreshold = 1
MSComm1.InBufferCount = 0 '...清空输入寄存器
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive '...有接受事件发生
Dim indata As Variant
Dim bte(0) As Byte
indata = MSComm1.Input
bte(0) = AscB(indata)'数据换换
Text1.Text = Text1.Text & bte(0) & " "
'MSComm1.InBufferCount = 0 '...清空输入寄存器
End Select
End Sub
按照这个写应该没问题的!
vb那头要把接收到的数据进行转换的!
FORM1 添加一个TEXT控件,一个MSCOMM控件!
Private Sub Command3_Click()
MSComm1.InBufferCount = 0 '...清空输入寄存器
Text1.Text = ""
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 6 '...使用Com1口根据自己的串口来设置
MSComm1.Settings = "9600,n,8,1" '...设置通讯参数
MSComm1.PortOpen = True '...打开串口
MSComm1.RThreshold = 1
MSComm1.InBufferCount = 0 '...清空输入寄存器
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive '...有接受事件发生
Dim indata As Variant
Dim bte(0) As Byte
indata = MSComm1.Input
bte(0) = AscB(indata)'数据换换
Text1.Text = Text1.Text & bte(0) & " "
'MSComm1.InBufferCount = 0 '...清空输入寄存器
End Select
End Sub
按照这个写应该没问题的!
一周热门 更多>