stoner_measurement.instruments.keithley.k6221.Keithley6221

class stoner_measurement.instruments.keithley.k6221.Keithley6221(transport: BaseTransport, protocol: BaseProtocol | None = None)[source]

Bases: CurrentSource

Driver for the Keithley 6221 precision AC/DC current source.

Provides DC source-level and compliance control plus AC waveform controls (waveform shape, frequency, and offset current) using SCPI commands. Built-in staircase sweeps (linear, logarithmic, custom list) and pulsed sweeps are also supported.

clear_sweep_complete_event() → None[source]

Clear a sweep event latched by an earlier acquisition.

configure_arm(source: str = 'IMM', bypass: bool = False, time: float = 0, direction: str = 'ACC', tlink_in: int | None = None, tlink_out: int | None = None, output: str = 'None')[source]

Configure the 6221 arm layer.

Keyword Arguments:
  • source (str, "IMM") – The ARM layer input sources, IMM, TIM, BUS, TLIN, NST, PST, MAN

  • bypass (bool, False) – Whetgher to bypass the ARM system altogether.

  • time (float, 0) – Timer to use when ARM source is TIM

  • direction (str, "ACC") – Even when not bypassing, it is possible to skip the first ARM source event by setting this to “SOUR”

  • tlink_out (tlink_in,) – Triggerlink lines to use when the source is “TLIN”

  • output (str, "NONE") – Whether to indicate a transition to (“TENT”) or from (“TEX”) the trigger layer, or not al at all (“NONE”).

configure_list_compliance(values: list[float]) → None[source]

Configure per-point compliance voltages for a LIST sweep.

Sends the compliance voltage list to the instrument in batches of _LIST_BATCH_SIZE (100) points, using SOUR:LIST:COMP:APP to append batches beyond the first.

Parameters:

values (list[float]) – Per-point compliance voltages in volts. Must not be empty.

Raises:

ValueError – If values is empty.

Examples

>>> from stoner_measurement.instruments.keithley.k6221 import Keithley6221
>>> # k.configure_list_compliance([10.0, 10.0, 10.0])  # per-point compliance
configure_pulse_delta_sweep(values: tuple[float, ...], *, width: float, source_delay: float, period: float, low_measurements: int = 2) → None[source]

Programme a native zero-baseline Pulse Delta custom sweep.

Requires a 2182A connected by RS-232 and Trigger Link. Does not arm or start output. See reference manual sections 5-37 to 5-50.

Parameters:

values (tuple[float, ...]) – High pulse currents in amps.

Keyword Parameters:
  • width (float) – Pulse width in seconds.

  • source_delay (float) – Settling delay within each pulse in seconds.

  • period (float) – Requested complete cycle period in seconds.

  • low_measurements (int) – Number of baseline measurements, 1 or 2.

Raises:

ValueError – If the current list or pulse timing is invalid.

configure_pulsed_sweep(sweep: CurrentSweepConfiguration, pulse: PulsedSweepConfiguration) → None[source]

Configure a pulsed current sweep.

Calls configure_sweep() to programme the sweep points, then enables pulsed mode and sets pulse timing parameters.

Parameters:
Raises:

ValueError – If pulse.width or pulse.off_time is not positive.

configure_sweep(config: CurrentSweepConfiguration) → None[source]

Configure a built-in current sweep.

For LIST spacing the values list is written to the instrument in batches of _LIST_BATCH_SIZE (100) points using the SOUR:LIST:CURR:APP append command so that sweeps longer than 100 points are handled transparently.

Parameters:

config (CurrentSweepConfiguration) – Sweep configuration. For LIST spacing, config.values must be non-empty.

Raises:

ValueError – If config.spacing is LIST and config.values is empty or None.

Examples

>>> from stoner_measurement.instruments.keithley.k6221 import Keithley6221, _LIST_BATCH_SIZE
>>> from stoner_measurement.instruments.current_source import (
...     CurrentSweepConfiguration, CurrentSweepSpacing)
>>> from stoner_measurement.instruments.transport.base import BaseTransport
configure_sweep_complete_srq() → None[source]

Route the sweep-finished operating event to the SRQ line.

