Spectrum Analyzer · SCPI command reference

Keysight N9020B SCPI commands

The Keysight N9020B spectrum analyzer is controlled remotely with SCPI commands. TestFlow's instrument library holds 103 commands for it, 22 of them queries that read values or state, grouped below by subsystem with their arguments. It is the same library TestFlow's AI agent uses to drive the N9020B on a real bench.

Commands
103
Queries
22
Subsystems
19
Models covered
1

Control the Keysight N9020B from Python

With PyVISA, any VISA backend, and the instrument on USB, LAN or GPIB, this opens a session, identifies the instrument, sends one setting, and reads one value. Every command in it comes from the reference below. For a full walkthrough, see the PyVISA tutorial and the SCPI command cheat sheet.

import pyvisa

rm = pyvisa.ResourceManager()
print(rm.list_resources())  # find the Keysight N9020B's VISA address

# Paste the address of your Keysight N9020B (USB, LAN or GPIB).
inst = rm.open_resource("PASTE_VISA_ADDRESS_HERE")
inst.timeout = 5000  # ms

print(inst.query("*IDN?"))  # identify the instrument
inst.write(":SENSe:FREQuency:SPAN:FULL")  # Set Full Span
print(inst.query(":READ:CHPower?"))  # Read Channel Power

inst.close()

Run a N9020B test without writing code

Describe the test in a sentence, for example “set full span on the N9020B, then read channel power and log it against a limit”. TestFlow's agent builds the steps from this command library, runs them on your bench through the TestFlow desktop app, and writes the report from the measured values. See AI test automation for lab instruments for how that works and where it stops.

Get started

SCPI command reference

103 commands in 19 groups. A ? marks a query that returns a value. Placeholders in angle brackets take the listed values.

Sense (SENSe) (42)

