The Tektronix AFG31022 and AFG31252 function generator is controlled remotely with SCPI commands. TestFlow's instrument library holds 95 commands for it, 12 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 AFG31022 on a real bench.
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 Tektronix AFG31022's VISA address
# Paste the address of your Tektronix AFG31022 (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("SOURce:ROSCillator:SOURce INTernal") # Set Clock Internal
print(inst.query("SYSTem:ERRor?")) # Read Error
inst.close()Describe the test in a sentence, for example “set clock internal on the AFG31022, then read error 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.
95 commands in 9 groups. A ? marks a query that returns a value. Placeholders in angle brackets take the listed values. The AFG31022 and AFG31252 share this command set in TestFlow's library.
| Command | What it does | Arguments |
|---|---|---|
| SOURce<Channel>:FUNCtion:SHAPe <Shape> | Set Function. Sets the output waveform shape for the selected channel. | Number: 1,2; Text: SINusoid,SQUare,PULSe,RAMP,PRNoise,DC,SINC,GAUSsian,LORentz,ERISe,EDECay,HAVersine,EMEMory,EFILe |
| SOURce<Channel>:FUNCtion:SHAPe? | Read Function. Reads the output waveform shape for the selected channel. | Number: 1,2 |
| SOURce<Channel>:FREQuency:FIXed <Freq> | Set Frequency. Sets the output frequency in Hz for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FREQuency:FIXed? | Read Frequency. Reads the output frequency for the selected channel. | Number: 1,2 |
| SOURce<Channel>:FREQuency:MODE CW | Set Frequency Mode CW. Sets the selected channel frequency mode to continuous wave. | Number: 1,2 |
| SOURce<Channel>:FREQuency:MODE SWEep | Set Frequency Mode Sweep. Sets the selected channel frequency mode to sweep. | Number: 1,2 |
| SOURce<Channel>:FREQuency:STARt <Freq> | Set Frequency Start. Sets the sweep start frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FREQuency:STOP <Freq> | Set Frequency Stop. Sets the sweep stop frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FREQuency:CENTer <Freq> | Set Frequency Center. Sets the sweep center frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FREQuency:SPAN <Freq> | Set Frequency Span. Sets the sweep frequency span for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PHASe:ADJust <Deg> | Set Phase. Sets the phase in degrees for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PHASe:ADJust? | Read Phase. Reads the phase for the selected channel. | Number: 1,2 |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:AMPLitude <Amp> | Set Amplitude. Sets the output amplitude for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:AMPLitude? | Read Amplitude. Reads the output amplitude for the selected channel. | Number: 1,2 |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:HIGH <Volt> | Set Voltage High. Sets the high voltage level for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:LOW <Volt> | Set Voltage Low. Sets the low voltage level for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:OFFSet <Volt> | Set Voltage Offset. Sets the DC offset voltage for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:VOLTage:LEVel:IMMediate:OFFSet? | Read Voltage Offset. Reads the DC offset voltage for the selected channel. | Number: 1,2 |
| SOURce<Channel>:VOLTage:UNIT <Unit> | Set Voltage Unit. Sets the amplitude unit for the selected channel. | Number: 1,2; Text: VPP,VRMS,DBM |
| SOURce<Channel>:VOLTage:LIMit:HIGH <Volt> | Set Voltage Limit High. Sets the high output-voltage limit for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:VOLTage:LIMit:LOW <Volt> | Set Voltage Limit Low. Sets the low output-voltage limit for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:WIDTh <Sec> | Set Pulse Width. Sets the pulse width in seconds for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:DCYCle <Pct> | Set Pulse Duty Cycle. Sets the pulse duty cycle percentage for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:PERiod <Sec> | Set Pulse Period. Sets the pulse period in seconds for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:TRANsition:LEADing <Sec> | Set Pulse Lead Edge. Sets the pulse leading-edge time for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:TRANsition:TRAiling <Sec> | Set Pulse Trail Edge. Sets the pulse trailing-edge time for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PULSe:DELay <Sec> | Set Pulse Delay. Sets the pulse delay for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FUNCtion:RAMP:SYMMetry <Pct> | Set Ramp Symmetry. Sets the ramp symmetry percentage for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:AM:STATe ON | Enable AM. Enables AM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:AM:STATe OFF | Disable AM. Disables AM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:AM:DEPTh <Pct> | Set AM Deviation. Sets the AM depth percentage for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:AM:SOURce <Src> | Set AM Source. Sets the AM modulation source for the selected channel. | Number: 1,2; Text: INTernal,EXTernal |
| SOURce<Channel>:AM:INTernal:FREQuency <Freq> | Set AM Int Freq. Sets the internal AM modulating frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:AM:INTernal:FUNCtion <Shape> | Set AM Int Function. Sets the internal AM modulating waveform for the selected channel. | Number: 1,2; Text: SINusoid,SQUare,TRIangle,RAMP,NRAMp,PRNoise |
| SOURce<Channel>:FM:STATe ON | Enable FM. Enables FM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:FM:STATe OFF | Disable FM. Disables FM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:FM:DEViation <Freq> | Set FM Deviation. Sets the FM frequency deviation in Hz for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FM:SOURce <Src> | Set FM Source. Sets the FM modulation source for the selected channel. | Number: 1,2; Text: INTernal,EXTernal |
| SOURce<Channel>:FM:INTernal:FREQuency <Freq> | Set FM Int Freq. Sets the internal FM modulating frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FM:INTernal:FUNCtion <Shape> | Set FM Int Function. Sets the internal FM modulating waveform for the selected channel. | Number: 1,2; Text: SINusoid,SQUare,TRIangle,RAMP,NRAMp,PRNoise |
| SOURce<Channel>:PM:STATe ON | Enable PM. Enables PM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:PM:STATe OFF | Disable PM. Disables PM modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:PM:DEViation <Deg> | Set PM Deviation. Sets the PM phase deviation in degrees for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PM:SOURce <Src> | Set PM Source. Sets the PM modulation source for the selected channel. | Number: 1,2; Text: INTernal,EXTernal |
| SOURce<Channel>:PM:INTernal:FREQuency <Freq> | Set PM Int Freq. Sets the internal PM modulating frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PM:INTernal:FUNCtion <Shape> | Set PM Int Function. Sets the internal PM modulating waveform for the selected channel. | Number: 1,2; Text: SINusoid,SQUare,TRIangle,RAMP,NRAMp,PRNoise |
| SOURce<Channel>:FSKey:STATe ON | Enable FSK. Enables FSK modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:FSKey:STATe OFF | Disable FSK. Disables FSK modulation on the selected channel. | Number: 1,2 |
| SOURce<Channel>:FSKey:FREQuency <Freq> | Set FSK Hop Freq. Sets the FSK hop frequency for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FSKey:INTernal:RATE <Rate> | Set FSK Rate. Sets the FSK internal rate for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:FSKey:SOURce <Src> | Set FSK Source. Sets the FSK source for the selected channel. | Number: 1,2; Text: INTernal,EXTernal |
| SOURce<Channel>:PWM:STATe ON | Enable PWM. Enables PWM on the selected channel. | Number: 1,2 |
| SOURce<Channel>:PWM:STATe OFF | Disable PWM. Disables PWM on the selected channel. | Number: 1,2 |
| SOURce<Channel>:PWM:DEViation:DCYCle <Pct> | Set PWM Deviation. Sets the PWM duty-cycle deviation for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:PWM:SOURce <Src> | Set PWM Source. Sets the PWM source for the selected channel. | Number: 1,2; Text: INTernal,EXTernal |
| SOURce<Channel>:SWEep:TIME <Sec> | Set Sweep Time. Sets the sweep time for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:SWEep:HTIMe <Sec> | Set Sweep Hold Time. Sets the sweep hold time for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:SWEep:RTIMe <Sec> | Set Sweep Return Time. Sets the sweep return time for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:SWEep:SPACing <Type> | Set Sweep Spacing. Sets the sweep spacing for the selected channel. | Number: 1,2; Text: LINear,LOGarithmic |
| SOURce<Channel>:SWEep:MODE <Mode> | Set Sweep Mode. Sets the sweep mode (auto/manual) for the selected channel. | Number: 1,2; Text: AUTO,MANual |
| SOURce<Channel>:BURSt:STATe ON | Enable Burst. Enables burst mode on the selected channel. | Number: 1,2 |
| SOURce<Channel>:BURSt:STATe OFF | Disable Burst. Disables burst mode on the selected channel. | Number: 1,2 |
| SOURce<Channel>:BURSt:MODE <Mode> | Set Burst Mode. Sets the burst mode for the selected channel. | Number: 1,2; Text: TRIGgered,GATed |
| SOURce<Channel>:BURSt:NCYCles <N> | Set Burst Cycles. Sets the number of cycles per burst for the selected channel. | Number: 1,2; Number |
| SOURce<Channel>:BURSt:TDELay <Sec> | Set Burst Delay. Sets the burst delay for the selected channel. | Number: 1,2; Number |
| SOURce:ROSCillator:SOURce INTernal | Set Clock Internal. Uses the internal reference clock. | None |
| SOURce:ROSCillator:SOURce EXTernal | Set Clock External. Uses the external reference clock. | None |
| Command | What it does | Arguments |
|---|---|---|
| OUTPut<Channel>:STATe ON | Turn On Output. Enables the selected channel output. | Number: 1,2 |
| OUTPut<Channel>:STATe OFF | Turn Off Output. Disables the selected channel output. | Number: 1,2 |
| OUTPut<Channel>:STATe? | Read Output State. Reads whether the selected channel output is on. | Number: 1,2 |
| OUTPut<Channel>:IMPedance <Ohm> | Set Output Impedance. Sets the the selected channel output load impedance in ohms (1 to 10k). | Number: 1,2; Number |
| OUTPut<Channel>:IMPedance? | Read Output Impedance. Reads the the selected channel output load impedance. | Number: 1,2 |
| OUTPut<Channel>:POLarity NORMal | Set Output Polarity Normal. Sets the selected channel output polarity to normal. | Number: 1,2 |
| OUTPut<Channel>:POLarity INVerted | Set Output Polarity Inverted. Sets the selected channel output polarity to inverted. | Number: 1,2 |
| Command | What it does | Arguments |
|---|---|---|
| TRIGger:SEQuence:SOURce <Src> | Set Trigger Source. Sets the trigger source. | Text: TIMer,EXTernal |
| TRIGger:SEQuence:SLOPe <Slope> | Set Trigger Slope. Sets the external trigger slope. | Text: POSitive,NEGative |
| TRIGger:SEQuence:TIMer <Sec> | Set Trigger Timer. Sets the internal trigger timer period. | Number |
| TRIGger:SEQuence:IMMediate | Trigger Now. Issues an immediate (manual) trigger. | None |
| Command | What it does | Arguments |
|---|---|---|
| SYSTem:ERRor? | Read Error. Reads and clears the next error-queue entry. | None |
| SYSTem:BEEPer:STATe ON | Enable Beeper. Enables the beeper. | None |
| SYSTem:BEEPer:STATe OFF | Disable Beeper. Disables the beeper. | None |
| Command | What it does | Arguments |
|---|---|---|
| DISPlay:BRIGhtness <Level> | Enable Display. Sets the display brightness (0 to 1). | Number |
| 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. | None |
| *OPC? | Operation Complete. Returns 1 when all pending operations are complete. | None |
| *WAI | Wait To Continue. Waits until all pending operations are complete. | None |
| *TRG | Trigger Bus. Generates a bus trigger. | None |
| *SAV <Slot> | Save State Slot. Stores the current state to a setup memory slot (0 to 4). | Number |
| *RCL <Slot> | Recall State Slot. Recalls a state from a setup memory slot (0 to 4). | Number |
| *OPT? | Read Options. Queries the installed options. | None |
This reference is generated from TestFlow's instrument library, which is drafted from Tektronix's programming documentation for the AFG31022 and AFG31252 and checked when the agent runs it. Ranges, timing, and option-dependent commands are defined by Tektronix's programming manual: check it before you rely on an edge case. Last updated November 17, 2026.
Yes. The Tektronix AFG31022 accepts SCPI commands over its remote interfaces. TestFlow's instrument library holds 95 SCPI commands for it: 12 queries that read values or state, and 83 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?, SOURce:ROSCillator:SOURce INTernal and SYSTem:ERRor?.
SYSTem:ERRor? (read error). Reads and clears the next error-queue entry. 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 Tektronix AFG31022 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.