试试我下面的程序,前提是你按规范发送数据。
Private Sub Command1_Click()
Timer1.Enabled = True
Command1.BackColor = vbGreen
End Sub
Private Sub Command2_Click()
Text1.Text = ""
End Sub
Private Sub Form_Load()
'通讯口初始化:
With MSComm1
.Settings = "9600,n,8,2"
.CommPort = 3
.InputMode = comInputModeBinary
.InBufferCount = 0
.OutBufferCount = 0
.RThreshold = 0
.SThreshold = 0
.PortOpen = True
End With
Text1.Text = ""
End Sub
Private Sub Text1_Change()
If Len(Text1.Text) > 10000 Then Text1.Text = ""
End Sub
Private Sub Timer1_Timer()
'采用轮循法采集数据
Dim inx() As Byte
Dim strTemp As String
Dim strTemp1 As String
Dim ReceivedLen As Integer
Timer1.Enabled = False '关闭定时器
If MSComm1.InBufferCount > 0 Then
ReceivedLen = MSComm1.InBufferCount
inx = MSComm1.Input
For i = 0 To UBound(inx)
strTemp1 = Hex(inx(i))
If Len(strTemp1) > 1 Then
strTemp = strTemp & strTemp1 & " "
Else
strTemp = strTemp & "0" & strTemp1 & " "
End If
Next i
Text1.Text = Text1.Text & Format(Second(Now), "00") & Right(Format(Str(Timer), "0.00"), 3) & " " & strTemp & vbCrLf
Text1.SelStart = Len(Text1.Text)
End If
Timer1.Enabled = True '打开定时器
Label1.Caption = Now()
End Sub