qcodes_contrib_drivers.drivers.NationalInstruments package

Submodules

qcodes_contrib_drivers.drivers.NationalInstruments.DAQ module

Qcodes drivers for National Instrument mutlifunction I/O devices (DAQs).

Requires nidaqmx package: https://nidaqmx-python.readthedocs.io/en/latest/

This was written for/tested with National Instruments USB-6363 DAQ, but the nidaqmx API is pretty general, so I expect it will work with other devices with minimal changes.

For an example of synchronously writing data to multiple analog outputs and acquiring data on multiple analog inputs, see https://scanning-squid.readthedocs.io/en/latest/_modules/microscope/susceptometer.html#SusceptometerMicroscope.scan_surface

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQAnalogInputVoltages(name: str, task: Any, samples_to_read: int, shape: Sequence[int], timeout: float | int, **kwargs)[source]

Bases: ArrayParameter

Acquires data from one or several DAQ analog inputs.

Parameters:
  • name – Name of parameter (usually ‘voltage’).

  • task – nidaqmx.Task with appropriate analog inputs channels.

  • samples_to_read – Number of samples to read. Will be averaged based on shape.

  • shape – Desired shape of averaged array, i.e. (nchannels, target_points).

  • timeout – Acquisition timeout in seconds.

  • kwargs – Keyword arguments to be passed to ArrayParameter constructor.

get_raw()[source]

Averages data to get self.target_points points per channel. If self.target_points == self.samples_to_read, no averaging is done.

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQAnalogInputs(*args: Any, **kwargs: Any)[source]

Bases: Instrument

Instrument to acquire DAQ analog input data in a qcodes Loop or measurement.

Parameters:
  • name – Name of instrument (usually ‘daq_ai’).

  • dev_name – NI DAQ device name (e.g. ‘Dev1’).

  • rate – Desired DAQ sampling rate per channel in Hz.

  • channels – Dict of analog input channel configuration.

  • task – fresh nidaqmx.Task to be populated with ai_channels.

  • min_val – minimum of input voltage range (-0.1, -0.2, -0.5, -1, -2, -5 [default], or -10)

  • max_val – maximum of input voltage range (0.1, 0.2, 0.5, 1, 2, 5 [default], or 10)

  • clock_src – Sample clock source for analog inputs. Default: None

  • samples_to_read – Number of samples to acquire from the DAQ per channel per measurement/loop iteration. Default: 2 (minimum number of samples DAQ will acquire in this timing mode).

  • target_points – Number of points per channel we want in our final array. samples_to_read will be averaged down to target_points.

  • timeout – Acquisition timeout in seconds. Default: 60.

  • kwargs – Keyword arguments to be passed to Instrument constructor.

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQAnalogOutputVoltage(name: str, dev_name: str, idx: int, **kwargs)[source]

Bases: Parameter

Writes data to one or several DAQ analog outputs. This only writes one channel at a time, since Qcodes ArrayParameters are not settable.

Parameters:
  • name – Name of parameter (usually ‘voltage’).

  • dev_name – DAQ device name (e.g. ‘Dev1’).

  • idx – AO channel index.

  • kwargs – Keyword arguments to be passed to ArrayParameter constructor.

get_raw()[source]

Returns last voltage array written to outputs.

set_raw(voltage: int | float) None[source]

set_raw is called to perform the actual setting of a parameter on the instrument. This method should either be overwritten to perform the desired operation or alternatively for Parameter a suitable method is automatically generated if set_cmd is supplied to the parameter constructor. The method is automatically wrapped to provide a set method on the parameter instance.

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQAnalogOutputs(*args: Any, **kwargs: Any)[source]

Bases: Instrument

Instrument to write DAQ analog output data in a qcodes Loop or measurement.

Parameters:
  • name – Name of instrument (usually ‘daq_ao’).

  • dev_name – NI DAQ device name (e.g. ‘Dev1’).

  • channels – Dict of analog output channel configuration.

  • **kwargs – Keyword arguments to be passed to Instrument constructor.

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQDigitalOutputState(name: str, dev_name: str, lines: list | str, **kwargs)[source]

Bases: Parameter

