vb 编写的串口软件 接收的数据不完整 中间会丢失几个数据 5
PrivateSubMSComm1_OnComm()DimintInputLenAsIntegerDimnAsIntegerDimteststringAsStringSe...
Private Sub MSComm1_OnComm()
Dim intInputLen As Integer
Dim n As Integer
Dim teststring As String
Select Case MSComm1.CommEvent
Case comEvReceive
If Option1.Value = True Then
MSComm1.InputMode = 1 '0:文本方式,1:二进制方式
Else
MSComm1.InputMode = 0 '0:文本方式,1:二进制方式
End If
intInputLen = MSComm1.InBufferCount
bytInput = MSComm1.Input
If Option1.Value = True Then
For n = 0 To intInputLen - 1
ReceiveData(rx) = bytInput(n)
rx = rx + 1
Text1.Text = Trim(Text1.Text) & " " & IIf(Len(Hex$(bytInput(n))) > 1, Hex$(bytInput(n)), "0" & Hex$(bytInput(n)))
Next n
Else
teststring = bytInput
Text1.Text = Text1.Text + teststring
End If
Timer_JCUart_Dtae.Enabled = True
End Select
End Sub
'端口初始化子程序'
Private Sub initial_com(com_num As Integer)
MSComm1.CommPort = com_num
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.SThreshold = 1
MSComm1.RThreshold = 1
MSComm1.Settings = com_setting
MSComm1.PortOpen = True
End Sub 展开
Dim intInputLen As Integer
Dim n As Integer
Dim teststring As String
Select Case MSComm1.CommEvent
Case comEvReceive
If Option1.Value = True Then
MSComm1.InputMode = 1 '0:文本方式,1:二进制方式
Else
MSComm1.InputMode = 0 '0:文本方式,1:二进制方式
End If
intInputLen = MSComm1.InBufferCount
bytInput = MSComm1.Input
If Option1.Value = True Then
For n = 0 To intInputLen - 1
ReceiveData(rx) = bytInput(n)
rx = rx + 1
Text1.Text = Trim(Text1.Text) & " " & IIf(Len(Hex$(bytInput(n))) > 1, Hex$(bytInput(n)), "0" & Hex$(bytInput(n)))
Next n
Else
teststring = bytInput
Text1.Text = Text1.Text + teststring
End If
Timer_JCUart_Dtae.Enabled = True
End Select
End Sub
'端口初始化子程序'
Private Sub initial_com(com_num As Integer)
MSComm1.CommPort = com_num
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
MSComm1.InputMode = 1
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.SThreshold = 1
MSComm1.RThreshold = 1
MSComm1.Settings = com_setting
MSComm1.PortOpen = True
End Sub 展开
4个回答
展开全部
需要给你完成吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先确认硬件有没有问题,数据线一定要质量好的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-01-06
展开全部
应该是你 程序问题
就是接受数据的处理
就是接受数据的处理
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询