请问vb多字节读取其中两位字节的问题
来源:百度知道 编辑:UC知道 时间:2024/07/08 02:13:45
Option Explicit
Dim strData As String
Private Sub Command1_Click()
Dim a(0) As Byte
a(0) = &H1
MSComm1.Output = a
End Sub
Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim buffer() As Byte
Select Case MSComm1.CommEvent
Case 2
buffer = MSComm1.Input
Dim i As Integer
For i = 0 To UBound(buffer)
If Len(Hex(buffer(i))) = 1 Then
strData = strData & "0" & Hex(buffer(i))
Else
strData = strData & Hex(buffer(i))
End If
Next
Text2 = strData
If Len(strData) =