Writes data to one or several DAQ digital outputs.

Parameters:
  • name – Name of parameter (usually ‘voltage’).

  • dev_name – DAQ device name (e.g. ‘Dev1’).

  • lines – DO lines.

  • kwargs – Keyword arguments to be passed to ParameterWithSetpoints constructor.

set_raw(state: list | bool) None[source]

set_raw is called to perform the actual setting of a parameter on the instrument. This method should either be overwritten to perform the desired operation or alternatively for Parameter a suitable method is automatically generated if set_cmd is supplied to the parameter constructor. The method is automatically wrapped to provide a set method on the parameter instance.

class qcodes_contrib_drivers.drivers.NationalInstruments.DAQ.DAQDigitalOutputs(*args: Any, **kwargs: Any)[source]

Bases: Instrument

Instrument to write DAQ digital output data in a qcodes Loop or measurement.

Parameters:
  • name – Name of instrument (usually ‘daq_do’).

  • dev_name – NI DAQ device name (e.g. ‘PXI1Slot2’).

  • lines – DO lines.

  • **kwargs – Keyword arguments to be passed to Instrument constructor.

qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_2597 module

class qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_2597.NI_PXIe_2597(*args: Any, **kwargs: Any)[source]

Bases: NI_Switch

QCoDeS driver for National Instruments RF switch PXIe-2597. The device connects the common “com” port to any of the 6 other ports, labeled “ch1”…”ch6” by default. Use the name_mapping argument to alias the channel names.

Parameters:
  • name – Qcodes name for this instrument

  • resource – Network address or VISA alias for the instrument.

  • name_mapping – Optional mapping from default channel names to custom aliases

  • reset_device – whether to reset the device on initialization

qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_5654 module

qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_5654.NI_PXIe_5654

alias of NationalInstruments_PXIe_5654

class qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_5654.NationalInstruments_PXIe_5654(*args: Any, **kwargs: Any)[source]

Bases: NationalInstruments_RFSG

Device-specific driver for the PXIe-5654 signal generator. See the NI_RFSG class for further details.

Parameters:
  • name – Name for this instrument

  • resource – Identifier for this instrument in NI MAX.

  • dll_path – path to the NI-RFSG library DLL. If not provided, use the default location, C:\Program Files\IVI Foundation\IVI\bin\NiRFSG_64.dll.

  • id_query – whether to perform an ID query on initialization

  • reset_device – whether to reset the device on initialization

qcodes_contrib_drivers.drivers.NationalInstruments.RFSG module

qcodes_contrib_drivers.drivers.NationalInstruments.RFSG.NI_RFSG

alias of NationalInstruments_RFSG

class qcodes_contrib_drivers.drivers.NationalInstruments.RFSG.NationalInstruments_RFSG(*args: Any, **kwargs: Any)[source]

Bases: NIDLLInstrument

This is the QCoDeS driver for National Instruments RF signal generator devices based on the NI-RFSG driver. As of NI-RFSG version 18.1, the supported devices are PXI-5610, PXI-5650, PXI-5651, PXI-5652, PXI-5670, PXI-5671, PXIe-5611, PXIe-5644, PXIe-5645, PXIe-5646, PXIe-5650, PXIe-5651, PXIe-5652, PXIe-5653, PXIe-5654, PXIe-5672, PXIe-5673, PXIe-5673E, PXIe-5820, PXIe-5840.

Documentation for the NI-RFSG C API can be found by default in the folder C:UsersPublicDocumentsNational InstrumentsNI-RFSGDocumentation

Only very basic functionality is implemented.

Tested with

  • PXIe-5654

Parameters:
  • name – Name for this instrument

  • resource – Identifier for this instrument in NI MAX.

  • dll_path – path to the NI-RFSG library DLL. If not provided, use the default location, C:\Program Files\IVI Foundation\IVI\bin\NiRFSG_64.dll.

  • id_query – whether to perform an ID query on initialization

  • reset_device – whether to reset the device on initialization

abort()[source]

Stop signal generation and return to the Configuration state.

get_idn()[source]

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Returns:

A dict containing vendor, model, serial, and firmware.

initiate()[source]

