VB串口通信程序设备接收不到(急)

来源:百度知道 编辑:UC知道 时间:2024/06/22 08:16:40
帮看看我的程序,设备没有响应,前提是我的串口中,波特率等一切用的都对,发去命令是十六进制的,用控制软件就好用,关了控制软件用我的就不行,没有反应也没有回应
Private Sub Command1_Click()
Dim fs(1 To 6) As Byte
Dim i As Integer
fs(1) = &HF5
For i = 0 To 3
fs(i + 2) = Val("&h" & Text1(i).Text)
Next
fs(i + 2) = &HFA
'MSComm1.Output = fs & vbcrlf
MSComm1.Output = fs
For i = 1 To 6
Form1.Print fs(i)
Next
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "115200,N,8,1"
MSComm1.PortOpen = True
MSComm1.RThreshold = 6
MSComm1.SThreshold = 6
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 0
End Sub

Private Sub MSComm1_OnComm()
Dim js() As Byte
Dim i As Integer
js = MSComm1.Input
For i = 0 To UBound(js)
Text2.Text = Text2.Text & Hex(js(i)) & " "
Next i
Text2.Text = Text2.Text & vbCrLf
End Sub
我把发出的数组里的数打出来了,A输出的是10,可是为什么不好用呢,或说发出的数据要AH么

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "115200,N,8,1"
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
'MSComm1.SThreshold = 6
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 0
Text2 = ""
End Sub
Private Sub Command1_Click()
Dim fs(1 To 6) As Byte
Dim i As Integer
fs(1) = &HF5
For i = 0 To 3
fs(i + 2) = Val("&h" & Text1(i).Text)
Next
fs(i + 2) = &HFA
MSComm1.Output = fs
End Sub
Private Sub MSComm1_OnComm()
Dim js() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case 2
js = MSComm1.Input
For i = 0 To UBound(js)
Text2.Text = Text2.Text & Right("0" & Hex(js(i)), 2) & " "
Next i
Text2.Text = Text2.Text & vbCrLf
End Select