CommandWhat it doesArguments
:SENSe:FREQuency:CENTer <Frequency>Set Center Freq. Sets the center frequency of the displayed span in Hz.Number
:SENSe:FREQuency:CENTer?Get Center Freq. Queries the current center frequency in Hz.None
:SENSe:FREQuency:STARt <Frequency>Set Start Freq. Sets the start (left edge) frequency of the sweep in Hz.Number
:SENSe:FREQuency:STARt?Get Start Freq. Queries the start frequency in Hz.None
:SENSe:FREQuency:STOP <Frequency>Set Stop Freq. Sets the stop (right edge) frequency of the sweep in Hz.Number
:SENSe:FREQuency:STOP?Get Stop Freq. Queries the stop frequency in Hz.None
:SENSe:FREQuency:SPAN <Span>Set Span. Sets the frequency span of the sweep in Hz.Number
:SENSe:FREQuency:SPAN?Get Span. Queries the current frequency span in Hz.None
:SENSe:FREQuency:SPAN:FULLSet Full Span. Sets the span to the full frequency range of the analyzer.None
:SENSe:FREQuency:SPAN 0Set Zero Span. Sets the analyzer to zero span (time-domain at the center frequency).None
:SENSe:FREQuency:OFFSet <Offset>Set Freq Offset. Sets a frequency offset added to all displayed frequency readouts in Hz.Number
:SENSe:POWer:RF:ATTenuation:AUTO ONSet Atten Auto On. Enables automatic input attenuation coupling to the reference level.None
:SENSe:POWer:RF:ATTenuation:AUTO OFFSet Atten Auto Off. Disables automatic attenuation so the manual attenuation value is used.None
:SENSe:POWer:RF:ATTenuation <Atten>Set Attenuation. Sets the input RF attenuation in dB (manual mode).Number
:SENSe:POWer:RF:ATTenuation?Get Attenuation. Queries the current input RF attenuation in dB.None
:SENSe:POWer:RF:GAIN:STATe ONPreamp On. Turns the internal RF preamplifier on.None
:SENSe:POWer:RF:GAIN:STATe OFFPreamp Off. Turns the internal RF preamplifier off.None
:SENSe:BANDwidth:RESolution:AUTO ONSet RBW Auto On. Enables automatic coupling of resolution bandwidth to span.None
:SENSe:BANDwidth:RESolution:AUTO OFFSet RBW Auto Off. Disables automatic RBW so the manual value is used.None
:SENSe:BANDwidth:RESolution <RBW>Set RBW. Sets the resolution bandwidth (RBW) in Hz.Number
:SENSe:BANDwidth:RESolution?Get RBW. Queries the current resolution bandwidth in Hz.None
:SENSe:BANDwidth:VIDeo:AUTO ONSet VBW Auto On. Enables automatic coupling of video bandwidth to RBW.None
:SENSe:BANDwidth:VIDeo:AUTO OFFSet VBW Auto Off. Disables automatic VBW so the manual value is used.None
:SENSe:BANDwidth:VIDeo <VBW>Set VBW. Sets the video bandwidth (VBW) in Hz.Number
:SENSe:BANDwidth:VIDeo?Get VBW. Queries the current video bandwidth in Hz.None
:SENSe:SWEep:TIME:AUTO ONSet Sweep Time Auto On. Enables automatic sweep time coupling to span and bandwidth.None
:SENSe:SWEep:TIME:AUTO OFFSet Sweep Time Auto Off. Disables automatic sweep time so the manual value is used.None
:SENSe:SWEep:TIME <Time>Set Sweep Time. Sets the sweep time in seconds.Number
:SENSe:SWEep:TIME?Get Sweep Time. Queries the current sweep time in seconds.None
:SENSe:SWEep:POINts <Points>Set Sweep Points. Sets the number of sweep (trace) data points.Number: 101,201,401,1001,2001,4001,8001,20001,40001
:SENSe:SWEep:POINts?Get Sweep Points. Queries the number of sweep data points.None
:SENSe:DETector:TRACe <Detector>Set Detector. Sets the detector type used to reduce sweep data to trace points.Text: NORMal,AVERage,POSitive,NEGative,SAMPle,QPEak,EAVerage,RAVerage
:SENSe:DETector:AUTO ONSet Detector Auto. Enables automatic detector selection based on the trace and measurement.None
:SENSe:AVERage:STATe ONSet Average On. Turns trace averaging on.None
:SENSe:AVERage:STATe OFFSet Average Off. Turns trace averaging off.None
:SENSe:AVERage:COUNt <Count>Set Average Count. Sets the number of averages to accumulate.Number
:SENSe:AVERage:TYPE <AvgType>Set Average Type. Sets the averaging type (power/RMS, log-power, or voltage/scalar).Text: RMS,LOG,SCALar
:SENSe:CHPower:BANDwidth:INTegration <IBW>Set CHP Integ BW. Sets the integration bandwidth used by the channel power measurement in Hz.Number
:SENSe:OBWidth:PERCent <Percent>Set OBW Percent. Sets the percent of total power used to define occupied bandwidth (typically 99).Number
:SENSe:CORRection:IMPedance:INPut:MAGNitude <Impedance>Set Input Impedance. Sets the input impedance reference (50 or 75 ohms) for amplitude correction.Number: 50,75
:SENSe:CORRection:SA:GAIN <Gain>Set Ext Gain. Sets an external gain/loss correction value applied to displayed amplitudes in dB.Number
:SENSe:ROSCillator:SOURce <Source>Set Ref Osc Source. Selects the reference oscillator (timebase) source: internal or external.Text: INTernal,EXTernal,SENSe

Calculate (CALCulate) (19)

CommandWhat it doesArguments
:CALCulate:MARKer<MkrNum>:STATe ONMarker On. Turns on the specified marker.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:STATe OFFMarker Off. Turns off the specified marker.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:X <Position>Set Marker X. Sets the X-axis (frequency or time) position of the specified marker.Number: 1,2,3,4,5,6,7,8,9,10,11,12; Number
:CALCulate:MARKer<MkrNum>:X?Get Marker X. Queries the X-axis position (frequency/time) of the specified marker.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:Y?Get Marker Y. Queries the Y-axis amplitude value at the specified marker.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MAXimumMarker Peak Search. Moves the specified marker to the highest peak on the trace.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MAXimum:NEXTMarker Peak Next. Moves the specified marker to the next-highest peak.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MAXimum:LEFTMarker Peak Left. Moves the specified marker to the next peak to the left.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MAXimum:RIGHtMarker Peak Right. Moves the specified marker to the next peak to the right.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MINimumMarker Min Search. Moves the specified marker to the minimum point on the trace.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:CENTerMarker To Center. Sets the center frequency to the marker's current frequency.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:RLEVelMarker To Ref Level. Sets the reference level to the marker's current amplitude.Number: 1,2,3,4,5,6,7,8,9,10,11,12
:CALCulate:MARKer<MkrNum>:MODE <Mode>Set Marker Mode. Sets the marker mode (normal position/delta/fixed/off).Number: 1,2,3,4,5,6,7,8,9,10,11,12; Text: POSition,DELTa,FIXed,OFF
:CALCulate:MARKer<MkrNum>:FUNCtion <Function>Set Marker Function. Sets a marker function such as noise marker or band/interval power.Number: 1,2,3,4,5,6,7,8,9,10,11,12; Text: NOISe,BPOWer,OFF
:CALCulate:MARKer<MkrNum>:FUNCtion:BAND:SPAN <Span>Set Marker Band Span. Sets the integration bandwidth (band span) for the marker band power function.Number: 1,2,3,4,5,6,7,8,9,10,11,12; Number
:CALCulate:MARKer:PEAK:TABLe:STATe ONPeak Table On. Turns on the peak table display listing detected signal peaks.None
:CALCulate:MARKer:PEAK:TABLe:STATe OFFPeak Table Off. Turns off the peak table display.None
:CALCulate:MARKer:PEAK:THReshold <Threshold>Set Peak Threshold. Sets the amplitude threshold above which peaks are recognized by peak search.Number
:CALCulate:MARKer:PEAK:EXCursion <Excursion>Set Peak Excursion. Sets the peak excursion (in dB) a signal must rise and fall to qualify as a peak.Number

