很容易:
Dim bytSend(7) As Byte, bytRecv() As Byte, i As Integer, n As Integer, tmp As Variant
'初始化
Private Sub Form_Load()
With MSComm1
.Settings = "9600,n,8,1"
.CommPort = 1
.InputMode = comInputModeBinary
.RThreshold = 4
.PortOpen = True
End With
End Sub
'发送
Private Sub Command1_Click()
n = Len(Text1) \ 2 'Text1 = "A567353131308001"
For i = 0 To n - 1
bytSend(i) = Val("&H" & Mid(Text1, i * 2 + 1, 2))
Next i
For i = n To 7
bytSend(i) = &H20
Next i
MSComm1.Output = bytSend
End Sub
'接收
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case 2
tmp = MSComm1.Input
bytRecv = tmp
Text2 = ""
For i = 0 To UBound(bytRecv)
Text2 = Text2 & Right("0" & Hex(bytRecv(i)), 2)
Next i
End Select
End Sub