Initiate signal generation. This causes the NI-RFSG device to leave the Configuration state.

dll_path = 'C:\\Program Files\\IVI Foundation\\IVI\\bin\\NiRFSG_64.dll'
property firmware: str
property model: str
property serial: str
property vendor: str

qcodes_contrib_drivers.drivers.NationalInstruments.Switch module

class qcodes_contrib_drivers.drivers.NationalInstruments.Switch.NI_Switch(*args: Any, **kwargs: Any)[source]

Bases: Instrument

This is the QCoDeS driver for National Instruments RF switch devices based on the NI-SWITCH driver, using the niswitch module. Parameter s for specific instruments should be defined in subclasses.

This main class mostly just maintains a reference to a niswitch.Session, and holds ChannelList of channels, or ports. Actually making connections between the channels is implemented by the SwitchChannel class.

Tested with

  • NI PXI-2597

Parameters:
  • name – Qcodes name for this instrument

  • resource – Network address or VISA alias for the instrument.

  • name_mapping – Optional mapping from default (“raw”) channel names to custom aliases

  • reset_device – whether to reset the device on initialization

  • niswitch_kw – other keyword arguments passed to the niswitch.Session constructor

close()[source]

Irreversibly stop this instrument and free its resources.

Subclasses should override this if they have other specific resources to close.

disconnect_all() None[source]
get_idn()[source]

Parse a standard VISA *IDN? response into an ID dict.

Even though this is the VISA standard, it applies to various other types as well, such as IPInstruments, so it is included here in the Instrument base class.

Override this if your instrument does not support *IDN? or returns a nonstandard IDN string. This string is supposed to be a comma-separated list of vendor, model, serial, and firmware, but semicolon and colon are also common separators so we accept them here as well.

Returns:

A dict containing vendor, model, serial, and firmware.

class qcodes_contrib_drivers.drivers.NationalInstruments.Switch.SwitchChannel(instrument: NI_Switch, name: str, raw_name: str)[source]

Bases: InstrumentChannel

This class represents one input or output port of a switch instrument.

Parameters:
  • instrument – the instrument to which this port belongs to

  • name – name or alias of this port in the parent instrument’s ChannelList

  • raw_name – name of this port in the driver’s channel table, as given by self._session.get_channel_name

connect_to(other: SwitchChannel) None[source]

Connect this channel to another channel. If either of the channels is already connected to something else, disconnect both channels first. If the channels are already connected to each other, do nothing. If the two channels cannot be connected, raises a DriverError, see the niswitch.Session.connect documentation for further details.

disconnect_from(other: SwitchChannel) None[source]

Disconnect this channel from another chanel. If the channels are not connected, raises a DriverError.

disconnect_from_all() None[source]

Disconnect this channel from all channels it is connected to.

qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper module

This module has some convenience classes and functions for wrapping NI C API calls. Modeled after the DLL calls in the NIMI-python library, see e.g. https://github.com/ni/nimi-python/blob/master/generated/nitclk/nitclk/_library.py

class qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper.AttributeWrapper(value: c_long, dtype: Any)[source]

Bases: object

Struct to associate a data type to a numeric constant (i.e. attribute) defined in a NI DLL library. dtype should be one of the types defined in the visa_types module. Here, value means the same as the attributeID in the DLL documentation.

dtype: Any
value: c_long
class qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper.NIDLLWrapper(dll_path: str, lib_prefix: str)[source]

Bases: object

This class provides convenience functions for wrapping and checking a DLL function call, as well as some premade pythonic wrapper functinos for common library functions such as libName_error_message, libName_init/close and libName_GetAttribute (e.g. niRFSG_init or niSync_init). Other functions should be wrapped by a library-specific class by calling wrap_dll_function_checked. See the NI_RFSG driver for a concrete example.

Parameters:
  • dll_path – path to the DLL file containing the library

  • lib_prefix – All function names in the library start with this. For example, for NI-RFSG, where function names are of the form niRFSG_FunctionName, lib_prefix should be ‘niRFSG’.

error_message(session: c_ulong | None = None, error_code: c_long = c_long(0)) str[source]

