VB如何用串口发送一组ASCII码数据,所有发送或接收的数字都以ASCII代码来表示

2024-12-03 15:45:43
推荐回答(3个)
回答1:

Private Sub Command1_Click()
Dim b() As Byte, s As String
'b是你要往串口发的字节数组
b = StrConv(Right(String(6, "0") & Hex(Text1), 6), vbFromUnicode)

'以下是验证
For i = 0 To UBound(b)
s = s & Hex(b(i))
Next
Debug.Print s

'以下是还原
s = Format(Val("&H" & StrConv(b, vbUnicode)), String(6, "0"))
Debug.Print s

End Sub

Private Sub Form_Load()
Text1.Text = "000042"
End Sub

回答2:

&2ota;

回答3:

Ι