The following example shows how to use SCPI commands with a Keithley 2000 multimeter in order to measure 10 voltages. After having read them, the program calculates the average voltage and prints it on the screen.
I'll explain the program step-by-step. First, we have to initialise the instrument:
from visa import instrument
keithley = instrument("GPIB::12")
keithley.write("*rst; status:preset; *cls")
The next step is to write all the measurement parameters, in particular the interval time (500ms) and the number of readings (10) to the instrument. I won't explain it in detail. Have a look at an SCPI and/or Keithley 2000 manual.
interval_in_ms = 500
number_of_readings = 10
keithley.write("status:measurement:enable 512; *sre 1")
keithley.write("sample:count %d" % number_of_readings)
keithley.write("trigger:source bus")
keithley.write("trigger:delay %f" % (interval_in_ms / 1000.0))
keithley.write("trace:points %d" % number_of_readings)
keithley.write("trace:feed sense1; feed:control next")
keithley.write("initiate")
keithley.trigger()
keithley.wait_for_srq()
NDCV-000.0004E+0,NDCV-000.0005E+0,NDCV-000.0004E+0,NDCV-000.0007E+0, NDCV-000.0000E+0,NDCV-000.0007E+0,NDCV-000.0008E+0,NDCV-000.0004E+0, NDCV-000.0002E+0,NDCV-000.0005E+0
ask_for_values() method does this work for us:
voltages = keithley.ask_for_values("trace:data?")
print "Average voltage: ", sum(voltages) / len(voltages)
keithley.ask("status:measurement?")
keithley.write("trace:clear; feed:control next")