Other topics about Sample Programs
This sample program demonstrates how to search for peaks using the Marker Search feature and analysis commands.
This program works in three steps:
See Searching for Positions That Match Specified Criteria for this programming.
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
Sub PeakSearch_Click()
Range("B6:I30").Clear
Dim Excursion As Double
Dim Freq As Double, Resp As Variant, PeakPoint As Variant
Dim Poin As Long, Stat As Long, Dummy As Long
Excursion = 1
Set ioMgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
'
'*** Open the instrument.
Set Ena.IO = ioMgr.Open("GPIB0::18::INSTR")
Ena.IO.timeout = 10000
'
' Setup Analyzer
'
Ena.WriteString ":SYST:PRES", True
Ena.WriteString ":INIT:CONT ON", True
Ena.WriteString ":TRIG:SOUR BUS", True
Ena.WriteString ":SENS1:FREQ:CENT 950E6", True
Ena.WriteString ":SENS1:FREQ:SPAN 200E6", True
Ena.WriteString ":SENS1:SWE:POIN 201", True
Ena.WriteString ":CALC1:PAR1:DEF S21", True
Ena.WriteString ":CALC1:PAR1:SEL", True ' Select trace 1
' Make a Measurement
Ena.WriteString ":TRIG:SING", True
Ena.WriteString "*OPC?", True ' Wait measurement end
Dummy = Ena.ReadNumber
Ena.WriteString ":DISP:WIND1:TRAC1:Y:AUTO", True ' Auto scale
'
' Example of Marker Peak Search
'
Ena.WriteString ":CALC1:MARK:FUNC:DOM ON", True
Ena.WriteString ":CALC1:MARK:FUNC:DOM:STAR 900E6", True
Ena.WriteString ":CALC1:MARK:FUNC:DOM:STOP 1E9", True
Ena.WriteString ":CALC1:MARK1:FUNC:TYPE PEAK", True ' Search type: peak
Ena.WriteString ":CALC1:MARK1:FUNC:PEXC " & Str(Excursion), True ' Set peak excursion
Ena.WriteString ":CALC1:MARK1:FUNC:PPOL POS", True ' Peak Polarity: positive
Ena.WriteString ":CALC1:MARK1:FUNC:EXEC", True ' Execute search
'Call ErrorCheck
Ena.WriteString ":CALC1:MARK1:X?", True ' Read marker stimulus value
Freq = Ena.ReadNumber
Ena.WriteString ":CALC1:MARK1:Y?", True ' Read marker value
Resp = Ena.ReadList
Cells(6, 2).Value = Val(Freq)
Cells(6, 3).Value = Resp(0) ' Display real part of result.
'
' Example of All Peak Search
'
Ena.WriteString ":CALC1:FUNC:DOM ON", True
Ena.WriteString ":CALC1:FUNC:DOM:STAR 900E6", True
Ena.WriteString ":CALC1:FUNC:DOM:STOP 1E9", True
Ena.WriteString ":CALC1:FUNC:TYPE APEAK", True ' Search type: all peak
Ena.WriteString ":CALC1:FUNC:PEXC " & Str(Excursion), True ' Set peak excursion
Ena.WriteString ":CALC1:FUNC:PPOL POS", True ' Peak Polarity: positive
Ena.WriteString ":CALC1:FUNC:EXEC", True ' Execute search
Ena.WriteString "*OPC?", True
Dummy = Ena.ReadNumber
Call ErrorCheck
'
Ena.WriteString ":CALC1:FUNC:POIN?", True ' Read value
Poin = Ena.ReadNumber
Ena.WriteString ":CALC1:FUNC:DATA?", True ' Read stimulus point number
PeakPoint = Ena.ReadList '
j = 0
For i = 1 To Poin
Cells(5 + i, 5).Value = Val(PeakPoint(j))
Cells(5 + i, 6).Value = Val(PeakPoint(j + 1))
j = j + 2
Next i
'
' Example of Multi Peak Search
'
Ena.WriteString ":CALC1:MARK:FUNC:MULT:TYPE PEAK", True
Ena.WriteString ":CALC1:MARK:FUNC:MULT:PEXC " & Str(Excursion), True
Ena.WriteString ":CALC1:MARK:FUNC:MULT:PPOL POS", True
Ena.WriteString ":CALC1:MARK:FUNC:EXEC", True
Ena.WriteString "*OPC?", True
Dummy = Ena.ReadNumber
Call ErrorCheck
For i = 1 To 9
Ena.WriteString ":CALC1:MARK" & i & "?", True ' Check if marker is active.
Stat = Ena.ReadNumber
If Stat = 1 Then
Ena.WriteString ":CALC1:MARK" & i & ":X?", True ' Read marker stimulus value
Freq = Ena.ReadNumber
Ena.WriteString ":CALC1:MARK" & i & ":Y?", True ' Read marker value
Resp = Ena.ReadList
Cells(5 + i, 8).Value = Val(Freq)
Cells(5 + i, 9).Value = Resp(0)
End If
Next i
Ena.IO.Close
'
End Sub
Sub ErrorCheck()
Dim err As Variant
Ena.WriteString ":SYST:ERR?", True 'Reads error message.
err = Ena.ReadList
If Val(err(0)) <> 0 Then
Response = MsgBox(CStr(err(1)), vbOKOnly) 'Display the message box.
End If
End Sub