stoner_measurement.instruments.keithley.k2400.Keithley2400

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

Bases: KeithleyScpiDataFormatMixin, SourceMeter

Driver for the Keithley 2400 Series SourceMeter.

Implements SourceMeter using SCPI commands specific to the Keithley 2400 instrument family. A ScpiProtocol instance is used by default; the transport must be supplied by the caller.

Variables:
  • transport (BaseTransport) – Transport layer (serial, GPIB, or Ethernet).

  • protocol (BaseProtocol) – Protocol instance (defaults to ScpiProtocol).

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import ScpiProtocol
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[
...     b"KEITHLEY INSTRUMENTS INC.,MODEL 2400,1234567,C32 Mar  4 2011\n",
... ])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.identify()
'KEITHLEY INSTRUMENTS INC.,MODEL 2400,1234567,C32 Mar  4 2011'
>>> k.disconnect()
abort() → None[source]

Abort trigger execution.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.abort()
>>> t.write_log[-1]
b':ABOR\n'
>>> k.disconnect()
check_error_queue(*, raise_on_error: bool = True) → tuple[tuple[int | None, str], ...][source]

Drain the error queue and optionally raise if instrument errors exist.

clear_buffer() → None[source]

Clear the reading buffer.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.clear_buffer()
>>> t.write_log[-1]
b':TRAC:CLE\n'
>>> k.disconnect()
clear_buffer_full_event() → None[source]

Clear a buffer-full event latched by an earlier acquisition.

configure_buffer(size: int, *, elements: tuple[str, ...] = ('VOLT', 'CURR', 'RES', 'TIME', 'STAT'), data_format: ElectrometerDataFormat | None = None) → None[source]

Configure the trace buffer and transfer format for buffered acquisition.

GPIB transfers default to native-order single-precision binary data. RS-232 transfers remain ASCII because the instrument does not support binary responses on that interface.

configure_buffer_full_srq() → None[source]

Route the trace-buffer-full measurement event to the SRQ line.

configure_source_sweep(config: SourceSweepConfiguration) → None[source]

Configure linear, logarithmic, or list source sweeps.

Parameters:

config (SourceSweepConfiguration) – Sweep configuration payload.

