stoner_measurement.instruments.source_meter.SourceMeter¶
- class stoner_measurement.instruments.source_meter.SourceMeter(transport: BaseTransport, protocol: BaseProtocol)[source]¶
Bases:
BaseInstrumentAbstract 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
NotImplementedErrorby default; drivers override only those methods that their hardware supports. Callers should consultget_capabilities()to determine which optional features are available before invoking them.- Variables:
transport (BaseTransport) – Transport layer instance.
protocol (BaseProtocol) – Protocol instance.
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_modelbefore calling.
- clear_buffer() None[source]¶
Clear the instrument reading buffer.
- Raises:
NotImplementedError – If the driver does not support reading buffer control. Check
SourceMeterCapabilities.has_bufferbefore 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_sweepbefore calling.
- configure_linear_sweep(start: float, stop: float, points: int, *, delay: float = 0.0) None[source]¶
Configure a linear source sweep.
- Parameters:
- 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_sweepbefore 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:
- 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_sweepbefore 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_sweepbefore 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_modelbefore calling.
- abstractmethod enable_output(state: bool) None[source]¶
Enable or disable the source output.
- Parameters:
state (bool) –
Trueto enable the output,Falseto 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_bufferbefore 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:
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_selectionbefore 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_delaybefore 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:
VOLTif the instrument is sourcing voltage,CURRif it is sourcing current.- Return type:
- 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_modelbefore 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-12A.
Notes
Currents with absolute magnitude smaller than
_MIN_CURRENT_FOR_RESISTANCE_CALCULATIONare 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
Trueif the source output is currently enabled.- Returns:
Truewhen the output is on,Falsewhen 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:
- Raises:
NotImplementedError – If the driver does not support reading buffer control. Check
SourceMeterCapabilities.has_bufferbefore 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_bufferbefore 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:
ConnectionError – If the transport is not open.
ValueError – If value exceeds the instrument’s maximum compliance.
- 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_selectionbefore 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:
ConnectionError – If the transport is not open.
ValueError – If value is outside the valid range.
- 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_delaybefore 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) –
VOLTfor voltage source orCURRfor current source.- Raises:
ConnectionError – If the transport is not open.