Option Explicit
Dim i As Integer
Dim strData As String
Private Sub Command1_Click()
Dim by(9) As Byte
by(0) = &H7E
by(1) = &H0
by(2) = &H26
by(3) = &H0
by(4) = &H0
by(5) = &H0
by(6) = &H0
by(7) = &H0
by(8) = &H0
by(9) = &H26
MSComm1.Output = by
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 0
End SubPrivate Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.InBufferSize = 64
MSComm1.OutBufferSize = 64
MSComm1.RThreshold = 10 '按下位机返回数据字节长设置
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.PortOpen = True
Timer1.Interval = 0
End SubPrivate Sub MSComm1_OnComm()
Dim strBuff As String
Dim str() As Byte
Select Case MSComm1.CommEvent
Case comEvReceive
Text1 = ""
MSComm1.InputLen = 0
strBuff = MSComm1.Input
str() = strBuff
'接收数据处理为16进制
For i = 0 To UBound(str)
If Len(Hex(str(i))) = 1 Then
strData = strData & "0" & Hex(str(i))
Else
strData = strData & Hex(str(i))
End If
Next
Text1.Text = strData
Call Timer1_Timer
End Select
End SubPrivate Sub Timer1_Timer()
strData = ""
End Sub 

解决方案 »

  1.   

    这是串口通信程序
    古语言:欲速则不达,楼主还是耐住性子学习一下相关知识吧,不然神仙都帮不了你
    http://download.csdn.net/source/1498637
    http://download.csdn.net/source/1498644
      

  2.   

    Private Sub MSComm1_OnComm() 
    Dim strBuff As String 
    Dim str() As Byte 
    Select Case MSComm1.CommEvent 
    Case comEvReceive 
    Text1 = "" 
    MSComm1.InputLen = 0 
    strBuff = MSComm1.Input 
    str() = strBuff 
    '接收数据处理为16进制 
    For i = 0 To UBound(str) 
    If Len(Hex(str(i))) = 1 Then 
    strData = strData & "0" & Hex(str(i)) 
    Else 
    strData = strData & Hex(str(i)) 
    End If 
    Next 
    Text1.Text = strData 
    Call Timer1_Timer 
    End Select 
    End Sub Private Sub Timer1_Timer() 
    strData = ""