在Text3的属性页设置MultiLine为TrueOption Explicit
Dim BytReceived() As Byte
Dim strData As String
Dim lenInput As IntegerPrivate Sub Command1_Click()
Dim strSend As String
Dim bData(0) As Byte
bData(0) = &HBA
MSComm1.Output = bData
strSend = Chr(&H9) & Text1 & Text2 & Chr(&H1)
MSComm1.Output = strSendEnd SubPrivate Sub Form_Load()
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 6
MSComm1.PortOpen = True
Text1 = 350
Text2 = "01.bmp"End SubPrivate Sub MSComm1_OnComm() '接收数据
Dim strBuff As String
Text3 = ""
Select Case MSComm1.CommEvent
Case 2
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
jieshou
If Mid(strData, 1, 2) = "BA" Then
strData = ""
End If
End SelectEnd SubPublic Function jieshou() '接收数据处理为16进制
Dim i As Integer
For i = 0 To UBound(BytReceived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i)) & vbNewLine
Else
strData = strData & Hex(BytReceived(i)) & vbNewLine
End If
Next
Text3 = strDataEnd Function