楼主想用EXCEL采集一台仪器(频谱仪)的测试数据,手里有以前的例子(做好的VBA),以前是用来采集HP的矢网仪,现在用来采集安捷伦的频谱仪,代码不多,也能看懂,但一些关键的指令不是很懂,感觉不能与频谱仪建立连接。就来论坛求助了。

解决方案 »

  1.   

    好,我这就把代码附上。
    Option Explicit' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
    ' Copyright (c) Agilent Technologies Inc. 1999.  All Rights Reserved.           '
    '                                                                               '
    ' Agilent Technologies provides programming samples for illustration            '
    ' purposes only.  This sample program assumes that you are familiar             '
    ' with the programming language being demonstrated and the tools used           '
    ' to create and debug procedures.  Agilent support engineers can help answer    '
    ' questions relating to the functionality of the software components            '
    ' provided by Agilent, but they will not modify these samples to provide added  '
    ' functionality or construct procedures to meet your specific needs.            '
    '                                                                               '
    ' You have a royalty-free right to use, modify, reproduce, and distribute       '
    ' this sample program (and/or any modified version) in any way you find         '
    ' useful, provided that you agree that Agilent has no warranty, obligations,    '
    ' or liability for any sample programs.                                         '
    '                                                                               '
    ' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'Dim nextTime As Variant
    Dim continue As Boolean
    Dim Scope As VisaComLib.FormattedIO488
    Dim i As Integer
    Dim T As IntegerSub cmdStart_Click()    ' set continue true to set the monitor
        continue = True
        ' start the readings
        update
        
    End SubSub cmdstop_click()
    Dim AMPTarget As Variant
     Dim i As Integer For i = 0 To 178
               AMPTarget = Cells(10 + i, 1)
    Cells(10 + i, 2) = ""Next
    End SubSub update()
        ' Using the Agt3494A control on this sheet, get the frequency
        ' and place in cell 'A1'
        ' set the timer to take the next reading
        Dim Freq As Long
        Dim reply As String
        Dim AMP As Variant
        Dim AMP2 As String
        Dim AMPTarget As Variant
        Dim FeqUp As Variant
        Dim FeqDown As Variant
        
       
        
        On Error GoTo MeasureError
             If continue Then ' take the reading
           
        '----------------滤波器1测试--------------------
             MsgBox "开始测试放大器"
           '-----测试频点增益----
            Scope.WriteString "CHAN1"
            'Scope.WriteString "STAR 6GHZ"
            'Scope.WriteString "STOP 18GHZ"
            Scope.WriteString "AVEROOff"
            'delay 1
            Scope.WriteString "AVEROOn"
            delay 8
            
             Dim i As Integer
             
             For i = 0 To 178
               AMPTarget = 0.3 + i * 0.1
           Scope.WriteString "MARK1" & Str$(AMPTarget) & "GHz"
            
            Scope.WriteString "OUTPMARK"
            AMP = Scope.ReadNumber
            Cells(10 + i, 2) = AMP
            
           
            Next
            
            
            'delay 1
            
            
            
            
            
            
            Scope.WriteString "AVEROOff"
            delay 1
            MsgBox "测试完毕"
           
                 
                        
        
        
        
        
        
        
        
        
        End If
        
        Exit Sub
        
    MeasureError:
        continue = False
        MsgBox "Error making measurement." & vbCrLf & _
        "Check IO settings, and make sure you have a valid waveform for this measurement."
    End SubSub SetIO(ByRef ioAddress As String)
        ' set the I/O address to the text box in case the
        ' user changed it.
        ' bring up the input dialog and save any changes to the
        ' text box
        Dim mgr As AgilentRMLib.SRMCls    On Error GoTo ioError    ioAddress = InputBox("Enter the IO address of the Scope", "Set IO address", ioAddress)    If Len(ioAddress) > 5 Then
            Set mgr = New AgilentRMLib.SRMCls
            Set Scope = New VisaComLib.FormattedIO488
            Set Scope.IO = mgr.Open(ioAddress)
        End If
        
        Exit Sub
        
    ioError:
        MsgBox "Set IO error:" & vbCrLf & Err.DescriptionEnd SubPrivate Sub CommandButton2_Click()
        SetIO Cells(5, 3)
    End Sub'------------------延时程序---------
    Sub delay(T As Single)
    Dim T1 As Single
    T1 = Timer
    Do
    DoEvents
    Loop While Timer - T1 < T
    End Sub
      

  2.   

    EXCEL界面上主要就三个按钮。
      

  3.   

    Dim Scope As VisaComLib.FormattedIO488
        ' Using the Agt3494A control on this sheet, get the frequency
        ' and place in cell 'A1'
        ' set the timer to take the next reading
     需要使用控件,看或搜相关控件的使用手册。
      

  4.   

    你说的对,我去找找 agilent e4440a 的指令手册。虽然感觉不是很好找的样子