Convenience wrapper around libName_error_message (which is wrapped as self._error_message).

get_attribute(session: c_ulong, attr: AttributeWrapper) Any[source]

Get an attribute with data type “DataType” by calling the appropriate “libName_GetAttribute<DataType>” function (for example niRFSG_GetAttributeViReal64 when lib_prefix is “niRFSG” and attr.dtype is ViReal64).

NOTE: channels are not implemented.

init(resource: str, id_query: bool = True, reset_device: bool = False) c_ulong[source]

Convenience wrapper around libName_init (e.g. niRFSG_init). Returns the ViSession handle of the initialized session. The wrapped version of the actual DLL function is registered as self._init, see __init__. Note that this class is not responsible for storing the handle, it should be managed by the function or class that calls the functions wrapped by this class.

Parameters:
  • resource – the resource name of the device to initialize, as given by NI MAX.

  • id_query – whether to perform an ID query on initialization

  • reset_device – whether to reset the device during initialization

Returns:

the ViSession handle of the initialized device

set_attribute(session: c_ulong, attr: AttributeWrapper, set_value: Any) Any[source]

Set an attribute with data type “DataType” by calling the appropriate “libName_SetAttribute<DataType>” function (for example niRFSG_SetAttributeViReal64 when lib_prefix is “niRFSG” and attr.dtype is ViReal64).

NOTE: channels are not implemented.

wrap_dll_function(name_in_library: str, argtypes: ~typing.List[~qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper.NamedArgType], restype: ~typing.Any = <class 'ctypes.c_long'>) Any[source]

Convenience method for wrapping a function in a NI C API.

Parameters:
  • name_in_library – The name of the function in the library (e.g. “niRFSG_init”, or without the prefix, just “init”)

  • argtypes – list of NamedArgType tuples containing the names and types of the arguments of the function to be wrapped.

  • restype – The return type of the library function (most likely ViStatus).

wrap_dll_function_checked(name_in_library: str, argtypes: List[NamedArgType]) Callable[source]

Same as wrap_dll_function, but check the return value and convert it to a Python exception or warning if it is nonzero using self._check_error. The arguments are the same as for wrap_dll_function, except that restype is always ViStatus.

class qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper.NamedArgType(name: str, argtype: Any)[source]

Bases: NamedTuple

Struct for associating a name with an argument type for DLL function signatures.

argtype: Any

Alias for field number 1

name: str

Alias for field number 0

qcodes_contrib_drivers.drivers.NationalInstruments.dll_wrapper.c_str(s: str) bytes[source]

qcodes_contrib_drivers.drivers.NationalInstruments.ni_dll_instrument module

This module contains a small class that mixes features that are common to all libraries in the NIDLLWrapper class with qcodes.Instrument.

class qcodes_contrib_drivers.drivers.NationalInstruments.ni_dll_instrument.NIDLLInstrument(*args: Any, **kwargs: Any)[source]

Bases: Instrument

Common base class for QCoDeS instruments based on NI DLL drivers, when an official NI Python driver (such as nidaqmx or nifpga) is not available. It holds a refence to an NI DLL wrapper object, as well as an instrument handle (ViSession). It handles calling the DLL methods and has some common methods implemented, such as init, close and get_attribute.

Parameters:
  • name – Name for this instrument

  • resource – Identifier for this instrument in NI MAX.

  • dll_path – path to the library DLL.

  • lib_prefix – the prefix of the function names in the library (see NIDLLWrapper)

  • id_query – whether to perform an ID query on initialization

  • reset_device – whether to reset the device on initialization

close()[source]

Irreversibly stop this instrument and free its resources.

Subclasses should override this if they have other specific resources to close.

get_attribute(attr: AttributeWrapper) Any[source]
init(id_query: bool = False, reset_device: bool = False) c_ulong[source]

Call the wrapped init function from the library

Parameters:
  • id_query – whether to perform an ID query

  • reset_device – whether to reset the device

Returns:

the ViSession handle of the initialized device

reset()[source]
set_attribute(attr: AttributeWrapper, set_value: Any)[source]

qcodes_contrib_drivers.drivers.NationalInstruments.visa_types module

Module contents