AnsweredAssumed Answered

Getting Trace Data with Excel VBA

Question asked by kumagai on Mar 2, 2010
Latest reply on Mar 3, 2010 by tsilchia001
Hello,

I'm trying to get trace data from E8364B with Excel VBA. I connect E8364B to PC with 82357A USB/GPIB Interface.

I refer to the following article.
http://na.tm.agilent.com/pna/help/WebHe ... g_GPIB.htm

I want to get S21 data(frequency, real, imaginary) and display three columns at Excel worksheet.

I've established a connection. But an error occurs. I attach my code. Could you check my code?

Thanks

Sub TEST()
   
    Dim ioMgr As AgilentRMLib.SRMCls
    Dim instrument As VisaComLib.FormattedIO488
    Dim idn, dat As String

    Dim i, t As Integer
    Dim datum(1, 1000) As Double


    Set ioMgr = New AgilentRMLib.SRMCls
    Set instrument = New VisaComLib.FormattedIO488
    Set instrument.IO = ioMgr.Open("GPIB0::16")


'Preset the analyzer
instrument.WriteString "SYST:FPReset"

' Create and turn on window 1
instrument.WriteString "DISPlay:WINDow1:STATE ON"
    
'Define a measurement name, parameter
instrument.WriteString "CALCulate:PARameter:DEFine 'S21',S21"
   
' Associate ("FEED") the measurement name ('S21') to WINDow (1)
instrument.WriteString "DISPlay:WINDow:TRACe1:FEED 'S21'"

' Select the measurement before sending other 'Calc' commands
instrument.WriteString "CALCulate:PARameter:SELect 'S21'"


'Set sweep type to linear
instrument.WriteString "SENSe:SWEep:TYPE LIN"

'Set IF Bandwidth to 1000 Hz
instrument.WriteString "SENSe:BANDwidth 1000"

'Set Start Freq's to 3 GHz
instrument.WriteString "SENSe:FREQuency:STARt 3ghz"

'Set Start Freq's to 11 GHz
instrument.WriteString "SENSe:FREQuency:STOP 11ghz"

'Set number of points to 801
instrument.WriteString "SENSe:SWEep:POINts 801"


'Turn continuous sweep off
instrument.WriteString "INITiate:CONTinuous OFF"

'Take a sweep
instrument.WriteString "INITiate:IMMediate;*wai"

'Ask for the Data
instrument.WriteString "CALCulate:DATA? SDATA"

'Parse the data
For i = 0 To 800
    For t = 0 To 1
        'Read the Data
            dat = instrument.ReadString()
        'Parse it into an array
            datum(t, i) = Val(dat)
    Next t
Next i

End Sub

Outcomes