vb串口发送数据问题 急 在线等
我用vb的那个串口控件向串口发数据
例如发 "A5 " 十六进制数,一个字节
用串口助手监视的结果是A和5的ASCII码 最后在网上找了一段程序
处理以后再发送 用串口助手监视的结果又变成了0A 05
请问错在哪里呀 急 急 急
private sub SendData()
dim rdata as string
rdata=Change_S( "A5 ")
Comm.OutPut=rdata '串口控件发送
end sub
Private Function Change_S(strs As String) As String
Dim i As Integer, t As Integer
Dim s As String, m As String, temp As String, lishi As String
m = strs
For i = 1 To Len(m)
lishi = Mid(m, i, 1)
t = Asc(Mid(m, i, 1))
If t > = 48 And t <= 57 Then
s = Chr(t - 48)
ElseIf t > = 65 And t <= 70 Then
s = Chr(t - 55)
ElseIf t > = 97 And t <= 102 Then
s = Chr(t - 87)
End If
temp = temp & s
Next i
Change_S = temp
End Function
[解决办法]
Private Sub SendData()
Dim rdata() As Byte
rdata = Change_S( "A5B6C7D8 ")
Comm.OutPut = rdata '串口控件发送
End Sub
Private Function Change_S(strs As String) As Variant
Dim i As Integer, Result() As Byte
ReDim Result(Len(strs) \ 2 - 1)
For i = 0 To Len(strs) \ 2 - 1
Result(i) = Val( "&H " & Mid(strs, i * 2 + 1, 2))
Next i
Change_S = Result
End Function