nibcq.Device

class nibcq.Device(device_family: nibcq.enums.DeviceFamily)

Class to represent and manage hardware device configurations.

Handles connection and communication with National Instruments measurement devices including Digital Multimeters (DMM) and Source Measure Units (SMU). Provides device validation, session management, and hardware abstraction for measurement operations.

Parameters:

device_family (nibcq.enums.DeviceFamily)

session

The active session object for communication with the hardware device.

Type:

nidmm.Session | nidcpower.Session

property product: str

Get the product model name of the connected device.

Returns the instrument model string as reported by the device driver. This is typically the full product name including manufacturer and model number.

Returns:

The product model name (e.g., “NI PXIe-4139”, “NI PXI-4071”)

Return type:

str

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> print(device.product)
"NI PXIe-4139"
property serial_number: str

Get the device serial number in raw format without leading zeros.

Returns the serial number as reported directly by the device driver, without any formatting modifications. For simulated devices, this typically returns “0”.

Returns:

The raw serial number without leading zero padding

Return type:

str

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> print(device.serial_number)
"12345678"  # or "0" for simulated devices
property device_family: nibcq.enums.DeviceFamily

Get the device family type of the connected device.

Returns the DeviceFamily enum value indicating whether this device is a Digital Multimeter (DMM) or Source Measure Unit (SMU). This information is useful for determining available functionality and measurement capabilities.

Returns:

The device family enum (DeviceFamily.DMM or DeviceFamily.SMU)

Return type:

DeviceFamily

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> print(device.device_family)
DeviceFamily.SMU
>>> if device.device_family == DeviceFamily.SMU:
...     print("This is a Source Measure Unit")
property full_serial_number: str

Get the device serial number formatted with leading zeros.

Returns the serial number padded to 8 characters with leading zeros for consistency with file naming conventions and device identification. For simulated devices (serial number “0”), returns “0” without padding.

Returns:

The serial number padded to 8 characters with leading zeros,

or “0” for simulated devices

Return type:

str

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> print(device.full_serial_number)
"12345678"  # Raw: "12345678"
>>> print(device.full_serial_number)
"00001234"  # Raw: "1234"
>>> print(device.full_serial_number)
"0"         # Raw: "0" (simulated)
property is_closed

Get the current session state of the device.

Returns whether the device session has been closed. A closed device cannot be used for measurements and must be reconnected to resume operation. This property is useful for session management and resource cleanup.

Returns:

True if the device session is closed, False if active

Return type:

bool

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> print(device.is_closed)
False
>>> device.close()
>>> print(device.is_closed)
True
static is_supported(device_type: nibcq.enums.DeviceFamily, device_to_check: str = None) bool

Check if a device product type is supported by the nibcq package.

Validates whether the specified device model is included in the list of supported instruments for the given device family. This is used during device initialization to ensure compatibility.

Parameters:
  • device_type (DeviceFamily) – The device family to check against (DeviceFamily.DMM or DeviceFamily.SMU).

  • device_to_check (str, optional) – The product model name to validate. Should match the instrument_model string from the device driver.

Returns:

True if the device is supported, False otherwise

Return type:

bool

Raises:

ValueError – If device_type is not a valid DeviceFamily enum value

Examples

>>> Device.is_supported(DeviceFamily.SMU, "NI PXIe-4139")
True
>>> Device.is_supported(DeviceFamily.DMM, "NI PXI-4071")
True
>>> Device.is_supported(DeviceFamily.SMU, "Unsupported Model")
False
connect(resource_name: str, options: str = '')

Connect this device instance to actual hardware.

Establishes a session with the specified hardware instrument. This instance method allows you to create a device object first and then connect it later.

Parameters:
  • resource_name (str) – The VISA resource name of the device to connect to. Example: “PXI1Slot2” or “Dev1”.

  • options (str, optional) – Additional connection options for the VISA session. Defaults to empty string for standard connection.

Returns:

Self (for method chaining)

Return type:

Device

Raises:
  • RuntimeError – If connection to the device fails or device already connected

  • ValueError – If the device is not supported

  • nidmm.errors.DriverError – If DMM-specific driver errors occur

  • nidcpower.errors.DriverError – If SMU-specific driver errors occur

Examples

>>> device = Device(DeviceFamily.SMU)
>>> device.connect("PXI1Slot2")
>>> # Or with method chaining:
>>> device = Device(DeviceFamily.SMU).connect("PXI1Slot2")
classmethod create(device_family: nibcq.enums.DeviceFamily, resource_name: str, options: str = '')

Create a new Device instance and connect it to hardware in one step.

Alternative constructor that provides a convenient interface for creating and connecting devices in a single call. This is equivalent to calling Device(device_family).connect(resource_name, options).