Raises:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> from stoner_measurement.instruments.source_meter import (
...     SourceSweepConfiguration, SweepSpacing,
... )
>>> t = NullTransport(responses=[b"VOLT\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.configure_source_sweep(
...     SourceSweepConfiguration(
...         start=0.0, stop=1.0, points=5,
...         spacing=SweepSpacing.LIN, delay=0.01,
...     )
... )
>>> t.write_log[-1]
b':SOUR:DEL 0.01\n'
>>> k.disconnect()

Handshake each source step with an external Trigger Link instrument.

The first trigger-layer event is bypassed so the initial source value can be applied immediately. Every source event then emits a pulse on output_line; subsequent source steps wait for a pulse on input_line.

Parameters:
  • input_line (int) – Trigger Link input line carrying measurement-complete pulses.

  • output_line (int) – Trigger Link output line carrying source-event pulses.

Raises:

ValueError – If either Trigger Link line is outside the supported range 1..6.

configure_trigger_model(config: TriggerModelConfiguration) → None[source]

Configure trigger and arm model settings.

Parameters:

config (TriggerModelConfiguration) – Trigger and arm model configuration.

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If trigger or arm counts are not positive, or trigger delay is negative.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> from stoner_measurement.instruments.source_meter import (
...     TriggerModelConfiguration, TriggerSource,
... )
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.configure_trigger_model(
...     TriggerModelConfiguration(
...         trigger_source=TriggerSource.BUS,
...         trigger_count=2,
...         trigger_delay=0.1,
...     )
... )
>>> t.write_log[0]
b':TRIG:SOUR BUS\n'
>>> k.disconnect()
drain_error_queue() → tuple[tuple[int | None, str], ...][source]

Drain the system error queue until the terminating no-error entry.

enable_output(state: bool) → None[source]

Enable or disable the source output.

Parameters:

state (bool) – True to turn the output on, False to turn it off.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.enable_output(True)
>>> t.write_log[-1]
b':OUTP:STAT 1\n'
>>> k.enable_output(False)
>>> t.write_log[-1]
b':OUTP:STAT 0\n'
>>> k.disconnect()
get_buffer_count() → int[source]

Return the actual number of readings currently stored in the buffer.

get_buffer_size() → int[source]

Return reading buffer capacity.

Returns:

Number of readings that can be stored.

Return type:

(int)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"250\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_buffer_size()
250
>>> k.disconnect()

Notes

Some instruments may return the buffer size in exponential format. The response is therefore parsed as float before conversion to int.

get_capabilities() → SourceMeterCapabilities[source]

Return the capability descriptor for the Keithley 2400 driver.

Returns:

Descriptor indicating that this driver supports measurement function selection, source sweeps, source delay, trigger/arm model configuration, reading buffer control, and configurable binary transfer format and byte order.

Return type:

(SourceMeterCapabilities)

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> caps = Keithley2400(transport=NullTransport()).get_capabilities()
>>> caps.has_sweep
True
>>> caps.has_buffer
True
get_compliance(source_mode: SourceMode | None = None) → float[source]

Return the compliance limit in amps (voltage mode) or volts (current mode).

Returns:

Compliance value.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"1.000000E-01\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_compliance()
0.1
>>> k.disconnect()
get_compliance_from_resistance(source_level: float | None = None) → float[source]

Return the effective compliance derived from a resistance threshold.

In voltage-source mode this returns the current compliance corresponding to a minimum allowed resistance. In current-source mode it returns the voltage compliance corresponding to a maximum allowed resistance.

get_error() → tuple[int | None, str][source]

Return the oldest queued system error.

get_measure_functions() → tuple[MeasureFunction, ...][source]

Return enabled measurement functions.

get_nplc() → float[source]

Return the integration time in power-line cycles.

Returns:

Integration time in power-line cycles.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"1.000000E+00\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_nplc()
1.0
>>> k.disconnect()
get_source_delay() → float[source]

Return source delay before each measurement trigger.

Returns:

Source delay in seconds.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"1.000000E-02\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_source_delay()
0.01
>>> k.disconnect()
get_source_level() → float[source]

Return the programmed source level in volts or amps.

Returns:

Source amplitude in the unit corresponding to the active source mode.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"1.000000E+00\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_source_level()
1.0
>>> k.disconnect()
get_source_mode() → SourceMode[source]

Return the active source mode.

Returns:

VOLT if the instrument is sourcing voltage, CURR if it is sourcing current.

Return type:

(SourceMode)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> from stoner_measurement.instruments.source_meter import SourceMode
>>> t = NullTransport(responses=[b"VOLT\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.get_source_mode()
<SourceMode.VOLT: 'VOLT'>
>>> k.disconnect()
initiate() → None[source]

Arm and start the trigger model.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.initiate()
>>> t.write_log[-1]
b':INIT\n'
>>> k.disconnect()
measure_current() → float[source]

Trigger a current measurement and return the result in amps.

Configures the sense function to current, triggers a single reading, and returns the parsed floating-point result.

Returns:

Measured current in amps.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"+1.000000E-03\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.measure_current()
0.001
>>> k.disconnect()
measure_power() → float[source]

Trigger simultaneous voltage/current measurements and return power in watts.

Returns:

Measured power in watts.

Return type:

(float)

Raises:
  • ConnectionError – If the transport is not open.

  • ValueError – If the instrument response does not include both voltage and current.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"+2.000000E+00,+5.000000E-01\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.measure_power()
1.0
>>> k.disconnect()
measure_resistance() → float[source]

Trigger a resistance measurement and return the result in ohms.

Returns:

Measured resistance in ohms.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"+1.200000E+03\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.measure_resistance()
1200.0
>>> k.disconnect()
measure_voltage() → float[source]

Trigger a voltage measurement and return the result in volts.

Configures the sense function to voltage, triggers a single reading, and returns the parsed floating-point result.

Returns:

Measured voltage in volts.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"+1.234567E+00\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.measure_voltage()
1.234567
>>> k.disconnect()
output_enabled() → bool[source]

Return True if the source output is currently enabled.

Returns:

True when the output is active.

Return type:

(bool)

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"0\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.output_enabled()
False
>>> k.disconnect()
read_buffer(count: int | None = None) → tuple[float, ...] | ndarray[source]

Read buffered readings from the internal trace buffer.

Parameters:

count (int | None) – Optional number of readings to return from the start of the buffer.

Returns:

Flat tuple for ASCII transfers, or a zero-copy array view for binary transfers.

Return type:

(tuple[float, …] | numpy.ndarray)

Raises:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport(responses=[b"1.0,2.0\n"])
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.read_buffer()
(1.0, 2.0)
>>> k.disconnect()
read_buffer_records(elements: tuple[str, ...], count: int | None = None) → tuple[BufferReading, ...][source]

Read and parse trace-buffer readings according to explicit format elements.

Parameters:
  • elements (tuple[str, ...]) – Ordered :FORM:ELEM configuration used for the transfer.

  • count (int | None) – Optional number of readings to read from the start of the buffer.

Returns:

Parsed buffer records.

Return type:

(tuple[BufferReading, …])

reset() → None[source]

Reset the instrument and restore cached format defaults.

reset_timestamp() → None[source]

Reset the instrument’s absolute timestamp counter.

safe_output_off() → None[source]

Best-effort output disable helper for cleanup paths.

set_buffer_size(size: int) → None[source]

Set reading buffer capacity.

Parameters:

size (int) – Number of readings for the buffer to retain.

Raises:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_buffer_size(100)
>>> t.write_log[-1]
b':TRAC:POIN 100\n'
>>> k.disconnect()
set_compliance(value: float, source_mode: SourceMode | None = None) → None[source]

Set the compliance limit.

Parameters:

value (float) – Compliance in amps (voltage mode) or volts (current mode).

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_compliance(0.05)
>>> t.write_log[-1]
b':SENS:CURR:PROT 0.05\n'
>>> k.disconnect()
set_compliance_from_resistance(resistance: float, *, source_level: float | None = None, source_mode: SourceMode | None = None) → float[source]

Set compliance from a resistance threshold and return the set limit.

For current-source mode, compliance = |I| * resistance so the resistance is interpreted as a maximum allowed resistance.

For voltage-source mode, compliance = |V| / resistance so the resistance is interpreted as a minimum allowed resistance.

set_data_format(data_format: ElectrometerDataFormat) → None[source]

Set ASCII or single-precision binary measurement transfers.

set_filter_count(count: int, source_mode: SourceMode | None = None) → None[source]

Set the digital averaging-filter count for the sensed quantity.

Parameters:
  • count (int) – Number of readings in the digital filter window.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

Raises:

ValueError – If count is not positive.

set_filter_enabled(enabled: bool, source_mode: SourceMode | None = None) → None[source]

Enable or disable the digital averaging filter on the sensed quantity.

Parameters:
  • enabled (bool) – True to enable the filter, False to disable it.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

set_filter_type(filter_type: FilterType, source_mode: SourceMode | None = None) → None[source]

Set the digital filter type for the sensed quantity.

Parameters:
  • filter_type (FilterType) – Filter type enum value.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

set_format_data_ascii() → None[source]

Select ASCII transfer format for reading data.

set_format_elements(elements: tuple[str, ...]) → None[source]

Set the reading elements returned by READ/FETCH/TRACE queries.

set_measure_functions(functions: tuple[MeasureFunction, ...]) → None[source]

Enable one or more measurement functions.

set_median_filter_enabled(enabled: bool, source_mode: SourceMode | None = None) → None[source]

Enable or disable the median filter on the sensed quantity.

Parameters:
  • enabled (bool) – True to enable the median filter, False to disable it.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

set_nplc(value: float) → None[source]

Set the integration time in power-line cycles.

Parameters:

value (float) – Integration time (0.01–10 PLC).

Raises:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_nplc(5.0)
>>> t.write_log  # two writes: voltage sense then current sense
[b':SENS:VOLT:NPLC 5.0\n', b':SENS:CURR:NPLC 5.0\n']
>>> k.disconnect()
set_remote_sense(enabled: bool) → None[source]

Enable or disable 4-wire remote sensing.

Parameters:

enabled (bool) – True for 4-wire sensing, False for 2-wire sensing.

set_sense_autorange(enabled: bool, source_mode: SourceMode | None = None) → None[source]

Enable or disable measurement autoranging for the sensed quantity.

Parameters:
  • enabled (bool) – True to enable autorange, False for fixed range mode.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

set_sense_range(value: float, source_mode: SourceMode | None = None) → None[source]

Set the fixed measurement range for the sensed quantity.

Parameters:
  • value (float) – Positive sense range in volts or amps.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

Raises:

ValueError – If value is not positive.

set_source_autorange(enabled: bool, source_mode: SourceMode | None = None) → None[source]

Enable or disable source autoranging for the selected source function.

Parameters:
  • enabled (bool) – True to enable autorange, False for fixed range mode.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

set_source_delay(delay: float) → None[source]

Set source delay before each measurement trigger.

Parameters:

delay (float) – Source delay in seconds.

Raises:

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_source_delay(0.01)
>>> t.write_log[-1]
b':SOUR:DEL 0.01\n'
>>> k.disconnect()
set_source_level(value: float) → None[source]

Set the source output level.

Parameters:

value (float) – Output amplitude in volts (voltage mode) or amps (current mode).

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_source_level(1.5)
>>> t.write_log[-1]
b':SOUR:AMPL 1.5\n'
>>> k.disconnect()
set_source_mode(mode: SourceMode) → None[source]

Set the source mode.

Parameters:

mode (SourceMode) – VOLT for voltage source or CURR for current source.

Raises:

ConnectionError – If the transport is not open.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.keithley import Keithley2400
>>> from stoner_measurement.instruments.source_meter import SourceMode
>>> t = NullTransport()
>>> k = Keithley2400(transport=t)
>>> k.connect()
>>> k.set_source_mode(SourceMode.VOLT)
>>> t.write_log[-1]
b':SOUR:FUNC:MODE VOLT\n'
>>> k.disconnect()
set_source_range(value: float, source_mode: SourceMode | None = None) → None[source]

Set the fixed source range for the selected source function.

Parameters:
  • value (float) – Positive source range in volts or amps.

  • source_mode (SourceMode | None) – Optional explicit source mode. If None, the active mode is queried from the instrument.

Raises:

ValueError – If value is not positive.

set_terminal_selection(terminal: TerminalSelection) → None[source]

Select the front or rear source/output terminals.

Parameters:

terminal (TerminalSelection) – Terminal selection enum value.

set_trace_feed_continuous_never() → None[source]

Disable trace-buffer filling.

set_trace_feed_continuous_next() → None[source]

Enable trace-buffer fill on the next initiated acquisition.

set_trace_feed_sense() → None[source]

Configure the trace buffer to store raw sense readings.

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

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

wait_for_operation_complete() → None[source]

Block until prior instrument operations have completed.