The Keysight N9342C and N9344C spectrum analyzer is controlled remotely with SCPI commands. TestFlow's instrument library holds 76 commands for it, 17 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 N9342C on a real bench.
Describe the test; TestFlow's agent uses this command set to drive your Keysight N9342C or N9344C 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 N9342C's VISA address
# Paste the address of your Keysight N9342C (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(":MEASure:CHPower?")) # Read Channel Power
inst.close()Describe the test; TestFlow's agent uses this command set to drive your Keysight N9342C or N9344C and writes the report from the measured results.
Describe the test in a sentence, for example “set full span on the N9342C, 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.
76 commands in 14 groups. A ? marks a query that returns a value. Placeholders in angle brackets take the listed values. The N9342C and N9344C 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:FREQuency:OFFSet <Offset> | Set Freq Offset. Sets a frequency offset added to all displayed frequency readouts in Hz. | Number |
| :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. | 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:DETector:TRACe <Detector> | Set Detector. Sets the detector type used to reduce sweep data to trace points. | Text: NORMal,AVERage,POSitive,NEGative,SAMPle |
| :SENSe:AVERage:TRACe<TraceNum>:STATe ON | Set Average On. Turns trace averaging on. | Number: 1-4 |
| :SENSe:AVERage:TRACe<TraceNum>:STATe OFF | Set Average Off. Turns trace averaging off. | Number: 1-4 |
| :SENSe:AVERage:TRACe<TraceNum>:COUNt <Count> | Set Average Count. Sets the number of averages to accumulate. | Number: 1-4; Number: 1-8192 |
| :SENSe:AVERage:TYPE <AvgType> | Set Average Type. Sets the averaging type (power/RMS, log-power, or voltage/scalar). | Text: LOGPower,POWer,VOLTage |
| :SENSe:CHPower:BANDwidth:INTegration <IBW> | Set CHP Integ BW. Sets the integration bandwidth used by the channel power measurement in Hz. | Number |
| :SENSe:OBW:PERCent <Percent> | Set OBW Percent. Sets the percent of total power used to define occupied bandwidth (typically 99). | Number: 10-99 |
| :SENSe:CORRection:IMPedance:INPut:MAGNitude <Impedance> | Set Input Impedance. Sets the input impedance reference (50 or 75 ohms) for amplitude correction. | Text: OHM50,OHM75 |
| Command | What it does | Arguments |
|---|---|---|
| :CALCulate:MARKer<MkrNum>:STATe ON | Marker On. Turns on the specified marker. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:STATe OFF | Marker Off. Turns off the specified marker. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:X <Position> | Set Marker X. Sets the X-axis (frequency or time) position of the specified marker. | Number: 1-6; Number |
| :CALCulate:MARKer<MkrNum>:X? | Get Marker X. Queries the X-axis position (frequency/time) of the specified marker. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:Y? | Get Marker Y. Queries the Y-axis amplitude value at the specified marker. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:MAXimum | Marker Peak Search. Moves the specified marker to the highest peak on the trace. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:MAXimum:NEXT | Marker Peak Next. Moves the specified marker to the next-highest peak. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:MAXimum:LEFT | Marker Peak Left. Moves the specified marker to the next peak to the left. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:MAXimum:RIGHt | Marker Peak Right. Moves the specified marker to the next peak to the right. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:SET:CENTer | Marker To Center. Sets the center frequency to the marker's current frequency. | Number: 1-6 |
| :CALCulate:MARKer<MkrNum>:MODE <Mode> | Set Marker Mode. Sets the marker mode (normal position/delta/fixed/off). | Number: 1-6; Text: POSition,DELTa,OFF |
| :CALCulate:MARKer<MkrNum>:FUNCtion <Function> | Set Marker Function. Sets a marker function such as noise marker or band/interval power. | Number: 1-6; Text: FCOunt,NOISe,OFF |
| :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 |
| Command | What it does | Arguments |
|---|---|---|
| :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). | Text: DIV1,DIV2,DIV5,DIV10 |
| 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 |
|---|---|---|
| :INSTrument:SELect SA | Select 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,TGENerator,POWermeter |
| Command | What it does | Arguments |
|---|---|---|
| :TRIGger:SEQuence:SOURce <Source> | Set Trigger Source. Selects the sweep trigger source. | Text: IMMediate,VIDeo,EXTernal |
| :TRIGger:VIDeo:LEVel <Level> | Set Trigger Level. Sets the video trigger level in the current amplitude units. | Number |
| Command | What it does | Arguments |
|---|---|---|
| :MEASure:CHPower? | Read Channel Power. Initiates and reads the channel power and power-spectral-density result. | None |
| :MEASure:OBW? | Read OBW. Initiates and reads the occupied bandwidth result. | None |
| Command | What it does | Arguments |
|---|---|---|
| :UNIT:POWer <Units> | Set Y Units. Sets the amplitude (Y-axis) units for power readouts. | Text: DBM,DBMV,DBMVEMF,DBUV,DBUVEMF,V,W,VEMF |
| Command | What it does | Arguments |
|---|---|---|
| :TRACe:DATA? <TraceName> | Read Trace Data. Reads back the amplitude data points of the specified trace. | Text: TRACe1,TRACe2,TRACe3,TRACe4 |
| Command | What it does | Arguments |
|---|---|---|
| :FORMat:TRACe:DATA <Format> | Set Trace Format. Sets the numeric data format used when transferring trace data. | Text: ASCii,REAL |
| 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 N9342C and N9344C 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 N9342C accepts SCPI commands over its remote interfaces. TestFlow's instrument library holds 76 SCPI commands for it: 17 queries that read values or state, and 59 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 :MEASure:CHPower?.
:MEASure: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 N9342C 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.