configure_trigger(source: str = 'IMM', bypass: bool = False, direction: str = 'ACC', tlink_in: int | None = None, tlink_out: int | None = None, output: str = 'None')[source]

Configure the trigger layer.

Keyword Arguments:
  • source (str, "IMM") – The Trigger layer input sources, IMM, TLIN

  • bypass (bool, False) – Whetgher to bypass the Trigger system altogether.

  • direction (str, "ACC") – Even when not bypassing, it is possible to skip the first Trigger source event by setting this to “SOUR”

  • tlink_out (tlink_in,) – Triggerlink lines to use when the source is “TLIN”

  • output (str, "NONE") – When the output trigger is sent - after source (“SOUR”), after delay (“DEL”), or not (“NONE”)

Configure trigger-link lines and trigger direction.

The 6221 raises a settings-conflict error if the requested line is already allocated to one of the other two trigger-link purposes (input line, output line, or waveform phase-marker output line). This method avoids those conflicts by:

  1. Reading the current output-line, input-line, and phase-marker output-line assignments.

  2. Moving any conflicting assignment to a temporary free line before writing each of the two new assignments.

  3. Writing the new output and input lines in a safe order.

Parameters:
  • output_line (int) – Trigger-link output line on the 6221 (valid range: 1..6).

  • input_line (int) – Trigger-link input line on the 6221 (valid range: 1..6).

Raises:

ValueError – If either line number is outside 1..6 or if output_line == input_line.

connect() → None[source]

Open the transport connection to the instrument.

After opening the transport, any data accumulated in the transport buffer since the last session is discarded via flush() so that stale responses from previous commands cannot be misread as replies to new queries.

Raises:

ConnectionError – If the underlying transport cannot be opened.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import ScpiProtocol
>>> from stoner_measurement.instruments.base_instrument import BaseInstrument
>>> instr = BaseInstrument(NullTransport(), ScpiProtocol())
>>> instr.connect()
>>> instr.is_connected
True
>>> instr.disconnect()
enable_output(state: bool) → None[source]

Enable or disable source output.

enable_phase_marker(state: bool) → None[source]

Enable or disable the waveform phase-marker output.

get_capabilities() → CurrentSourceCapabilities[source]

Return static capabilities for Keithley 6221.

get_compliance_voltage() → float[source]

Return compliance voltage in volts.

get_frequency() → float[source]

Return AC waveform frequency in Hz.

get_offset_current() → float[source]

Return AC waveform DC offset current in amps.

get_operating_status() → int[source]

Return the current operating-status condition register.

get_phase_marker_output_line() → int[source]

Return the configured phase-marker trigger-link output line.

get_source_level() → float[source]

Return programmed source current in amps.

get_waveform() → CurrentWaveform[source]

Return waveform mode.

get_waveform_amplitude() → float[source]

Return AC waveform amplitude in amps.

output_enabled() → bool[source]

Return True if source output is enabled.

phase_marker_enabled() → bool[source]

Return True if the waveform phase marker is enabled.

prepare_pulse_delta_buffer(count: int) → None[source]

Clear and enable the 6221 buffer for one complete pulse sweep.

Parameters:

count (int) – Number of corrected voltages to store, 1 to 65536.

Raises:

ValueError – If the requested buffer size is invalid.

pulse_delta_arm() → None[source]

Arm Pulse Delta, allowing time for the internal sweep table build.

Raises:

RuntimeError – If the instrument does not confirm the armed state.

pulse_delta_buffer_count() → int[source]

Return the number of corrected readings committed to the 6221 buffer.

pulse_delta_present() → bool[source]

Return whether a compatible 2182A is connected over RS-232.

query_serial_command(cmd: str, *, command_terminator: str = '\r\n', response_terminator: str = '\n', max_chunks: int = 64) → str[source]

Relay a serial query and return the line response.

Parameters:

cmd (str) – Query command to send to the downstream serial instrument.

Keyword Parameters:
  • command_terminator (str) – Terminator appended to cmd before relay transmission.

  • response_terminator (str) – Line terminator that marks completion of the response.

  • max_chunks (int) – Maximum number of relay chunks to read while waiting for the terminator.

Returns:

Response string with trailing CR/LF stripped.

Return type:

(str)

