vb串口程序,发送十六进制数,单片机没有反应,求大佬解答,Private Sub Command1_Click()
Dim send(0 To 3) As Byte
send(0) = &HC0
send(1) = &HC0
send(2) = &H8
send(3) = &H41
MSComm1.Output = send
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
MSComm1.CommPort = 3 ‘??????
MSComm1.Settings = “9600,n,8,1”
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
MSComm1.SThreshold = 2
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub Command4_Click()
MSComm1.OutBufferCount = 0
End Sub
Private Sub Command5_Click()
MSComm1.InBufferCount = 0
End Sub
Private Sub MSComm1_OnComm()
Dim buffer As String
buffer = MSComm1.Input
Text2.Text = buffer
End Sub
,你设置的是二进制数据接收,直接给文本当然接不到了。
用数组接收再转成文本显示。
Dim buffer() As Byte
buffer = MSComm1.Input,send(0) = &HC0
send(1) = &HC0
send(2) = &H8
send(3) = &H41
MSComm1.Output = send
如果想发送十六进制到串口,这样给数组赋值是错误的,应该是把想要发送的十六进制数转成十进制送给数组,十六进制收发时,串口控件要选用“字节”发送
比如send(0) = 26 发送出去后,串口用十六进制收到的就是1A