Skip to content

Getting started

Ralf Steinert edited this page Nov 9, 2026 · 5 revisions

From nothing to a script talking to a simulated power supply, in five steps.

1. Install

pip install scpi-sim                 # Python 3.10 or newer
pip install pyvisa pyvisa-py         # for the PyVISA examples below

Or without Python on the machine: docker run --rm -p 5025-5027:5025-5027 ghcr.io/steitec/scpi-sim starts the example bench (see Testing in CI).

2. Start an instrument

$ scpi-sim serve psu --load 24
scpi-sim: PSU listening on 127.0.0.1:5025 (Ctrl+C to stop)

A generic power supply on port 5025, the port real LAN instruments use for raw SCPI, with a 24 Ω load on its output. It keeps running until Ctrl+C.

3. Talk to it

In a second terminal, with the client that comes with scpi-sim:

$ scpi-sim query "*IDN?" "VOLT 12;CURR 1;:OUTP ON" "MEAS:CURR?" "VOLT 40" "SYST:ERR?"
scpi-sim,PSU,SIM00002,0.7.3
+5.00000000E-01
-222,"Data out of range"

query sends each message and prints the answer to every message that contains a ?. 12 V into 24 Ω gives 0.5 A; 40 V is above the supply's 30 V, so it lands in the error queue — exactly where a real instrument would put it.

4. From Python

import pyvisa

rm = pyvisa.ResourceManager("@py")
psu = rm.open_resource("TCPIP0::127.0.0.1::5025::SOCKET",
                       read_termination="\n", write_termination="\n")
psu.write("VOLT 12;CURR 1;:OUTP ON")
print(psu.query("MEAS:CURR?"))                  # +5.00000000E-01
psu.write("CURR 0.25")                          # the load wants 0.5 A ...
print(psu.query("MEAS:VOLT?;:OUTP:MODE?"))      # +6.00000000E+00;CC  ... so: current limit

A SOCKET resource needs read_termination and write_termination; without them PyVISA waits for an end that never comes (see Troubleshooting).

5. Make it a real model

Your code is written for a specific instrument? Start its profile instead:

$ scpi-sim profiles
$ scpi-sim serve --profile rs-hmp4040 --load 24

Now *IDN? answers Rohde&Schwarz,HMP4040,..., the HMP dialect works (INST OUT1, APPL 12,1, OUTP:SEL ON, OUTP:GEN ON), and readings come back as 0.500 instead of +5.00000000E-01. The profile table lists all ten models and what each covers.

Next steps

Clone this wiki locally