Parameters:
  • device_family (DeviceFamily) – The type of device (DMM or SMU) to connect to. Must be a valid DeviceFamily enum value.

  • resource_name (str) – The VISA resource name of the device to connect to. Example: “PXI1Slot2” or “Dev1”.

  • options (str, optional) – Additional connection options for the VISA session. Defaults to empty string for standard connection.

Returns:

A new Device instance connected to the specified instrument

Return type:

Device

Raises:
  • RuntimeError – If connection to the device fails

  • ValueError – If the device is not supported

  • nidmm.errors.DriverError – If DMM-specific driver errors occur

  • nidcpower.errors.DriverError – If SMU-specific driver errors occur

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> device = Device.create(DeviceFamily.DMM, "Dev1", "Simulate=1")
close()

Close the device session and release hardware resources.

Properly terminates the connection to the device and marks the session as closed. After calling this method, the device cannot be used for measurements until a new connection is established. This method should be called when finished with the device to ensure proper resource cleanup.

Raises:
  • nidmm.errors.DriverError – If DMM-specific errors occur during closure

  • nidcpower.errors.DriverError – If SMU-specific errors occur during closure

Examples

>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2")
>>> # ... perform measurements ...
>>> device.close()
>>> print(device.is_closed)
True
__enter__()

Enter the runtime context for use with ‘with’ statements.

Enables the Device class to be used as a context manager, allowing automatic resource management through Python’s ‘with’ statement. The device session will be automatically closed when exiting the context, even if an exception occurs.

Returns:

The Device instance for use within the context

Return type:

Device

Examples

>>> with Device.create(DeviceFamily.SMU, "PXI1Slot2") as device:
...     # Use device for measurements
...     result = device.session.measure()
# Device is automatically closed here
__exit__(exc_type, exc_value, traceback)

Exit the runtime context and ensure proper resource cleanup.

Automatically closes the device session when exiting a ‘with’ statement context. This ensures that hardware resources are properly released regardless of whether the context was exited normally or due to an exception.

Parameters:
  • exc_type – The exception type if an exception occurred, None otherwise

  • exc_value – The exception instance if an exception occurred, None otherwise

  • traceback – The traceback object if an exception occurred, None otherwise

Returns:

False to allow any exception that occurred to propagate normally

Return type:

bool

Examples

>>> with Device(DeviceFamily.SMU, "PXI1Slot2") as device:
...     raise ValueError("Something went wrong")
# Device is still properly closed despite the exception
property default_calibration_path

Get the default calibration file path for the connected device.

Generates the default calibration diary file path based on the device’s full serial number and the toolkit folder structure. This path is used when no specific calibration file path is provided during initialization.

Returns:

The default calibration file path in the format:

{TOOLKIT_FOLDER}/Calibration/{serial_number}_calibration_log.csv

Return type:

str

Raises:

RuntimeError – If the device is not initialized

Examples

>>> measurement = Measurement(device)
>>> print(measurement.default_calibration_path)
"/path/to/toolkit/Calibration/12345678_calibration_log.csv"
with_temperature(thermocouple_settings: nibcq.temperature.ThermocoupleSettings, temperature_delta: float = math.nan)

Add temperature measurement capability to this device.

Parameters:
Returns:

This device instance for method chaining

Examples

>>> from nibcq.temperature import ThermocoupleSettings
>>> settings = ThermocoupleSettings("Dev1/ai0")
>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2").with_temperature(settings)
with_switching(config: nibcq.switch.SwitchConfiguration, sense_switch_resource_name: str, source_switch_resource_name: str | None = None, dmm_terminal_channel: str | None = None, dmm_switch_type: nibcq.enums.SwitchDeviceType | None = None)

Add switching capability to this device.

Enables multiplexer switching functionality for sequential testing of multiple DUTs. The device will support automatic channel switching based on the switch configuration.

Parameters:
  • sense_switch_resource_name (str) – The resource name of the sense switch. This is a VISA resource name. Defining this is manditory. In case of a DMM device, this defines the main switch, and in case of SMU devices, this is connected to the terminal responsible for sensing back the source signal impact.

  • source_switch_resource_name (Optional[str]) – The resource name of the source switch. This is a VISA resource name. It is optional, as only SMU Devices require a source switch. This is the switch connected to the source terminal of the SMU.

  • dmm_terminal_channel (Optional[str]) – The terminal channel connecting the switch to the DMM.

  • dmm_switch_type (Optional[str]) – The type of the switch being connected to the DMM.

  • config (SwitchConfiguration) – The switch configuration object containing topology, channel definitions, and DUT information.

Returns:

This device instance for method chaining

Raises:
  • ValueError – If switching is not supported for this device family or it was incorrectly set up.

  • FileNotFoundError – If configuration file doesn’t exist

Examples

>>> device = Device.create(DeviceFamily.DMM, "Dev1").with_switching(
...     "switch_config.json"
... )
>>> device = Device.create(DeviceFamily.SMU, "PXI1Slot2").with_switching(
...     "smu_switch.json"
... )