stoner_measurement.instruments.keithley.k6221.Keithley6221¶
- class stoner_measurement.instruments.keithley.k6221.Keithley6221(transport: BaseTransport, protocol: BaseProtocol | None = None)[source]¶
Bases:
CurrentSourceDriver 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.
- 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, usingSOUR:LIST:COMP:APPto 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:
- 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:
sweep (CurrentSweepConfiguration) – Sweep point configuration.
pulse (PulsedSweepConfiguration) – Pulse timing and baseline current.
pulse.widthandpulse.off_timemust both be positive.
- Raises:
ValueError – If
pulse.widthorpulse.off_timeis not positive.
- configure_sweep(config: CurrentSweepConfiguration) None[source]¶
Configure a built-in current sweep.
For
LISTspacing the values list is written to the instrument in batches of_LIST_BATCH_SIZE(100) points using theSOUR:LIST:CURR:APPappend command so that sweeps longer than 100 points are handled transparently.- Parameters:
config (CurrentSweepConfiguration) – Sweep configuration. For
LISTspacing,config.valuesmust be non-empty.- Raises:
ValueError – If
config.spacingisLISTandconfig.valuesis empty orNone.
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(output_line: int, input_line: int) None[source]¶
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:
Reading the current output-line, input-line, and phase-marker output-line assignments.
Moving any conflicting assignment to a temporary free line before writing each of the two new assignments.
Writing the new output and input lines in a safe order.
- Parameters:
- Raises:
ValueError – If either line number is outside
1..6or ifoutput_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()
- get_capabilities() CurrentSourceCapabilities[source]¶
Return static capabilities for Keithley 6221.
- get_phase_marker_output_line() int[source]¶
Return the configured phase-marker trigger-link output line.
- get_waveform() CurrentWaveform[source]¶
Return waveform mode.
- 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.
- 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:
- 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
*RSTshould 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_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_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_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.
- sweep_is_finished() bool[source]¶
Return
Truewhen the operating-status register reports sweep completion.
- 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:
- 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.