VB通过MSC控件接收数据全为0

使用VB的MSC控件,实现与单片机之间数据的接收发送,为什么接收回来的数据全是0,接收的是18个数,用二进制接收,转换成16进制后,显示在文本框text1,请帮忙看一下程序哪里有问题。
还有就是读数据的时候老显示读comm设备有误,我改一下RThre的值,它又能正常显示了
Private Sub Command3_click()
Dim ReceiveArr() As Byte
Dim receivedata As String
Dim counter As Integer
Dim i As Integer
Dim s As String
Dim a(18) As Variant
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0
receivedata = ""
If (MSComm1.InBufferCount > 0) Then
counter = MSComm1.InBufferCount
ReceiveArr = MSComm1.Input
For i = 0 To (counter - 1) Step 1
ReDim ReceiveArr(i)
If ReceiveArr(i) < 16 Then
receivedata = receivedata & "0" + Hex(ReceiveArr(i)) & Space(1)
Else
receivedata = receivedata & Hex(ReceiveArr(i)) & Space(1)
End If
s = receivedata
text1.Text=s

2个回答

你好,我这里是写错了,程序里边是MSComm1.InputMode = comInputModeBinary但是接收的数据也全是0,

程序和说明不一致!你明明用的是comInputModeText文本模式接收。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