The Keysight E4402B and E4407B spectrum analyzer is controlled remotely with SCPI commands. TestFlow's instrument library holds 86 commands for it, 20 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 E4402B on a real bench.
Describe the test; TestFlow's agent uses this command set to drive your Keysight E4402B or E4407B and writes the report from the measured results.
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 E4402B's VISA address
# Paste the address of your Keysight E4402B (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()Describe the test; TestFlow's agent uses this command set to drive your Keysight E4402B or E4407B and writes the report from the measured results.
Describe the test in a sentence, for example “set full span on the E4402B, 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.
86 commands in 19 groups. A ? marks a query that returns a value. Placeholders in angle brackets take the listed values. The E4402B and E4407B share this command set in TestFlow's library.
| Command | What it does | Arguments |
|---|---|---|
| :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:FULL | Set Full Span. Sets the span to the full frequency range of the analyzer. | None |
| :SENSe:FREQuency:SPAN 0 | Set Zero Span. Sets the analyzer to zero span (time-domain at the center frequency). | None |
| :SENSe:POWer:RF:ATTenuation:AUTO ON | Set Atten Auto On. Enables automatic input attenuation coupling to the reference level. | None |
| :SENSe:POWer:RF:ATTenuation:AUTO OFF | Set 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 ON | Preamp On. Turns the internal RF preamplifier on (option dependent). | None |
| :SENSe:POWer:RF:GAIN:STATe OFF | Preamp Off. Turns the internal RF preamplifier off. | None |
| :SENSe:BANDwidth:RESolution:AUTO ON | Set RBW Auto On. Enables automatic coupling of resolution bandwidth to span. | None |
| :SENSe:BANDwidth:RESolution:AUTO OFF | Set 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 ON | Set VBW Auto On. Enables automatic coupling of video bandwidth to RBW. | None |
| :SENSe:BANDwidth:VIDeo:AUTO OFF | Set 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 ON | Set Sweep Time Auto On. Enables automatic sweep time coupling to span and bandwidth. | None |
| :SENSe:SWEep:TIME:AUTO OFF | Set 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 |
| :SENSe:SWEep:POINts? | Get Sweep Points. Queries the number of sweep data points. | None |
| :SENSe:DETector:FUNCtion <Detector> | Set Detector. Sets the detector type used to reduce sweep data to trace points. | Text: POSitive,NEGative,SAMPle,AVERage,RMS |
| :SENSe:DETector:AUTO ON | Set Detector Auto. Enables automatic detector selection based on the measurement. | None |
| :SENSe:AVERage:STATe ON | Set Average On. Turns trace averaging on. | None |
| :SENSe:AVERage:STATe OFF | Set 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 used for trace averaging. | Text: VIDeo,RMS |
| :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 <Impedance> | Set Input Impedance. Sets the input impedance reference (50 or 75 ohms) for amplitude correction. | Number: 50,75 |
| Command | What it does | Arguments |
|---|---|---|
| :CALCulate:MARKer<MkrNum>:STATe ON | Marker On. Turns on the specified marker. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:STATe OFF | Marker Off. Turns off the specified marker. | Number: 1,2,3,4 |
| :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; Number |
| :CALCulate:MARKer<MkrNum>:X? | Get Marker X. Queries the X-axis position (frequency/time) of the specified marker. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:Y? | Get Marker Y. Queries the Y-axis amplitude value at the specified marker. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:MAXimum | Marker Peak Search. Moves the specified marker to the highest peak on the trace. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:MAXimum:NEXT | Marker Peak Next. Moves the specified marker to the next-highest peak. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:MINimum | Marker Min Search. Moves the specified marker to the minimum point on the trace. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:CENTer | Marker To Center. Sets the center frequency to the marker's current frequency. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:RLEVel | Marker To Ref Level. Sets the reference level to the marker's current amplitude. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:MODE DELTa | Set Marker Delta. Sets the specified marker to delta (relative) mode. | Number: 1,2,3,4 |
| :CALCulate:MARKer<MkrNum>:FUNCtion NOISe | Set Marker Noise. Turns on the noise marker function for the specified marker. | Number: 1,2,3,4 |
| Command | What it does | Arguments |
|---|---|---|
| :DISPlay:WINDow:TRACe:X:SCALe:OFFSet <Offset> | Set Freq Offset. Sets a frequency offset added to all displayed frequency readouts in Hz. | Number |
| :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:WINDow:TRACe:Y:SCALe:SPACing <Spacing> | Set Y Scale Type. Sets the vertical scale to logarithmic or linear. | Text: LOGarithmic,LINear |
| Command | What it does | Arguments |
|---|---|---|
| :INITiate:CONTinuous ON | Continuous Sweep On. Sets the analyzer to continuous (free-run) sweep mode. | None |
| :INITiate:CONTinuous OFF | Continuous Sweep Off. Sets the analyzer to single-sweep mode. | None |
| :INITiate:IMMediate | Initiate Sweep. Triggers a new sweep/measurement (single-shot when not continuous). | None |
| Command | What it does | Arguments |
|---|---|---|
| :CONFigure:CHPower | Config Channel Power. Configures the analyzer for the Channel Power (CHP) measurement. | None |
| :CONFigure:ACPower | Config ACP. Configures the analyzer for the Adjacent Channel Power (ACP) measurement. | None |
| :CONFigure:OBWidth | Config OBW. Configures the analyzer for the Occupied Bandwidth (OBW) measurement. | None |
| Command | What it does | Arguments |
|---|---|---|
| :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 |
| Command | What it does | Arguments |
|---|---|---|
| :TRACe<TraceNum>:MODE <TraceMode> | Set Trace Mode. Sets the update mode for the specified trace (clear-write/max-hold/min-hold/view/blank). | Number: 1,2,3; Text: WRITe,MAXHold,MINHold,VIEW,BLANk |
| :TRACe:DATA? <TraceName> | Read Trace Data. Reads back the amplitude data points of the specified trace. | Text: TRACE1,TRACE2,TRACE3 |
| Command | What it does | Arguments |
|---|---|---|
| :TRIGger:SOURce <Source> | Set Trigger Source. Selects the sweep trigger source. | Text: IMMediate,VIDeo,LINE,EXTernal,RFBurst |
| :TRIGger:VIDeo:LEVel <Level> | Set Trigger Level. Sets the video trigger level in the current amplitude units. | Number |
| Command | What it does | Arguments |
|---|---|---|
| :INSTrument:SELect SA | Select SA Mode. Selects the basic Spectrum Analyzer measurement personality. | None |
| Command | What it does | Arguments |
|---|---|---|
| :UNIT:POWer <Units> | Set Y Units. Sets the amplitude (Y-axis) units for power readouts. | Text: DBM,DBMV,DBUV,DBUA,V,W,A |
| Command | What it does | Arguments |
|---|---|---|
| :FORMat:DATA <Format> | Set Trace Format. Sets the numeric data format used when transferring trace data. | Text: ASCii |
| Command | What it does | Arguments |
|---|---|---|
| :ABORt | Abort. Aborts the current sweep or measurement in progress. | None |
| Command | What it does | Arguments |
|---|---|---|
| :INPut:COUPling <Coupling> | Set Input Coupling. Sets the RF input coupling to AC or DC. | Text: AC,DC |
| Command | What it does | Arguments |
|---|---|---|
| :MMEMory:STORe:SCReen "C:\Temp\scrn.gif" ; wait(500) ; :MMEMory:DELete "C:\Temp\scrn.gif" | Capture. Saves a screen image to a temporary file on the analyzer, reads it back to the controller, then deletes the temp file. | None |
| Command | What it does | Arguments |
|---|---|---|
| :CALibration:ALL? | Self Calibration. Runs internal self-alignment/calibration and returns 0 on success. | None |
| Command | What it does | Arguments |
|---|---|---|
| <Output Variable>=<Equation> | Math. Variable equals an equation like (${Var_name}= ${Var_name}/2) | Number; Text |
| Command | What it does | Arguments |
|---|---|---|
| wait(<ms>) | Wait. Waits for number of milliseconds | Number |
| Command | What it does | Arguments |
|---|---|---|
| save2var <Variable_name> | Save2Variable. Saves last measurement to a variable | Text |
| Command | What it does | Arguments |
|---|---|---|
| *IDN? | Identify. Returns the instrument identification string (manufacturer, model, serial, firmware). | None |
| *RST | Reset. Resets the instrument to its default state. | None |
| *CLS | Clear 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 |
| *WAI | Wait To Continue. Waits until all pending operations are complete before continuing. | None |
| *TRG | Trigger Bus. Generates a bus trigger when the instrument is in wait-for-trigger state. | None |
This reference is generated from TestFlow's instrument library, which is drafted from Keysight's programming documentation for the E4402B and E4407B 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 17, 2026.
Yes. The Keysight E4402B accepts SCPI commands over its remote interfaces. TestFlow's instrument library holds 86 SCPI commands for it: 20 queries that read values or state, and 66 settings and actions.
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?.
: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.
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 E4402B through the TestFlow desktop app, and writes the report from the measured results.
Describe the test. TestFlow builds the workflow, runs it on your instruments, and writes the report. See it on a bench like yours.