Python instrument control means sending SCPI text commands to bench instruments through a VISA layer, usually with the PyVISA package. VISA opens the session over USB, LAN, GPIB, or serial, and SCPI is what you send once connected. PyVISA is free and MIT licensed, and the commands come from each instrument's own programming guide.
19 articles · Updated November 24, 2026
Everything needed to drive a bench instrument from Python: backends, resource strings, the query and write distinction, binary transfers, error checking, and the traps that waste a first afternoon.
The SCPI commands you actually use, organised by instrument class, with the universal commands, the syntax rules that trip people up, and where Keysight, Tektronix, and Rigol differ.
Five Python libraries for driving lab instruments, the same measurement written in each, and a clear answer on which to pick depending on whether you want a transport layer or a framework.
SCPI is what you say to an instrument, VISA is how the words get there, and PyVISA is the Python package that calls VISA for you. SCPI (Standard Commands for Programmable Instruments) is a text command language: *IDN? asks an instrument to identify itself, and MEASure:VOLTage:DC? asks a meter for a DC reading. VISA (Virtual Instrument Software Architecture) is a standard API that opens a connection over GPIB, USB, serial, or Ethernet without your code caring about the wiring. The VISA and SCPI explainer shows the whole stack in four lines of code.
PyVISA wraps a VISA backend, so one API drives a Keysight multimeter, a Tektronix oscilloscope, and a Rigol power supply on different cables. You need exactly one backend: NI-VISA, Keysight IO Libraries Suite, or pyvisa-py, a pure-Python backend installed with pip that needs no vendor installer but has limited GPIB support. The PyVISA tutorial walks through all three and how to tell which one a machine actually loaded.
A first script opens the instrument by its resource string, configures one measurement, and reads it back. This is the DMM example from the Python library comparison, unchanged:
import pyvisa
rm = pyvisa.ResourceManager()
dmm = rm.open_resource("USB0::0x2A8D::0x1301::MY57200001::INSTR")
dmm.write("CONF:VOLT:DC 10,0.0001")
voltage = float(dmm.query("READ?"))The resource string encodes the interface, the address, and the resource class. USB0::0x2A8D::0x1301::MY57200001::INSTR is a USB instrument carrying Keysight's vendor ID, and TCPIP0::192.168.1.42::inst0::INSTR is the LAN form. rm.list_resources() prints what VISA can see, though LAN instruments often do not appear and are simpler to address directly.
Two habits turn this into a script you can trust. Start every session with *RST then *CLS so leftover configuration cannot leak into the run, and wrap the session in try/finally so an exception never leaves a supply output enabled. The instrument guides apply the same pattern to a bench multimeter, a Keysight E36100 or E36300 supply, a Rigol DS1000Z scope, a Tektronix oscilloscope, and a three-instrument VI curve sweep.
SCPI is standardized at the top of the command tree and vendor-specific below it. The IEEE 488.2 common commands work on every compliant instrument, while measurement commands differ between vendors and sometimes between models. Use the programming guide for your exact model, and keep the SCPI command cheat sheet open for syntax.
| Command | What it does | Where it works |
|---|---|---|
*IDN? | Returns manufacturer, model, serial, and firmware | Every compliant instrument |
*RST then *CLS | Resets to defaults, clears status and the error queue | Every compliant instrument |
*OPC? | Blocks until pending operations complete | Every compliant instrument |
SYST:ERR? | Reads the next error from the queue | Every compliant instrument |
CONF:VOLT:DC 10,0.0001 then READ? | Configures once, then triggers and reads in a loop | Multimeters |
VOLT, CURR, OUTP ON | Sets voltage and current limit, enables the output | Power supplies |
INP ON | Enables the input (loads use INP, not OUTP) | Electronic loads |
:MEAS:VPP? CHAN1 vs MEASUREMENT:IMMED:TYPE PK2PK | Peak-to-peak voltage | Keysight InfiniiVision vs Tektronix |
Three syntax rules catch most people. The uppercase part of a keyword is the short form, so MEASure:VOLTage:DC? can be sent as MEAS:VOLT:DC?. A leading colon after a semicolon returns to the root, so VOLT 3.3;:CURR 0.5 works where VOLT 3.3;CURR 0.5 may fail. And a function generator assumes a 50 ohm load by default, so driving a high-impedance input gives exactly twice the amplitude you asked for until you send OUTP:LOAD INF.
The same commands sit underneath datasheet work. Reading a DMM datasheet turns accuracy specs into limits, function generator specifications lists what to validate on a source, and multimeter software compares logging options for the 34461A and 34465A.
For short SCPI commands the interface barely matters, because instrument response time dominates. A short round trip takes roughly 1 to 3 ms over GPIB or USB and 1 to 5 ms over LAN, while a DMM at NPLC 10 takes 200 ms to produce one reading. Interfaces only pull apart on large waveform transfers and remote access.
| Interface | Practical throughput | Use it when |
|---|---|---|
| LAN (LXI), gigabit | ~50 to 100 MB/s | Racked, shared, or remotely accessed instruments |
| USB 2.0 (USBTMC) | ~10 to 30 MB/s | One instrument on one engineer's desk |
| GPIB (IEEE 488.1) | ~1 MB/s | The instrument has nothing else |
| Serial (RS-232) | ~11 KB/s at 115200 baud | Older instruments with low data rates |
Reserve LAN addresses with a static IP or a DHCP reservation, or scripts break when an instrument moves. The GPIB vs USB vs LAN guide covers connection diagnosis for each interface.
Above the transport, PyVISA is plumbing and the other libraries are frameworks built on it. PyMeasure adds typed instrument classes, an experiment runner, and live plotting. QCoDeS targets research sweeps with a built-in database. InstrumentKit is units-aware through pint but AGPL licensed, and tm_devices is Tektronix's own package for Tektronix hardware only. For NI DAQ hardware, nidaqmx is NI's official Python package, covered in DAQ with Python. The whole zero-cost stack, including OpenTAP and Keysight Command Expert, is in free instrument control software.
Coming from LabVIEW, the LabVIEW vs Python comparison covers when each wins, and the migration guide maps VISA and DAQmx VIs to pyvisa and nidaqmx. FPGA and Real-Time targets stay in LabVIEW.
Most PyVISA failures are timeouts, and most timeouts come from a mismatch between what the script sent and what it then reads. Work through these in order.
?, use query. write("MEAS:VOLT?") leaves a response in the buffer, and every later read is off by one.query("VOLT 3.3") waits for a response that never arrives, which is a guaranteed timeout.read_termination and write_termination set, usually "\n". The symptom is a hang on the first query.*OPC? after slow operations instead of guessing at a delay.rm.visalib. The two machines usually resolved different VISA backends.Every library on this page still needs someone who knows which SCPI commands a given model needs, in which order. TestFlow builds AI agents for electronics testing: describe the test, and the agent builds the workflow, generates the Python and SCPI, drives the instruments, and writes the report from the run's own results. The generated code exports as a standalone Python package you own, as the TestFlow vs PyVISA comparison shows. Bench runs go through the Windows desktop app, and the web app can build and simulate. Its DAQ coverage is limited to a few NI devices, so for most DAQ cards nidaqmx stays the answer. Check supported instruments and pricing.
Decide what to build on before writing the first line of instrument code.
Connect, address, and drive your first instruments from Python.
Multi-instrument scripts, and the cases where SCPI is not the whole story.
Turn instrument specifications into limits, plans, and logged runs.
The definitions and syntax every other page on this hub assumes.
Every command TestFlow's agent uses to drive each instrument, from TestFlow's own instrument library, with arguments and a working PyVISA example.
By vendor: Aim-TTi, Chroma, GW Instek, ITECH, Keithley, Keysight, Rigol, Rohde & Schwarz, Siglent, Tektronix, Teledyne LeCroy, UNI-T
SCPI commands are text instructions, from Standard Commands for Programmable Instruments, that control test equipment. The SCPI Consortium released the first standard in 1990 as a layer on top of IEEE 488.2. Common commands such as *IDN?, *RST, and *CLS work on every compliant instrument, while measurement subsystems differ between vendors and models, so the programming guide for your exact model is the reference that counts.
VISA is the connection layer and SCPI is the command language. VISA (Virtual Instrument Software Architecture) is a standard API that opens a session to an instrument over GPIB, USB, LAN, or serial. SCPI is the text you send through that session, such as MEAS:VOLT:DC?. You need both: VISA without SCPI has nothing to say, and SCPI without VISA has no way to reach the instrument.
PyVISA is an open-source Python package, MIT licensed, that controls measurement instruments over USB, LAN, GPIB, and serial using the VISA standard. It gives you one Python interface regardless of the physical connection, with write for commands, query for anything ending in a question mark, and helpers for binary waveform transfers. It needs a VISA backend underneath: NI-VISA, Keysight IO Libraries Suite, or pyvisa-py.
PyVISA is the API your code calls. pyvisa-py is one of the backends it can run on, written in pure Python and installed with pip, so it needs no vendor installer. It is the easiest start on a LAN bench. Its GPIB support is limited, so a GPIB bench, or a USB instrument that will not enumerate, usually needs NI-VISA or Keysight IO Libraries Suite instead.
Use the programming guide for that exact model, which vendors publish as PDFs, not a generic SCPI reference. Firmware and options differ even within one series, so check *IDN? and *OPT? first. Send each new command on its own and read SYST:ERR? straight after it: an Undefined header error (-113) means the command does not exist on that model. Keysight Command Expert, a free tool, also browses an instrument's command set.
Yes. PyVISA with a free VISA backend drives any SCPI instrument at no license cost, and NI-VISA and Keysight IO Libraries Suite are free downloads. Keysight Command Expert is free for finding and testing SCPI commands, and OpenTAP and pytest are free for sequencing. What free does not cover is build time: you still write the instrument classes, the sequencing, and the reports yourself.
Describe the test. TestFlow builds the workflow, runs it on your instruments, and writes the report. See it on a bench like yours.