VB编程mscomm控件问题?高手请进
用VB编程用MSCOMM控件获取串口数据,比如我要在接收数据时,遇到#字符开始接收数据,遇到!字符就停止接收,就显示TEXT中,请问怎么mscomm控件的OnComm事件...
用VB编程用MSCOMM控件获取串口数据,比如我要在接收数据时,遇到#字符开始接收数据,遇到!字符就停止接收,就显示TEXT中,请问怎么mscomm控件的OnComm事件中怎么写代码?
MSComm1.CommPort = 1
MSComm1.Settings = "19200,n,8,1"
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeText
请问一下 mscomm控件的MSComm1.RThreshold属性设置为1? 展开
MSComm1.CommPort = 1
MSComm1.Settings = "19200,n,8,1"
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeText
请问一下 mscomm控件的MSComm1.RThreshold属性设置为1? 展开
2个回答
展开全部
Option Explicit
Dim strData As String
Private Sub Form_Load()
MSComm1.CommPort = 1 'COM端口
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeText
MSComm1.InBufferCount = 0 '清空接受缓冲区
MSComm1.OutBufferCount = 0 '清空传输缓冲区
MSComm1.RThreshold = 1 '产生MSComm事件
MSComm1.InBufferSize = 1024
MSComm1.PortOpen = True
Text1 = ""
End Sub
Private Sub MSComm1_OnComm() '接收数据
Dim BytReceived() As Byte
Dim strBuff As String
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
strData = strData & MSComm1.Input
'数据处理代码
If Left(strData, 1) = "#" And Right(strData, 1) = "!" Then
Text1 = strData
Else
strData = ""
End If
End Select
End Sub
Dim strData As String
Private Sub Form_Load()
MSComm1.CommPort = 1 'COM端口
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeText
MSComm1.InBufferCount = 0 '清空接受缓冲区
MSComm1.OutBufferCount = 0 '清空传输缓冲区
MSComm1.RThreshold = 1 '产生MSComm事件
MSComm1.InBufferSize = 1024
MSComm1.PortOpen = True
Text1 = ""
End Sub
Private Sub MSComm1_OnComm() '接收数据
Dim BytReceived() As Byte
Dim strBuff As String
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
strData = strData & MSComm1.Input
'数据处理代码
If Left(strData, 1) = "#" And Right(strData, 1) = "!" Then
Text1 = strData
Else
strData = ""
End If
End Select
End Sub
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
展开全部
首先要知道你串口设备返回的是asc码,还是16进制数
MSComm1.InputMode = comInputModeText '返回的asc码
do while mscomm1.InBufferCount>1
if instr(mscomm1.input,"#")<>0 then
me.text1.text=me.text1.text & mscomm1.input
doevents
end if
if instr(mscomm1.input,"!")<>0 then exit do
loop
MSComm1.InputMode = comInputModeText '返回的asc码
do while mscomm1.InBufferCount>1
if instr(mscomm1.input,"#")<>0 then
me.text1.text=me.text1.text & mscomm1.input
doevents
end if
if instr(mscomm1.input,"!")<>0 then exit do
loop
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询