Repository navigation
Getting started
From nothing to a script talking to a simulated power supply, in five steps.
pip install scpi-sim # Python 3.10 or newer
pip install pyvisa pyvisa-py # for the PyVISA examples belowOr 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).
$ 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.
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.
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 limitA SOCKET resource needs read_termination and write_termination; without
them PyVISA waits for an end that never comes (see Troubleshooting).
Your code is written for a specific instrument? Start its profile instead:
$ scpi-sim profiles
$ scpi-sim serve --profile rs-hmp4040 --load 24Now *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.
- Several instruments wired together: a bench file
(README: Bench), e.g.
scpi-sim serve --bench examples/profiles/bench.yaml— the bench of the Browser demo. - Your script opens
TCPIP::host::INSTRorhislip0? → VXI-11 and HiSLIP - Tests with pytest and in a pipeline → Testing in CI
- Make instruments fail on purpose → Fault injection recipes
scpi-sim · MIT licensed · instrument names are trademarks of their owners; scpi-sim is not affiliated with them.