Display (DISPlay) (5)

CommandWhat it doesArguments
:DISPlay:WINDow:TRACe:Y:SCALe:RLEVel <Level>Set Ref Level. Sets the reference level (top of the display grid) in the current Y units.Number
:DISPlay:WINDow:TRACe:Y:SCALe:RLEVel?Get Ref Level. Queries the current reference level.None
:DISPlay:WINDow:TRACe:Y:SCALe:PDIVision <ScalePerDiv>Set Y Scale Div. Sets the vertical scale per division (dB/div in log mode).Number
:DISPlay:ENABle ONDisplay All On. Turns the front-panel display update on.None
:DISPlay:ENABle OFFDisplay All Off. Turns the front-panel display update off to speed up remote operation.None

Configure (CONFigure) (5)

CommandWhat it doesArguments
:CONFigure:CHPowerConfig Channel Power. Configures the analyzer for the Channel Power (CHP) measurement.None
:CONFigure:ACPowerConfig ACP. Configures the analyzer for the Adjacent Channel Power (ACP) measurement.None
:CONFigure:OBWidthConfig OBW. Configures the analyzer for the Occupied Bandwidth (OBW) measurement.None
:CONFigure:TOIConfig TOI. Configures the analyzer for the third-order intercept (TOI) measurement.None
:CONFigure:HARMonicsConfig Harmonics. Configures the analyzer for the harmonic distortion measurement.None

Read (READ) (5)

CommandWhat it doesArguments
:READ:CHPower?Read Channel Power. Initiates and reads the channel power and power-spectral-density result.None
:READ:ACPower?Read ACP. Initiates and reads the adjacent channel power ratio results.None
:READ:OBWidth?Read OBW. Initiates and reads the occupied bandwidth result.None
:READ:TOI?Read TOI. Initiates and reads the third-order intercept measurement results.None
:READ:HARMonics:DISTortion?Read Harmonics. Initiates and reads the total harmonic distortion result.None

Trace (TRACe) (4)

CommandWhat it doesArguments
:TRACe<TraceNum>:TYPE <TraceType>Set Trace Type. Sets the update type for the specified trace (clear-write/average/max-hold/min-hold).Number: 1,2,3,4,5,6; Text: WRITe,AVERage,MAXHold,MINHold
:TRACe<TraceNum>:UPDate:STATe ONSet Trace Update On. Enables live updating of the specified trace.Number: 1,2,3,4,5,6
:TRACe<TraceNum>:UPDate:STATe OFFSet Trace Update Off. Freezes (stops updating) the specified trace.Number: 1,2,3,4,5,6
:TRACe:DATA? <TraceName>Read Trace Data. Reads back the amplitude data points of the specified trace.Text: TRACE1,TRACE2,TRACE3,TRACE4,TRACE5,TRACE6

Initiate (INITiate) (3)

CommandWhat it doesArguments
:INITiate:CONTinuous ONContinuous Sweep On. Sets the analyzer to continuous (free-run) sweep mode.None
:INITiate:CONTinuous OFFContinuous Sweep Off. Sets the analyzer to single-sweep mode.None
:INITiate:IMMediateInitiate Sweep. Triggers a new sweep/measurement (single-shot when not continuous).None

Instrument (INSTrument) (2)

