使用定长接收10个字节内容,将RThreshold = 10,接收别人上位机程序串口发送过来的10个数据始终不能实现定长接收,每次只接收一个或两个字节内容,使用串口调试工具发送同样内容可以实现定每次只长接收10数据.求教它出现这个问题的可能原因.
接收别人上位机发送的内容:串口调试接收内容:串口设置: With MSComm1
.Settings = "19200,N,8,1" '基本参数
.InputMode = comInputModeBinary '按2进制接收方式
.RThreshold = 10 '接收字节处理数
.SThreshold = 1 '以字节发送
.InputLen = 0
.InBufferCount = 0
.CommPort = 4 '打开4口
.PortOpen = True
End With串口接收:
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim strinput() As Byte
strinput = MSComm1.Input '得到当前数据
For i = 0 To UBound(strinput)
If strinput(i) < 10 Then
temp = temp & " " & "0" & Hex(strinput(i)) '每个字节两位数格式
Else
temp = temp & " " & Hex(strinput(i))
End If
Next
Label2.Caption = CStr(temp) '显示接受内容
Print temp '打印内容
End Sub
接收别人上位机发送的内容:串口调试接收内容:串口设置: With MSComm1
.Settings = "19200,N,8,1" '基本参数
.InputMode = comInputModeBinary '按2进制接收方式
.RThreshold = 10 '接收字节处理数
.SThreshold = 1 '以字节发送
.InputLen = 0
.InBufferCount = 0
.CommPort = 4 '打开4口
.PortOpen = True
End With串口接收:
Private Sub MSComm1_OnComm()
Dim i As Integer
Dim strinput() As Byte
strinput = MSComm1.Input '得到当前数据
For i = 0 To UBound(strinput)
If strinput(i) < 10 Then
temp = temp & " " & "0" & Hex(strinput(i)) '每个字节两位数格式
Else
temp = temp & " " & Hex(strinput(i))
End If
Next
Label2.Caption = CStr(temp) '显示接受内容
Print temp '打印内容
End Sub
解决方案 »
- VB+Access SQL问题
- 去除text1中的带有某字符@的特定一行 VB
- 新开的VB创意QQ 1209520226 VB方面有需要高薪就业的,请加
- VB窗体的图标能不能动态更改
- 图像处理问题:请问哪位老师能贴个黑白图象转换成伪彩的代码?
- 100分求购MSDN98的下载地址
- 请教:这样的一个函数怎么做成一个dll?做成DLL之后,在一个新建成的工程中怎么调用?
- 如何在vb中实现程序运行一小时后屏保3分钟?谢谢!
- 怎么样让透明窗体可以移动?
- 如何中断我正在向A:中复制文件?
- 为什么数据库查询语句,老是返回一条语句?RecordCount获取条数,同样的SQL我在Access中查询不止一条!求大神帮忙看看
- VB 执行邮件附件
Private Sub MSComm1_OnComm()
Dim i As Integer, temp As String
Dim strinput() As Variant
If MSComm1.CommEvent = comEvReceive Then strinput = MSComm1.Input '得到当前数据
For i = 0 To UBound(strinput)
If strinput(i) < 16 Then
temp = temp & " " & "0" & Hex(strinput(i)) '每个字节两位数格式
Else
temp = temp & " " & Hex(strinput(i))
End If
Next
Label2.Caption = temp '显示接受内容End If
End Sub