Qcodes example for National Instruments PXIe-2597 RF Switch

from qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_2597 import NI_PXIe_2597

The PXIe-2597 has a multiplexer configuration. It connects the common com port to one of 6 ports. Default channel names are "ch#". We connect to the device using the VISA alias RF_switch assigned in NI MAX.

dev = NI_PXIe_2597("Switch", resource="RF_switch")

print('All channels:', [ch.short_name for ch in dev.channels])
print('Initially connected to:',  dev.channel())
Connected to: National Instruments PXI-2597 (serial:1DBFD38, firmware:Not Available) in 6.85s
All channels: ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'com']
Initially connected to: ch3

Connect different channels on the switch

The main way of connecting channels is the channel parameter.

print('Now connected to:', dev.channel())

# disconnect by setting to None
print('Now connected to:', dev.channel())

print('Now connected to:', dev.channel())

# or by using disconnect_all
print('Now connected to:', dev.channel())
Now connected to: ch3
Now connected to: None
Now connected to: ch1
Now connected to: None

Channels may be also connected using their connect_to method, although it doesn’t make much sense for the PXI-2597, which can have one connection at a time anyway.

print("Connected to:", dev.channel())
Connected to: ch1

You can check which channels are connected to which using the connections parameter of a channel. Disconnected channels return an empty list.

print("ch1 is connected to", dev.channels.ch1.connections())
print("com is connected to", dev.channels.com.connections())
print("ch2 is connected to", dev.channels.ch2.connections())
ch1 is connected to ['com']
com is connected to ['ch1']
ch2 is connected to []

Aliasing channel names

You may also provide a dict of aliases for more memorable channel names. This can be also set up in the station YAML file. Note that if you want to use the channel as a setpoint in a measurement, it should be a valid Python identifier (unlike in the example below). The com port cannot be aliased.

name_mapping = {'ch1': 'Main channel',
                'ch3': 'Qubit channel'}


dev = NI_PXIe_2597("Switch", resource="RF_switch",

dev.channel('Main channel')
print('Now connected to:', dev.channel())

dev.channel('Qubit channel')
print('Now connected to:', dev.channel())

# non-existent channel throws an error
    dev.channel('Undefined channel')
except ValueError as e:
Connected to: National Instruments PXI-2597 (serial:1DBFD38, firmware:Not Available) in 2.28s
Now connected to: Main channel
Now connected to: Qubit channel
("'Undefined channel' is not in {'ch5', 'ch2', 'ch4', 'Qubit channel', None, 'ch6', 'Main channel'}; Parameter: Switch.channel", 'setting Switch_channel to Undefined channel')