CommandWhat it doesArguments
:INSTrument:SELect SASelect SA Mode. Selects the Spectrum Analyzer (Swept SA) measurement mode.None
:INSTrument:SELect <Mode>Select Mode. Selects the active measurement mode/application on the analyzer.Text: SA,BASIC,WCDMA,EDGEGSM,LTEAFDD,LTEATDD,NFIGure,PNOISE,VSA89601,RTSA,EMI,SEQAN,ADEMOD,BTooth,WLAN

Trigger (TRIGger) (2)

CommandWhat it doesArguments
:TRIGger:SOURce <Source>Set Trigger Source. Selects the sweep trigger source.Text: IMMediate,VIDeo,LINE,EXTernal1,EXTernal2,RFBurst,FRAMe
:TRIGger:VIDeo:LEVel <Level>Set Trigger Level. Sets the video trigger level in the current amplitude units.Number

UNIT subsystem (1)

CommandWhat it doesArguments
:UNIT:POWer <Units>Set Y Units. Sets the amplitude (Y-axis) units for power readouts.Text: DBM,DBMV,DBMA,V,W,A,DBUV,DBUA,DBUVM,DBUAM,DBPT,DBG

FORM subsystem (1)

CommandWhat it doesArguments
:FORMat:TRACe:DATA <Format>Set Trace Format. Sets the numeric data format used when transferring trace data.Text

Abort (1)

CommandWhat it doesArguments
:ABORtAbort. Aborts the current sweep or measurement in progress.None

INP subsystem (1)

CommandWhat it doesArguments
:INPut:COUPling <Coupling>Set Input Coupling. Sets the RF input coupling to AC or DC.Text: AC,DC

Mass memory (MMEMory) (1)

CommandWhat it doesArguments
:MMEMory:STORe:SCReen "C:\Temp\scrn.png" ; wait(500) ; :MMEMory:DELete "C:\Temp\scrn.png"Capture. Saves a screen image to a temporary PNG on the analyzer, reads it back to the controller, then deletes the temp file.None

CAL subsystem (1)

CommandWhat it doesArguments
:CALibration:ALL?Self Calibration. Runs internal self-alignment/calibration and returns 0 on success.None

Other subsystem (1)

CommandWhat it doesArguments
<Output Variable>=<Equation>Math. Variable equals an equation like (${Var_name}= ${Var_name}/2)Number; Text

WAIT subsystem (1)

CommandWhat it doesArguments
wait(<ms>)Wait. Waits for number of millisecondsNumber

SAVE subsystem (1)

CommandWhat it doesArguments
save2var <Variable_name>Save2Variable. Saves last measurement to a variableText

IEEE 488.2 common commands (7)

CommandWhat it doesArguments
*IDN?Identify. Returns the instrument identification string (manufacturer, model, serial, firmware).None
*RSTReset. Resets the instrument to its default state.None
*CLSClear Status. Clears all event registers and the error queue.None
*TST?Self Test. Runs the self-test and returns 0 for pass or 1 for failure.None
*OPC?Operation Complete. Returns 1 when all pending operations are complete.None
*WAIWait To Continue. Waits until all pending operations are complete before continuing.None
*TRGTrigger Bus. Generates a bus trigger when the instrument is in wait-for-trigger state.None

Where these commands come from

This reference is generated from TestFlow's instrument library, which is drafted from Keysight's programming documentation for the N9020B and checked when the agent runs it. Ranges, timing, and option-dependent commands are defined by Keysight's programming manual: check it before you rely on an edge case. Last updated November 12, 2026.

Frequently asked questions

Does the Keysight N9020B support SCPI remote control?

Yes. The Keysight N9020B accepts SCPI commands over its remote interfaces. TestFlow's instrument library holds 103 SCPI commands for it: 22 queries that read values or state, and 81 settings and actions.

How do I control the Keysight N9020B from Python?

Install PyVISA and a VISA backend, find the instrument's address with ResourceManager().list_resources(), open it, then send commands with write() and read values with query(). The example on this page sends *IDN?, :SENSe:FREQuency:SPAN:FULL and :READ:CHPower?.

Which command reads a value from the Keysight N9020B?

:READ:CHPower? (read channel power). Initiates and reads the channel power and power-spectral-density result. The full list of queries is in the command reference on this page, grouped by subsystem.

Can I automate the Keysight N9020B without writing code?

Yes. TestFlow is an AI agent for electronics testing: you describe the test, and it builds the automation from this command library, runs it on the Keysight N9020B through the TestFlow desktop app, and writes the report from the measured results.

Your next test, automated today

Describe the test. TestFlow builds the workflow, runs it on your instruments, and writes the report. See it on a bench like yours.