stoner_measurement.instruments.source_meter.SourceMeter

class stoner_measurement.instruments.source_meter.SourceMeter(transport: BaseTransport, protocol: BaseProtocol)[source]

Bases: BaseInstrument

Abstract base class for source-measure unit (SMU) instruments.

A source-meter can source voltage or current while simultaneously measuring the complementary quantity, making it suitable for current-voltage (I–V) characterisation.

Subclasses must implement the core abstract methods. Optional capability methods raise NotImplementedError by default; drivers override only those methods that their hardware supports. Callers should consult get_capabilities() to determine which optional features are available before invoking them.

Variables:

Examples

>>> # Demonstrate interface using a minimal concrete implementation
>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import ScpiProtocol
>>> from stoner_measurement.instruments.source_meter import (
...     SourceMeter, SourceMode, SourceMeterCapabilities,
... )
>>> class _SM(SourceMeter):
...     def get_source_mode(self): return SourceMode.VOLT
...     def set_source_mode(self, mode): pass
...     def get_source_level(self): return 1.0
...     def set_source_level(self, value): pass
...     def get_compliance(self): return 0.1
...     def set_compliance(self, value): pass
...     def get_nplc(self): return 1.0
...     def set_nplc(self, value): pass
...     def measure_voltage(self): return 1.0
...     def measure_current(self): return 0.001
...     def output_enabled(self): return False
...     def enable_output(self, state): pass
...     def get_capabilities(self): return SourceMeterCapabilities()
>>> sm = _SM(NullTransport(), ScpiProtocol())
>>> sm.get_source_mode()
<SourceMode.VOLT: 'VOLT'>
>>> sm.get_capabilities().has_sweep
False
abort() → None[source]

Abort trigger execution.

Raises:

NotImplementedError – If the driver does not support trigger abort. Check SourceMeterCapabilities.has_trigger_model before calling.

clear_buffer() → None[source]

Clear the instrument reading buffer.

Raises:

NotImplementedError – If the driver does not support reading buffer control. Check SourceMeterCapabilities.has_buffer before calling.

configure_custom_sweep(values: tuple[float, ...], *, delay: float = 0.0) → None[source]

Configure a custom point-by-point source sweep.

Parameters:

values (tuple[float, ...]) – Explicit source values to program.

Keyword Parameters:

delay (float) – Source settling delay between points in seconds.

Raises:

NotImplementedError – If the driver does not support source sweep configuration. Check SourceMeterCapabilities.has_sweep before calling.

configure_linear_sweep(start: float, stop: float, points: int, *, delay: float = 0.0) → None[source]

Configure a linear source sweep.

Parameters:
  • start (float) – Sweep start value in source units.

  • stop (float) – Sweep stop value in source units.

  • points (int) – Number of points in the sweep.

Keyword Parameters:

delay (float) – Source settling delay between sweep points in seconds.

Raises:

NotImplementedError – If the driver does not support source sweep configuration. Check SourceMeterCapabilities.has_sweep before calling.

Examples

>>> from stoner_measurement.instruments.transport import NullTransport
>>> from stoner_measurement.instruments.protocol import ScpiProtocol
>>> from stoner_measurement.instruments.source_meter import (
...     SourceMeter, SourceMode, SourceMeterCapabilities,
... )
>>> class _SM(SourceMeter):
...     def get_source_mode(self): return SourceMode.VOLT
...     def set_source_mode(self, mode): pass
...     def get_source_level(self): return 0.0
...     def set_source_level(self, value): pass
...     def get_compliance(self): return 0.0
...     def set_compliance(self, value): pass
...     def get_nplc(self): return 1.0
...     def set_nplc(self, value): pass
...     def measure_voltage(self): return 0.0
...     def measure_current(self): return 0.0
...     def output_enabled(self): return False
...     def enable_output(self, state): pass
...     def get_capabilities(self): return SourceMeterCapabilities()
>>> sm = _SM(NullTransport(), ScpiProtocol())
>>> sm.configure_linear_sweep(0.0, 1.0, 11, delay=0.01)
Traceback (most recent call last):
...
NotImplementedError: _SM does not support source sweep configuration. ...
configure_log_sweep(start: float, stop: float, points: int, *, delay: float = 0.0) → None[source]

Configure a logarithmic source sweep.

Parameters:
  • start (float) – Sweep start value in source units.

  • stop (float) – Sweep stop value in source units.

  • points (int) – Number of points in the sweep.

Keyword Parameters:

delay (float) – Source settling delay between sweep points in seconds.

Raises:

NotImplementedError – If the driver does not support source sweep configuration. Check SourceMeterCapabilities.has_sweep before calling.

configure_source_sweep(config: SourceSweepConfiguration) → None[source]

Configure a source sweep.

Parameters:

config (SourceSweepConfiguration) – Source sweep configuration.

Raises:

NotImplementedError – If the driver does not support source sweep configuration. Check SourceMeterCapabilities.has_sweep before calling.

configure_trigger_model(config: TriggerModelConfiguration) → None[source]

