keithley2600.keithley_driver
Core driver with the low level functions.
Module Contents
Classes
Mimics a Keithley TSP Lua property (bool, number or string). |
|
Mimics a Keithley TSP (Lua) function |
|
Mimics a Keithley TSP (Lua) table |
|
Keithley2600 driver |
|
Keithley2600 driver with high level functionality |
Functions
|
Removes the given prefix from a string. Only the first instance of the prefix is |
- keithley2600.keithley_driver.removeprefix(self: str, prefix: str) str
Removes the given prefix from a string. Only the first instance of the prefix is removed. The original string is returned if it does not start with the given prefix.
This follows the Python 3.9 implementation of
str.removeprefix
.- Parameters:
self – Original string.
prefix – Prefix to remove.
- Returns:
String without prefix.
- exception keithley2600.keithley_driver.KeithleyIOError
Bases:
Exception
Raised when no Keithley instrument is connected.
- class __cause__
exception cause
- class __context__
exception context
- __delattr__()
Implement delattr(self, name).
- __dir__()
Default dir() implementation.
- __eq__()
Return self==value.
- __format__()
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
- __ge__()
Return self>=value.
- __getattribute__()
Return getattr(self, name).
- __getstate__()
Helper for pickle.
- __gt__()
Return self>value.
- __hash__()
Return hash(self).
- __le__()
Return self<=value.
- __lt__()
Return self<value.
- __ne__()
Return self!=value.
- __reduce__()
Helper for pickle.
- __reduce_ex__()
Helper for pickle.
- __repr__()
Return repr(self).
- __setattr__()
Implement setattr(self, name, value).
- __sizeof__()
Size of object in memory, in bytes.
- __str__()
Return str(self).
- __subclasshook__()
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception keithley2600.keithley_driver.KeithleyError
Bases:
Exception
Raised for error messages from the Keithley itself.
- class __cause__
exception cause
- class __context__
exception context
- __delattr__()
Implement delattr(self, name).
- __dir__()
Default dir() implementation.
- __eq__()
Return self==value.
- __format__()
Default object formatter.
Return str(self) if format_spec is empty. Raise TypeError otherwise.
- __ge__()
Return self>=value.
- __getattribute__()
Return getattr(self, name).
- __getstate__()
Helper for pickle.
- __gt__()
Return self>value.
- __hash__()
Return hash(self).
- __le__()
Return self<=value.
- __lt__()
Return self<value.
- __ne__()
Return self!=value.
- __reduce__()
Helper for pickle.
- __reduce_ex__()
Helper for pickle.
- __repr__()
Return repr(self).
- __setattr__()
Implement setattr(self, name, value).
- __sizeof__()
Size of object in memory, in bytes.
- __str__()
Return str(self).
- __subclasshook__()
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class keithley2600.keithley_driver.KeithleyProperty(name: str, parent: KeithleyClass, readonly: bool = False)
Mimics a Keithley TSP Lua property (bool, number or string).
Getters and setters forward their calls to
_query()
and_write()
methods of the parent command. Booleans, numbers and strings are accepted natively, anything else will be converted to a string.
- class keithley2600.keithley_driver.KeithleyFunction(name: str, parent: KeithleyClass)
Mimics a Keithley TSP (Lua) function
Class which mimics a function and can be dynamically created. It forwards all calls to the
_query()
method of the parent command and returns the result from_query()
. Calls accept arbitrary arguments, as long as_query()
can handle them.This class is designed to look like a Keithley TSP function, forward function calls to the Keithley, and return the results.
- class keithley2600.keithley_driver.KeithleyClass(name: str, parent: KeithleyClass | None = None)
Mimics a Keithley TSP (Lua) table
Class which represents a Keithley TSP / Lua table. Tables act as the equivalent of objects in the Lua scripting language and table indices can be both numbers or strings. Their values are accessible by index notation or as “attributes” in case of string indices. For example,
table["name"]
andtable.name
access the same field. If tables have numeric indices only, they practically serve as a list.- create_lua_attr(name: str | int, value: Any) LuaBridgeType
Creates an attribute / index of this table, initialized to the provided value.
If the attribute already exists, set it to the provided value.
- Parameters:
name – Variable name.
value – Initial value, will be used to infer the type.
- Returns:
The accessor for the created variable.
- class keithley2600.keithley_driver.Keithley2600Base(visa_address: str, visa_library: str = '@py', raise_keithley_errors: bool = False, **kwargs)
Bases:
KeithleyClass
Keithley2600 driver
Keithley driver for base functionality. It replicates the functionality and syntax from the Keithley TSP commands, as provided by the Lua scripting language. Attributes are created on-demand if they correspond to Keithley TSP commands.
- Parameters:
visa_address – Visa address of the instrument.
visa_library – Path to visa library. Defaults to “@py” for pyvisa-py but another IVI library may be appropriate (NI-VISA, Keysight VISA, R&S VISA, tekVISA etc.). If an empty string is given, an IVI library will be used if installed and pyvisa-py otherwise.
raise_keithley_errors – If
True
, all Keithley errors will be raised as Python errors instead of being ignored. This causes significant communication overhead because the Keithley’s error queue is read after each command. Defaults toFalse
.kwargs – Keyword arguments passed on to the visa connection, for instance baude-rate or timeout. If not given, reasonable defaults will be used.
- Variables:
connection – Attribute holding a reference to the actual connection.
connected –
True
if connected to an instrument,False
otherwise.busy –
True
if a measurement is running,False
otherwise.CHUNK_SIZE – Maximum length of lists which can be sent to the Keithley. Longer lists will be transferred in chunks.
Note
See the Keithley 2600 reference manual for all available commands and arguments. A dictionary of available commands will be loaded on access from the Keithley at runtime, if connected.
- Examples:
>>> keithley = Keithley2600Base('TCPIP0::192.168.2.121::INSTR') >>> keithley.smua.measure.v() # measures voltage at smuA >>> keithley.smua.source.levelv = -40 # applies -40V to smuA
- connect(**kwargs) bool
Connects to Keithley.
- Parameters:
kwargs – Keyword arguments for Visa connection.
- Returns:
Whether the connection succeeded.
- create_lua_attr(name: str | int, value: Any) LuaBridgeType
Creates an attribute / index of this table, initialized to the provided value.
If the attribute already exists, set it to the provided value.
- Parameters:
name – Variable name.
value – Initial value, will be used to infer the type.
- Returns:
The accessor for the created variable.
- class keithley2600.keithley_driver.Keithley2600(visa_address: str, visa_library: str = '@py', raise_keithley_errors: bool = False, **kwargs)
Bases:
Keithley2600Base
Keithley2600 driver with high level functionality
Keithley driver with access to base functions and higher level functions such as IV measurements, transfer and output curves, etc. Inherits from
Keithley2600Base
. Base commands replicate the functionality and syntax of Keithley TSP functions.- Parameters:
visa_address – Visa address of the instrument.
visa_library – Path to visa library. Defaults to “@py” for pyvisa-py but another IVI library may be appropriate (NI-VISA, Keysight VISA, R&S VISA, tekVISA etc.). If an empty string is given, an IVI library will be used if installed and pyvisa-py otherwise.
raise_keithley_errors – If
True
, all Keithley errors will be raised as Python errors instead of being ignored. This causes significant communication overhead because the Keithley’s error queue is read after each command. Defaults toFalse
.kwargs – Keyword arguments passed on to the visa connection, for instance baude-rate or timeout. If not given, reasonable defaults will be used.
- Variables:
connection – Attribute holding a reference to the actual connection.
connected –
True
if connected to an instrument,False
otherwise.busy (bool) –
True
if a measurement is running,False
otherwise.
- Examples:
Base commands from Keithley TSP:
>>> k = Keithley2600('TCPIP0::192.168.2.121::INSTR') >>> volts = k.smua.measure.v() # measures and returns the smuA voltage >>> k.smua.source.levelv = -40 # sets source level of smuA >>> k.smua.nvbuffer1.clear() # clears nvbuffer1 of smuA
New mid-level commands:
>>> data = k.read_buffer(k.smua.nvbuffer1) >>> errs = k.read_error_queue() >>> k.set_integration_time(k.smua, 0.001) # in sec
>>> k.apply_voltage(k.smua, -60) # applies -60V to smuA >>> k.apply_current(k.smub, 0.1) # sources 0.1A from smuB >>> k.ramp_to_voltage(k.smua, 10, delay=0.1, step_size=1)
>>> # voltage sweeps, single and dual SMU >>> k.voltage_sweep_single_smu(smu=k.smua, smu_sweeplist=range(0, 61), ... t_int=0.1, delay=-1, pulsed=False) >>> k.voltage_sweep_dual_smu(smu1=k.smua, smu2=k.smub, ... smu1_sweeplist=range(0, 61), ... smu2_sweeplist=range(0, 61), ... t_int=0.1, delay=-1, pulsed=False)
New high-level commands:
>>> data1 = k.output_measurement(...) # records output curve >>> data2 = k.transfer_measurement(...) # records transfer curve
- read_error_queue() List[Tuple[LuaReturnTypes, Ellipsis]]
Returns all entries from the Keithley error queue and clears the queue.
- Returns:
List of errors from the Keithley error queue. Each entry is a tuple
(error_code, message, severity, error_node)
. If the queue is empty, an empty list is returned.
- static read_buffer(buffer: KeithleyClass) List[float]
Reads buffer values and returns them as a list. This can be done more quickly by calling
buffer.readings
but such a call may fail due to I/O limitations of the keithley if the returned list is too long.- Parameters:
buffer – A keithley buffer instance.
- Returns:
A list with buffer readings.
- set_integration_time(smu: KeithleyClass, t_int: float) None
Sets the integration time of SMU for measurements in sec.
- Parameters:
smu – A keithley smu instance.
t_int – Integration time in sec. Value must be between 1/1000 and 25 power line cycles (50Hz or 60 Hz).
- Raises:
ValueError
for too short or too long integration times.
- apply_voltage(smu: KeithleyClass, voltage: float) None
Turns on the specified SMU and applies a voltage.
- Parameters:
smu – A keithley smu instance.
voltage – Voltage to apply in Volts.
- apply_current(smu: KeithleyClass, curr: float) None
Turns on the specified SMU and sources a current.
- Parameters:
smu – A keithley smu instance.
curr – Current to apply in Ampere.
- measure_voltage(smu: KeithleyClass) float
Measures a voltage at the specified SMU.
- Parameters:
smu – A keithley smu instance.
- Returns:
Measured voltage in Volts.
- measure_current(smu: KeithleyClass) float
Measures a current at the specified SMU.
- Parameters:
smu – A keithley smu instance.
- Returns:
Measured current in Ampere.
- ramp_to_voltage(smu: KeithleyClass, target_volt: float, delay: float = 0.1, step_size: float = 1) None
Ramps up the voltage of the specified SMU.
- Parameters:
smu – A keithley smu instance.
target_volt – Target voltage in Volts.
step_size – Size of the voltage steps in Volts.
delay – Delay between steps in sec.
- send_trigger() None
Manually sends a trigger signal to the Keithley. This can be used for instance to start a pre-programmed sweep.
- voltage_sweep_single_smu(smu: KeithleyClass, smu_sweeplist: Sequence[float], t_int: float, delay: float, pulsed: bool) Tuple[List[float], List[float]]
Sweeps the voltage through the specified list of steps at the given SMU. Measures and returns the current and voltage during the sweep.
- Parameters:
smu – A keithley smu instance.
smu_sweeplist – Voltages to sweep through (can be a numpy array, list, tuple or any other iterable of numbers).
t_int – Integration time per data point. Must be between 0.001 to 25 times the power line frequency (50Hz or 60Hz).
delay – Settling delay before each measurement. A value of -1 automatically starts a measurement once the current is stable.
pulsed – Select pulsed or continuous sweep. In a pulsed sweep, the voltage is always reset to zero between data points.
- Returns:
Lists of voltages and currents measured during the sweep (in Volt and Ampere, respectively):
(v_smu, i_smu)
.
- voltage_sweep_dual_smu(smu1: KeithleyClass, smu2: KeithleyClass, smu1_sweeplist: Sequence[float], smu2_sweeplist: Sequence[float], t_int: float, delay: float, pulsed: bool) Tuple[List[float], List[float], List[float], List[float]]
Sweeps voltages at two SMUs. Measures and returns current and voltage during sweep.
- Parameters:
smu1 – 1st keithley smu instance to be swept.
smu2 – 2nd keithley smu instance to be swept.
smu1_sweeplist – Voltages to sweep at
smu1
(can be a numpy array, list, tuple or any other iterable with numbers).smu2_sweeplist – Voltages to sweep at
smu2
(can be a numpy array, list, tuple or any other iterable with numbers).t_int – Integration time per data point. Must be between 0.001 to 25 times the power line frequency (50Hz or 60Hz).
delay – Settling delay before each measurement. A value of -1 automatically starts a measurement once the current is stable.
pulsed – Select pulsed or continuous sweep. In a pulsed sweep, the voltage is always reset to zero between data points.
- Returns:
Lists of voltages and currents measured during the sweep (in Volt and Ampere, respectively):
(v_smu1, i_smu1, v_smu2, i_smu2)
.
- transfer_measurement(smu_gate: KeithleyClass, smu_drain: KeithleyClass, vg_start: float, vg_stop: float, vg_step: float, vd_list: Sequence[float], t_int: float, delay: float, pulsed: bool) keithley2600.result_table.FETResultTable
Records a transfer curve with forward and reverse sweeps and returns the results in a
sweep_data.TransistorSweepData
instance.- Parameters:
smu_gate – Keithley smu attached to gate electrode.
smu_drain – Keithley smu attached to drain electrode.
vg_start – Start voltage of transfer sweep in Volt.
vg_stop – End voltage of transfer sweep in Volt.
vg_step – Voltage step size for transfer sweep in Volt.
vd_list – List of drain voltage steps in Volt. Can be a numpy array, list, tuple, range / xrange. Optionally, you can also pass the string
"trailing"
for the drain voltage to always follow the gate voltage. This ensures that the FET is always at the edge of “saturation”.t_int – Integration time per data point. Must be between 0.001 to 25 times the power line frequency (50Hz or 60Hz).
delay – Settling delay before each measurement. A value of -1 automatically starts a measurement once the current is stable.
pulsed (bool) – Select pulsed or continuous sweep. In a pulsed sweep, the voltage is always reset to zero between data points.
- Returns:
Transfer curve data.
- output_measurement(smu_gate: KeithleyClass, smu_drain: KeithleyClass, vd_start: float, vd_stop: float, vd_step: float, vg_list: Sequence[float], t_int: float, delay: float, pulsed: bool) keithley2600.result_table.FETResultTable
Records an output curve with forward and reverse sweeps and returns the results in a
sweep_data.TransistorSweepData
instance.- Parameters:
smu_gate – Keithley smu attached to gate electrode.
smu_drain – Keithley smu attached to drain electrode.
vd_start (float) – Start voltage of output sweep in Volt.
vd_stop (float) – End voltage of output sweep in Volt.
vd_step (float) – Voltage step size for output sweep in Volt.
vg_list – List of gate voltage steps in Volt. Can be a numpy array, list, tuple, range / xrange.
t_int (float) – Integration time per data point. Must be between 0.001 to 25 times the power line frequency (50Hz or 60Hz).
delay (float) – Settling delay before each measurement. A value of -1 automatically starts a measurement once the current is stable.
pulsed (bool) – Select pulsed or continuous sweep. In a pulsed sweep, the voltage is always reset to zero between data points.
- Returns:
Output curve data.
- play_chord(notes: Tuple[str, Ellipsis] = ('C6', 'E6', 'G6'), durations: float | Iterable[float] = 0.3) None
Plays a chord on the Keithley.
- Parameters:
notes – List of notes in scientific pitch notation, for instance
['F4', 'Ab4', 'C4']
for a f-minor chord in the 4th octave. Defaults to c-major in the 6th octave.durations – List of durations for each note in sec. If a single float is given, all notes will have the same duration. Defaults to 0.3 sec.
- connect(**kwargs) bool
Connects to Keithley.
- Parameters:
kwargs – Keyword arguments for Visa connection.
- Returns:
Whether the connection succeeded.
- create_lua_attr(name: str | int, value: Any) LuaBridgeType
Creates an attribute / index of this table, initialized to the provided value.
If the attribute already exists, set it to the provided value.
- Parameters:
name – Variable name.
value – Initial value, will be used to infer the type.
- Returns:
The accessor for the created variable.