{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Qcodes example for National Instruments PXIe-2597 RF Switch" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qcodes_contrib_drivers.drivers.NationalInstruments.PXIe_2597 import NI_PXIe_2597" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected to: National Instruments PXI-2597 (serial:1DBFD38, firmware:Not Available) in 6.85s\n", "All channels: ['ch1', 'ch2', 'ch3', 'ch4', 'ch5', 'ch6', 'com']\n", "Initially connected to: ch3\n" ] } ], "source": [ "dev = NI_PXIe_2597(\"Switch\", resource=\"RF_switch\")\n", "\n", "print('All channels:', [ch.short_name for ch in dev.channels])\n", "print('Initially connected to:', dev.channel())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect different channels on the switch\n", "\n", "The main way of connecting channels is the `channel` parameter." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Now connected to: ch3\n", "Now connected to: None\n", "Now connected to: ch1\n", "Now connected to: None\n" ] } ], "source": [ "dev.channel(\"ch3\")\n", "print('Now connected to:', dev.channel())\n", "\n", "# disconnect by setting to None\n", "dev.channel(None)\n", "print('Now connected to:', dev.channel())\n", "\n", "dev.channel(\"ch1\")\n", "print('Now connected to:', dev.channel())\n", "\n", "# or by using disconnect_all\n", "dev.disconnect_all()\n", "print('Now connected to:', dev.channel())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected to: ch1\n" ] } ], "source": [ "dev.channels.ch1.connect_to(dev.channels.com)\n", "print(\"Connected to:\", dev.channel())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can check which channels are connected to which using the `connections` parameter of a channel. Disconnected channels return an empty list." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ch1 is connected to ['com']\n", "com is connected to ['ch1']\n", "ch2 is connected to []\n" ] } ], "source": [ "dev.channel(\"ch1\")\n", "print(\"ch1 is connected to\", dev.channels.ch1.connections())\n", "print(\"com is connected to\", dev.channels.com.connections())\n", "print(\"ch2 is connected to\", dev.channels.ch2.connections())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Aliasing channel names" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected to: National Instruments PXI-2597 (serial:1DBFD38, firmware:Not Available) in 2.28s\n", "Now connected to: Main channel\n", "Now connected to: Qubit channel\n", "(\"'Undefined channel' is not in {'ch5', 'ch2', 'ch4', 'Qubit channel', None, 'ch6', 'Main channel'}; Parameter: Switch.channel\", 'setting Switch_channel to Undefined channel')\n" ] } ], "source": [ "name_mapping = {'ch1': 'Main channel',\n", " 'ch3': 'Qubit channel'}\n", "\n", "dev.close()\n", "\n", "dev = NI_PXIe_2597(\"Switch\", resource=\"RF_switch\",\n", " name_mapping=name_mapping)\n", "\n", "dev.channel('Main channel')\n", "print('Now connected to:', dev.channel())\n", "\n", "dev.channel('Qubit channel')\n", "print('Now connected to:', dev.channel())\n", "\n", "# non-existent channel throws an error\n", "try:\n", " dev.channel('Undefined channel')\n", "except ValueError as e:\n", " print(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Print a snapshot" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Switch:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "IDN :\t{'vendor': 'National Instruments', 'model': 'PXI-2597', 'serial': '...\n", "channel :\tQubit channel \n", "Switch_Main channel:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t['com'] \n", "Switch_ch2:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t[] \n", "Switch_Qubit channel:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t[] \n", "Switch_ch4:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t[] \n", "Switch_ch5:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t[] \n", "Switch_ch6:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t[] \n", "Switch_com:\n", "\tparameter value\n", "--------------------------------------------------------------------------------\n", "connections :\t['Main channel'] \n" ] } ], "source": [ "dev.print_readable_snapshot()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "dev.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" }, "nbsphinx": { "execute": "never" } }, "nbformat": 4, "nbformat_minor": 4 }