Configure trigger and arm behaviour.

Parameters:

config (TriggerModelConfiguration) – Trigger and arm model configuration.

Raises:

NotImplementedError – If the driver does not support trigger model configuration. Check SourceMeterCapabilities.has_trigger_model before calling.

abstractmethod enable_output(state: bool) → None[source]

Enable or disable the source output.

Parameters:

state (bool) – True to enable the output, False to disable it.

Raises:

ConnectionError – If the transport is not open.

get_buffer_size() → int[source]

Return reading buffer capacity.

Returns:

Number of readings that the buffer can store.

Return type:

(int)

Raises:

NotImplementedError – If the driver does not support reading buffer control. Check SourceMeterCapabilities.has_buffer before calling.

abstractmethod get_capabilities() → SourceMeterCapabilities[source]

Return the static capability descriptor for this SMU driver.

Returns:

Descriptor advertising which optional feature groups are supported by this driver.

Return type:

(SourceMeterCapabilities)

Examples

>>> caps = sm.get_capabilities()
>>> caps.has_sweep
False
abstractmethod get_compliance() → float[source]

Return the compliance limit (A in voltage mode, V in current mode).

Returns:

Compliance value in amps or volts.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

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

Return enabled measurement functions.

Returns:

Enabled measurement functions.

Return type:

(tuple[MeasureFunction, …])

Raises:

NotImplementedError – If the driver does not support function selection. Check SourceMeterCapabilities.has_function_selection before calling.

abstractmethod get_nplc() → float[source]

Return the integration time in power-line cycles (NPLC).

Returns:

Integration time in power-line cycles.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

get_source_delay() → float[source]

Return source delay in seconds.

Returns:

Source delay in seconds.

Return type:

(float)

Raises:

NotImplementedError – If the driver does not support source delay control. Check SourceMeterCapabilities.has_source_delay before calling.

abstractmethod get_source_level() → float[source]

Return the programmed source level (V or A).

Returns:

Source amplitude in volts or amps depending on get_source_mode().

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

abstractmethod get_source_mode() → SourceMode[source]

Return the current 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.

initiate() → None[source]

Arm and initiate acquisition.

Raises:

NotImplementedError – If the driver does not support trigger initiation. Check SourceMeterCapabilities.has_trigger_model before calling.

abstractmethod measure_current() → float[source]

Trigger a current measurement and return the result in amps.

Returns:

Measured current in amps.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

measure_power() → float[source]

Return power calculated from measured voltage and current.

Returns:

Electrical power in watts.

Return type:

(float)

measure_resistance() → float[source]

Return resistance calculated from measured voltage and current.

Returns:

Resistance in ohms.

Return type:

(float)

Raises:

ZeroDivisionError – If the measured current magnitude is below 1e-12 A.

Notes

Currents with absolute magnitude smaller than _MIN_CURRENT_FOR_RESISTANCE_CALCULATION are treated as zero to avoid numerically unstable resistance values.

abstractmethod measure_voltage() → float[source]

Trigger a voltage measurement and return the result in volts.

Returns:

Measured voltage in volts.

Return type:

(float)

Raises:

ConnectionError – If the transport is not open.

abstractmethod output_enabled() → bool[source]

Return True if the source output is currently enabled.

Returns:

True when the output is on, False when off.

Return type:

(bool)

Raises:

ConnectionError – If the transport is not open.

read_buffer(count: int | None = None) → tuple[float, ...] | ndarray[source]

Return readings from the instrument buffer.

Parameters:

count (int | None) – Optional count of readings to request.

Returns:

Flat tuple of numeric readings from the instrument buffer.

Return type:

(tuple[float, …])

Raises:

NotImplementedError – If the driver does not support reading buffer control. Check SourceMeterCapabilities.has_buffer before calling.

set_buffer_size(size: int) → None[source]

Set reading buffer capacity.

Parameters:

size (int) – Number of readings the instrument should retain.

Raises:

NotImplementedError – If the driver does not support reading buffer control. Check SourceMeterCapabilities.has_buffer before calling.

abstractmethod set_compliance(value: float) → None[source]

Set the compliance limit.

Parameters:

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

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

Enable one or more measurement functions.

Parameters:

functions (tuple[MeasureFunction, ...]) – Sequence of measurement functions to enable.

Raises:

NotImplementedError – If the driver does not support function selection. Check SourceMeterCapabilities.has_function_selection before calling.

abstractmethod set_nplc(value: float) → None[source]

Set the integration time in power-line cycles.

Parameters:

value (float) – Integration time in power-line cycles. Typical range is 0.01–10.

Raises:
set_source_delay(delay: float) → None[source]

Set source delay in seconds before each measurement trigger.

Parameters:

delay (float) – Source delay in seconds.

Raises:

NotImplementedError – If the driver does not support source delay control. Check SourceMeterCapabilities.has_source_delay before calling.

abstractmethod set_source_level(value: float) → None[source]

Set the source output level (V or A).

Parameters:

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

Raises:

ConnectionError – If the transport is not open.

abstractmethod 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.