Raises:
  • ValueError – If max_chunks is not positive.

  • RuntimeError – If a line-terminated response is not received within max_chunks chunks.

Notes

This will terminate after if recieves a blank chunk after it recieves a non-blank chunk.

read_pulse_delta_buffer(count: int) → tuple[float, ...][source]

Read corrected voltages, rejecting incomplete or malformed buffers.

Parameters:

count (int) – Expected number of readings.

Returns:

Corrected pulse voltages in volts.

Return type:

(tuple[float, …])

Raises:

ValueError – If the buffer response is malformed or incomplete.

reset() → None[source]

Send the standard IEEE 488.2 reset command (*RST).

Instruments that do not support *RST should override this method.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import ScpiProtocol
>>> from stoner_measurement.instruments.base_instrument import BaseInstrument
>>> t = NullTransport()
>>> instr = BaseInstrument(t, ScpiProtocol())
>>> instr.connect()
>>> instr.reset()
>>> t.write_log
[b'*RST\n']
>>> instr.disconnect()
send_serial_command(cmd: str, *, terminator: str = '\r\n') → None[source]

Relay a serial command through the 6221.

Parameters:

cmd (str) – Command to send to the downstream serial instrument.

Keyword Parameters:

terminator (str) – Serial command terminator appended once to cmd.

set_compliance_voltage(value: float) → None[source]

Set compliance voltage in volts.

set_fixed_range(value: float) → None[source]

Set a fixed source-current range.

Parameters:

value (float) – Fixed current range in amps.

Raises:

ValueError – If value is not positive.

set_frequency(value: float) → None[source]

Set AC waveform frequency in Hz.

set_offset_current(value: float) → None[source]

Set AC waveform DC offset current in amps.

set_phase_marker_output_line(output_line: int) → None[source]

Set the phase-marker trigger-link output line.

set_pulse_delta_voltage_range(value: float) → None[source]

Set the 2182A range through serial; zero selects autorange.

Parameters:

value (float) – Voltage range in volts, or zero for autorange.

Raises:

ValueError – If the voltage range is invalid.

set_source_level(value: float) → None[source]

Set source current in amps.

set_sweep_count(count: int) → None[source]

Set sweep repeat count.

Parameters:

count (int) – Number of sweep repetitions.

Raises:

ValueError – If count is not positive.

set_sweep_range_mode(mode: str) → None[source]

Set sweep range mode.

Parameters:

mode (str) – Sweep range mode token. Supported values are "AUTO" and "BEST" (case-insensitive).

Raises:

ValueError – If mode is not "AUTO" or "BEST".

set_waveform(waveform: CurrentWaveform) → None[source]

Set waveform mode.

set_waveform_amplitude(value: float) → None[source]

Set AC waveform amplitude in amps.

state() → _K6221_STATE[source]

Determine the state of the 6221 through status queries.

sweep_abort() → None[source]

Abort a running or armed sweep.

sweep_arm() → None[source]

Arm the configured sweep.

sweep_init() → None[source]

Manually trigger the arm layer for a sweep.

sweep_is_finished() → bool[source]

Return True when the operating-status register reports sweep completion.

sweep_is_running() → bool[source]

Return True while the instrument reports an active sweep.

sweep_start() → None[source]

Arm the configured sweep, making it ready for triggering.

static validate_pulse_delta_sweep(values: tuple[float, ...], *, width: float, source_delay: float, period: float, low_measurements: int) → None[source]

Validate native Pulse Delta settings before any instrument writes.

Parameters:

values (tuple[float, ...]) – High pulse currents in amps.

Keyword Parameters:
  • width (float) – Pulse width, 50 microseconds to 12 milliseconds.

  • source_delay (float) – Settling time within a pulse, in seconds.

  • period (float) – Requested cycle period in seconds.

  • low_measurements (int) – One or two baseline measurements.

Raises:

ValueError – If a list or timing setting is outside its limits.

wait_for_sweep_complete_srq(timeout: float, poll_interval: float = 0.01) → bool[source]

Wait for sweep SRQ, using a transport-native operation if available.

wave_abort() → None[source]

Abort a runnign waveform.

wave_start() → None[source]

Arm the wave outpit.