pymeasure Tools
These 4 tools are only available when pymeasure is installed:
pip install mcpyvisa[pymeasure]They complement the raw SCPI tools documented in Universal Tools. Use the pymeasure tools when a driver exists for your instrument — they provide property validation, type conversion, and high-level methods that encode multi-step SCPI sequences. Fall back to instrument_query and instrument_write for instruments without a pymeasure driver, or for operations not covered by the driver.
Currently supported instruments: HP 33120A, HP 34401A, HP 3478A, HP 8657B, Agilent 4284A, Keithley 2000, Keithley 2400, Keithley 6517B.
Instruments are addressed by VISA resource string ("GPIB0::24::INSTR") or by a configured alias ("smu").
instrument_inspect
Section titled “instrument_inspect”Discover a pymeasure driver’s validated properties and methods for an instrument. This is the starting point — run it first to see what operations are available before calling instrument_get, instrument_set, or instrument_call.
If no pymeasure driver is found for the instrument, returns a message suggesting raw SCPI access instead.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Yes | VISA resource string or configured alias |
Example
result = await client.call_tool("instrument_inspect", { "instrument": "smu"})Returns
For an instrument with a matching driver (e.g., a Keithley 2400):
pymeasure driver: keithley-2400 (Keithley2400)Instrument: smu (GPIB0::24::INSTR)
Use instrument_get/instrument_set/instrument_call for validated access.
# Keithley2400
Represents the Keithley 2400 SourceMeter and provides a high-levelinterface for interacting with the instrument.
## Measurements (read-only -- triggers a measurement) - `current` (SCPI: :MEAS:CURR?) -- Reads the current in Amps - `resistance` (SCPI: :MEAS:RES?) -- Reads the resistance in Ohms - `voltage` (SCPI: :MEAS:VOLT?) -- Reads the voltage in Volts
## Controls (read + write -- get/set with validation) - `compliance_current` (SCPI: :SENS:CURR:PROT? / :SENS:CURR:PROT %g) -- Current compliance value in Amps Valid: [0, 1.05] Validator: truncated_range - `compliance_voltage` (SCPI: :SENS:VOLT:PROT? / :SENS:VOLT:PROT %g) -- Voltage compliance value in Volts Valid: [0, 210] Validator: truncated_range - `source_current` (SCPI: :SOUR:CURR? / :SOUR:CURR:LEV %g) -- Source current in Amps Valid: [-1.05, 1.05] Validator: truncated_range - `source_mode` (SCPI: :SOUR:FUNC:MODE? / :SOUR:FUNC:MODE %s) -- Source mode Valid: ['current', 'voltage'] Validator: strict_discrete_set - `source_voltage` (SCPI: :SOUR:VOLT? / :SOUR:VOLT:LEV %g) -- Source voltage in Volts Valid: [-210, 210] Validator: truncated_range
## Methods (high-level operations) - `apply_current(current_range, compliance_voltage)` -- Configure and apply a source current - `apply_voltage(voltage_range, compliance_current)` -- Configure and apply a source voltage - `enable_source()` -- Enable the source output - `disable_source()` -- Disable the source output - `shutdown()` -- Safely shut down the instrument, disabling the source outputWhen no driver is found:
No pymeasure driver available for instrument GPIB0::7::INSTR.
Use instrument_query() and instrument_write() for raw SCPI access.
Supported instruments with pymeasure drivers: - hp-33120a: pymeasure.instruments.hp.HP33120A - hp-34401a: pymeasure.instruments.hp.HP34401A - hp-3478a: pymeasure.instruments.hp.HP3478A - hp-8657b: pymeasure.instruments.hp.HP8657B - agilent-4284a: pymeasure.instruments.agilent.Agilent4284A - keithley-2000: pymeasure.instruments.keithley.Keithley2000 - keithley-2400: pymeasure.instruments.keithley.Keithley2400 - keithley-6517b: pymeasure.instruments.keithley.Keithley6517Binstrument_get
Section titled “instrument_get”Read a property value from an instrument using its pymeasure driver. For measurement properties, this triggers an actual measurement on the instrument. For control properties, it queries the current setting. pymeasure handles response parsing, type conversion, and unit handling internally.
Run instrument_inspect first to see available properties.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Yes | VISA resource string or configured alias |
property | string | Yes | Name of the property to read (from instrument_inspect output) |
Example
# Read a measurement property (triggers a real voltage measurement)result = await client.call_tool("instrument_get", { "instrument": "smu", "property": "voltage"})
# Read a control property (queries the current source mode setting)result = await client.call_tool("instrument_get", { "instrument": "smu", "property": "source_mode"})Returns
For a measurement property:
voltage = 4.99823For a control property:
source_mode = 'voltage'instrument_set
Section titled “instrument_set”Set a control property on an instrument. The pymeasure driver validates the value before sending the SCPI command — out-of-range or invalid values are rejected without reaching the instrument, protecting expensive equipment from bad parameters.
Run instrument_inspect first to see available properties and their valid ranges.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Yes | VISA resource string or configured alias |
property | string | Yes | Name of the control property to set |
value | string | Yes | Value to set (automatically converted to the correct type) |
Example
# Set a numeric control propertyresult = await client.call_tool("instrument_set", { "instrument": "smu", "property": "source_voltage", "value": "5.0"})
# Set a discrete control propertyresult = await client.call_tool("instrument_set", { "instrument": "smu", "property": "source_mode", "value": "voltage"})Returns
Successful set:
Set source_voltage = 5.0Validation failure (value out of range):
Validation error for 'source_voltage' = '999': 999 is not in range [-210, 210]Validation failure (invalid discrete value):
Validation error for 'source_mode' = 'plasma': 'plasma' is not in the discrete set ['current', 'voltage']Attempting to set a read-only measurement property:
Property 'voltage' is read-only (measurement)instrument_call
Section titled “instrument_call”Call a high-level method on an instrument. Methods often encode multi-step SCPI sequences — for example, apply_voltage on a Keithley 2400 might configure source mode, voltage level, and compliance current in a single call.
Run instrument_inspect first to see available methods and their parameters.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Yes | VISA resource string or configured alias |
method | string | Yes | Name of the method to call (from instrument_inspect output) |
kwargs_json | string | No | JSON object of keyword arguments (default: "{}") |
Example
# Call a method with keyword argumentsresult = await client.call_tool("instrument_call", { "instrument": "smu", "method": "apply_voltage", "kwargs_json": '{"voltage_range": 5.0, "compliance_current": 0.1}'})
# Call a method with no argumentsresult = await client.call_tool("instrument_call", { "instrument": "smu", "method": "shutdown"})
# Call enable_source before taking measurementsresult = await client.call_tool("instrument_call", { "instrument": "smu", "method": "enable_source"})Returns
For a void method:
Called apply_voltage(voltage_range=5.0, compliance_current=0.1)For a method with no arguments:
Called shutdown()For a method that returns a value:
measure_current() returned: 0.04723