From d8b66cd63692e22267ec29a2910516f8ce5cb18d Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Thu, 6 Jan 2022 15:44:45 +0100 Subject: [PATCH 01/10] Add signal core driver --- docs/examples/SignalCore.ipynb | 207 ++++++++++++ .../drivers/SignalCore/SignalCore.py | 311 ++++++++++++++++++ .../drivers/SignalCore/__init__.py | 0 3 files changed, 518 insertions(+) create mode 100644 docs/examples/SignalCore.ipynb create mode 100644 qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py create mode 100644 qcodes_contrib_drivers/drivers/SignalCore/__init__.py diff --git a/docs/examples/SignalCore.ipynb b/docs/examples/SignalCore.ipynb new file mode 100644 index 000000000..beec1c65a --- /dev/null +++ b/docs/examples/SignalCore.ipynb @@ -0,0 +1,207 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "nbsphinx": { + "execute": "never" + }, + }, + "source": [ + "# Example with the microwave source SC5521A from Signal Core" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Logging hadn't been started.\n", + "Activating auto-logging. Current session state plus future input saved.\n", + "Filename : C:\\Users\\ed261978\\.qcodes\\logs\\command_history.log\n", + "Mode : append\n", + "Output logging : True\n", + "Raw input log : False\n", + "Timestamping : True\n", + "State : active\n", + "Qcodes Logfile : C:\\Users\\ed261978\\.qcodes\\logs\\210604-4564-qcodes.log\n" + ] + } + ], + "source": [ + "import qcodes as qc\n", + "from qcodes_contrib_drivers.drivers.SignalCore.SignalCore import SC5521A" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Device connection\n", + "\n", + "1. Install the set-up software for your device and computer architecture here: https://www.signalcore.com/40ghz_signal-source.html\n", + "2. This will install the needed DLL in the default path: `C:\\Program Files\\SignalCore\\SC5520A\\api\\c\\scipci\\x64\\sc5520a_uhfs.dll`.\n", + "3. The driver will automatically recognize and connect to the signal core connected to the computer." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Connected to: SignalCore SC5521A (serial:268445854, firmware:2.0199999809265137) in 0.06s\n" + ] + } + ], + "source": [ + "sc = SC5521A('mw1')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mw1:\n", + "\tparameter value\n", + "--------------------------------------------------------------------------------\n", + "IDN :\t{'vendor': 'SignalCore', 'model': 'SC5521A', 'serial': 2684...\n", + "clock_frequency :\t100 (MHz)\n", + "clock_reference :\tinternal \n", + "frequency :\t5e+08 (Hz)\n", + "power :\t0 (dbm)\n", + "rf_mode :\tsingle_tone \n", + "status :\ton \n", + "temperature :\t45.406 (celsius)\n" + ] + } + ], + "source": [ + "sc.print_readable_snapshot(update=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'vendor': 'SignalCore',\n", + " 'model': 'SC5521A',\n", + " 'serial': 268445854,\n", + " 'firmware': 2.0199999809265137,\n", + " 'hardware': 5.0,\n", + " 'manufacture_date': '2021-3-12 at 11h'}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sc.get_idn()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Set parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "sc.frequency(10e9)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10000000000.0" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sc.frequency()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "sc.power(-10)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-10.0" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sc.power()" + ] + } + ], + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py new file mode 100644 index 000000000..06bad480c --- /dev/null +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -0,0 +1,311 @@ +import ctypes +import os +from typing import Dict, Optional +from qcodes import Instrument +from qcodes.utils.validators import Enum + +MAXDEVICES = 50 +MAXDESCRIPTORSIZE = 9 +COMMINTERFACE = ctypes.c_uint8(1) + +class ManDate(ctypes.Structure): + _fields_ = [('year', ctypes.c_uint8), + ('month', ctypes.c_uint8), + ('day', ctypes.c_uint8), + ('hour', ctypes.c_uint8)] + + +class DeviceInfoT(ctypes.Structure): + _fields_ = [('product_serial_number', ctypes.c_uint32), + ('hardware_revision', ctypes.c_float), + ('firmware_revision', ctypes.c_float), + ('device_interfaces', ctypes.c_uint8), + ('man_date', ManDate)] +device_info_t = DeviceInfoT() + + +class ListModeT(ctypes.Structure): + _fields_ = [('sweep_mode', ctypes.c_uint8), + ('sweep_dir', ctypes.c_uint8), + ('tri_waveform', ctypes.c_uint8), + ('hw_trigger', ctypes.c_uint8), + ('step_on_hw_trig', ctypes.c_uint8), + ('return_to_start', ctypes.c_uint8), + ('trig_out_enable', ctypes.c_uint8), + ('trig_out_on_cycle', ctypes.c_uint8)] + + +class PLLStatusT(ctypes.Structure): + _fields_ = [('sum_pll_ld', ctypes.c_uint8), + ('crs_pll_ld', ctypes.c_uint8), + ('fine_pll_ld', ctypes.c_uint8), + ('crs_ref_pll_ld', ctypes.c_uint8), + ('crs_aux_pll_ld', ctypes.c_uint8), + ('ref_100_pll_ld', ctypes.c_uint8), + ('ref_10_pll_ld', ctypes.c_uint8)] + + +class OperateStatusT(ctypes.Structure): + _fields_ = [('rf1_lock_mode', ctypes.c_uint8), + ('rf1_loop_gain', ctypes.c_uint8), + ('device_access', ctypes.c_uint8), + ('device_standby', ctypes.c_uint8), + ('auto_pwr_disable', ctypes.c_uint8), + ('output_enable', ctypes.c_uint8), + ('ext_ref_lock_enable', ctypes.c_uint8), + ('ext_ref_detect', ctypes.c_uint8), + ('ref_out_select', ctypes.c_uint8), + ('list_mode_running', ctypes.c_uint8), + ('rf_mode', ctypes.c_uint8), + ('over_temp', ctypes.c_uint8), + ('harmonic_ss', ctypes.c_uint8), + ('pci_clk_enable', ctypes.c_uint8)] + + +class DeviceStatusT(ctypes.Structure): + _fields_ = [('list_mode_t', ListModeT), + ('operate_status_t', OperateStatusT), + ('pll_status_t', PLLStatusT)] +device_status_t = DeviceStatusT() + + +class HWTriggerT(ctypes.Structure): + _fields_ = [('edge', ctypes.c_uint8), + ('pxi_enable', ctypes.c_uint8), + ('pxi_line', ctypes.c_uint8)] +hw_trigger_t = HWTriggerT() + + +class DeviceRFParamsT(ctypes.Structure): + _fields_ = [('frequency', ctypes.c_double), + ('sweep_start_freq', ctypes.c_double), + ('sweep_stop_freq', ctypes.c_double), + ('sweep_step_freq', ctypes.c_double), + ('sweep_dwell_time', ctypes.c_uint32), + ('sweep_cycles', ctypes.c_uint32), + ('buffer_points', ctypes.c_uint32), + ('rf_phase_offset', ctypes.c_float), + ('power_level', ctypes.c_float), + ('atten_value', ctypes.c_float), + ('level_dac_value', ctypes.c_uint16)] +device_rf_params_t = DeviceRFParamsT() + + +error_dict = {'0':'SCI_SUCCESS', + '0':'SCI_ERROR_NONE', + '-1':'SCI_ERROR_INVALID_DEVICE_HANDLE', + '-2':'SCI_ERROR_NO_DEVICE', + '-3':'SCI_ERROR_INVALID_DEVICE', + '-4':'SCI_ERROR_MEM_UNALLOCATE', + '-5':'SCI_ERROR_MEM_EXCEEDED', + '-6':'SCI_ERROR_INVALID_REG', + '-7':'SCI_ERROR_INVALID_ARGUMENT', + '-8':'SCI_ERROR_COMM_FAIL', + '-9':'SCI_ERROR_OUT_OF_RANGE', + '-10':'SCI_ERROR_PLL_LOCK', + '-11':'SCI_ERROR_TIMED_OUT', + '-12':'SCI_ERROR_COMM_INIT', + '-13':'SCI_ERROR_TIMED_OUT_READ', + '-14':'SCI_ERROR_INVALID_INTERFACE'} + + + +class SC5521A(Instrument): + __doc__ = 'QCoDeS python driver for the Signal Core SC5521A.' + + def __init__(self, name: str, + dll_path: str='SignalCore\\SC5520A\\api\\c\\scipci\\x64\\sc5520a_uhfs.dll', + **kwargs): + """ + QCoDeS driver for the Signal Core SC5521A. + This driver has been tested when only one SignalCore is connected to the + computer. + + Args: + name (str): Name of the instrument. + dll_path (str): Path towards the instrument DLL. + """ + + (super().__init__)(name, **kwargs) + + # Adapt the path to the computer language + dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) + + self._dll = ctypes.WinDLL(dll_path) + self._devices_number = ctypes.c_uint() + self._pxi10Enable = 0 + self._lock_external = 0 + self._clock_frequency = 10 + buffers = [ctypes.create_string_buffer(MAXDESCRIPTORSIZE + 1) for bid in range(MAXDEVICES)] + self.buffer_pointer_array = (ctypes.c_char_p * MAXDEVICES)() + for device in range(MAXDEVICES): + self.buffer_pointer_array[device] = ctypes.cast(buffers[device], ctypes.c_char_p) + + self._buffer_pointer_array_p = ctypes.cast(self.buffer_pointer_array, ctypes.POINTER(ctypes.c_char_p)) + found = self._dll.sc5520a_uhfsSearchDevices(COMMINTERFACE, self._buffer_pointer_array_p, ctypes.byref(self._devices_number)) + if found: + raise RuntimeError('Failed to find any device') + self._open() + + self.add_parameter(name='temperature', + docstring='Return the microwave source internal temperature.', + label='Device temperature', + unit='celsius', + get_cmd=self._get_temperature) + + self.add_parameter(name='status', + docstring='.', + vals=Enum('on', 'off'), + set_cmd=self._set_status, + get_cmd=self._get_status) + + self.add_parameter(name='power', + docstring='.', + label='Power', + unit='dbm', + set_cmd=self._set_power, + get_cmd=self._get_power) + + self.add_parameter(name='frequency', + docstring='.', + label='Frequency', + unit='Hz', + set_cmd=self._set_frequency, + get_cmd=self._get_frequency) + + self.add_parameter(name='rf_mode', + docstring='.', + vals=Enum('single_tone', 'sweep'), + initial_value='single_tone', + set_cmd=self._set_rf_mode, + get_cmd=self._get_rf_mode) + + self.add_parameter(name='clock_frequency', + docstring='Select the internal clock frequency, 10 or 100MHz.', + unit='MHz', + vals=Enum(10, 100), + initial_value=100, + set_cmd=self._set_clock_frequency, + get_cmd=self._get_clock_frequency) + + self.add_parameter(name='clock_reference', + docstring='Select the clock reference, internal or external.', + vals=Enum('internal', 'external'), + initial_value='internal', + set_cmd=self._set_clock_reference, + get_cmd=self._get_clock_reference) + self.connect_message() + + def _open(self) -> None: + self._handle = ctypes.wintypes.HANDLE() + self._dll.sc5520a_uhfsOpenDevice(COMMINTERFACE, self.buffer_pointer_array[0], ctypes.c_uint8(1), ctypes.byref(self._handle)) + + def _close(self) -> None: + self._dll.sc5520a_uhfsCloseDevice(self._handle) + + def _error_handler(self, msg: int) -> None: + """Display error when setting the device fail. + + Args: + msg (int): error key, see error_dict dict. + + Raises: + BaseException + """ + + if msg!=0: + raise BaseException("Couldn't set the devise due to {}.".format(error_dict[str(msg)])) + else: + pass + + def _get_temperature(self) -> float: + temperature = ctypes.c_float() + self._dll.sc5520a_uhfsFetchTemperature(self._handle, ctypes.byref(temperature)) + return temperature.value + + def _set_status(self, status: str) -> None: + if status.lower() == 'on': + status_ = 1 + else: + status_ = 0 + msg = self._dll.sc5520a_uhfsSetOutputEnable(self._handle, ctypes.c_int(status_)) + self._error_handler(msg) + + def _get_status(self) -> str: + self._dll.sc5520a_uhfsFetchDeviceStatus(self._handle, ctypes.byref(device_status_t)) + if device_status_t.operate_status_t.output_enable: + return 'on' + else: + return 'off' + + def _set_power(self, power: float) -> None: + msg = self._dll.sc5520a_uhfsSetPowerLevel(self._handle, ctypes.c_float(power)) + self._error_handler(msg) + + def _get_power(self) -> float: + self._dll.sc5520a_uhfsFetchRfParameters(self._handle, ctypes.byref(device_rf_params_t)) + return device_rf_params_t.power_level + + def _set_frequency(self, frequency: float) -> None: + msg = self._dll.sc5520a_uhfsSetFrequency(self._handle, ctypes.c_double(frequency)) + self._error_handler(msg) + + def _get_frequency(self) -> float: + device_rf_params_t = DeviceRFParamsT() + self._dll.sc5520a_uhfsFetchRfParameters(self._handle, ctypes.byref(device_rf_params_t)) + return float(device_rf_params_t.frequency) + + def _set_clock_frequency(self, clock_frequency: float) -> None: + if clock_frequency == 10: + self._select_high = 0 + else: + self._select_high = 1 + msg = self._dll.sc5520a_uhfsSetReferenceMode(self._handle, ctypes.c_int(self._pxi10Enable), ctypes.c_int(self._select_high), ctypes.c_int(self._lock_external)) + self._error_handler(msg) + + def _get_clock_frequency(self) -> float: + self._dll.sc5520a_uhfsFetchDeviceStatus(self._handle, ctypes.byref(device_status_t)) + ref_out_select = device_status_t.operate_status_t.ref_out_select + if ref_out_select == 1: + return 100 + return 10 + + def _set_clock_reference(self, clock_reference: str) -> None: + if clock_reference.lower() == 'internal': + self._lock_external = 0 + else: + self._lock_external = 1 + msg = self._dll.sc5520a_uhfsSetReferenceMode(self._handle, ctypes.c_int(self._pxi10Enable), ctypes.c_int(self._select_high), ctypes.c_int(self._lock_external)) + self._error_handler(msg) + + def _get_clock_reference(self) -> str: + self._dll.sc5520a_uhfsFetchDeviceStatus(self._handle, ctypes.byref(device_status_t)) + ext_ref_detect = device_status_t.operate_status_t.ext_ref_detect + if ext_ref_detect == 1: + return 'external' + return 'internal' + + def _set_rf_mode(self, rf_mode: str) -> None: + if rf_mode.lower() == 'single_tone': + self.rf_mode_ = 0 + else: + self.rf_mode_ = 1 + msg = self._dll.sc5520a_uhfsSetRfMode(self._handle, ctypes.c_int(self.rf_mode_)) + self._error_handler(msg) + + def _get_rf_mode(self) -> str: + self._dll.sc5520a_uhfsFetchDeviceStatus(self._handle, ctypes.byref(device_status_t)) + rf_mode = device_status_t.operate_status_t.rf_mode + if rf_mode == 0: + return 'single_tone' + return 'sweep' + + def get_idn(self) -> Dict[str, Optional[str]]: + self._dll.sc5520a_uhfsFetchDeviceInfo(self._handle, ctypes.byref(device_info_t)) + + return {'vendor':'SignalCore', + 'model':'SC5521A', + 'serial':device_info_t.product_serial_number, + 'firmware':device_info_t.firmware_revision, + 'hardware':device_info_t.hardware_revision, + 'manufacture_date':'20{}-{}-{} at {}h'.format(device_info_t.man_date.year, device_info_t.man_date.month, device_info_t.man_date.day, device_info_t.man_date.hour)} diff --git a/qcodes_contrib_drivers/drivers/SignalCore/__init__.py b/qcodes_contrib_drivers/drivers/SignalCore/__init__.py new file mode 100644 index 000000000..e69de29bb From b0b2dd1a93da344c3ff2369b9c1b55d1a072bfd0 Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Thu, 6 Jan 2022 16:59:34 +0100 Subject: [PATCH 02/10] Correct the json (remove comma) --- docs/examples/SignalCore.ipynb | 438 ++++++++++++++++++--------------- 1 file changed, 234 insertions(+), 204 deletions(-) diff --git a/docs/examples/SignalCore.ipynb b/docs/examples/SignalCore.ipynb index beec1c65a..14913545f 100644 --- a/docs/examples/SignalCore.ipynb +++ b/docs/examples/SignalCore.ipynb @@ -1,207 +1,237 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "nbsphinx": { - "execute": "never" - }, - }, - "source": [ - "# Example with the microwave source SC5521A from Signal Core" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Logging hadn't been started.\n", - "Activating auto-logging. Current session state plus future input saved.\n", - "Filename : C:\\Users\\ed261978\\.qcodes\\logs\\command_history.log\n", - "Mode : append\n", - "Output logging : True\n", - "Raw input log : False\n", - "Timestamping : True\n", - "State : active\n", - "Qcodes Logfile : C:\\Users\\ed261978\\.qcodes\\logs\\210604-4564-qcodes.log\n" - ] - } + "cells":[ + { + "cell_type":"markdown", + "metadata":{ + "nbsphinx":{ + "execute":"never" + } + }, + "source":[ + "# Example with the microwave source SC5521A from Signal Core" + ] + }, + { + "cell_type":"code", + "execution_count":1, + "metadata":{ + + }, + "outputs":[ + { + "name":"stdout", + "output_type":"stream", + "text":[ + "Logging hadn't been started.\n", + "Activating auto-logging. Current session state plus future input saved.\n", + "Filename : C:\\Users\\ed261978\\.qcodes\\logs\\command_history.log\n", + "Mode : append\n", + "Output logging : True\n", + "Raw input log : False\n", + "Timestamping : True\n", + "State : active\n", + "Qcodes Logfile : C:\\Users\\ed261978\\.qcodes\\logs\\210604-4564-qcodes.log\n" + ] + } + ], + "source":[ + "import qcodes as qc\n", + "from qcodes_contrib_drivers.drivers.SignalCore.SignalCore import SC5521A" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + + }, + "source":[ + "# Device connection\n", + "\n", + "1. Install the set-up software for your device and computer architecture here: https://www.signalcore.com/40ghz_signal-source.html\n", + "2. This will install the needed DLL in the default path: `C:\\Program Files\\SignalCore\\SC5520A\\api\\c\\scipci\\x64\\sc5520a_uhfs.dll`.\n", + "3. The driver will automatically recognize and connect to the signal core connected to the computer." + ] + }, + { + "cell_type":"code", + "execution_count":2, + "metadata":{ + + }, + "outputs":[ + { + "name":"stdout", + "output_type":"stream", + "text":[ + "Connected to: SignalCore SC5521A (serial:268445854, firmware:2.0199999809265137) in 0.06s\n" + ] + } + ], + "source":[ + "sc = SC5521A('mw1')" + ] + }, + { + "cell_type":"code", + "execution_count":3, + "metadata":{ + + }, + "outputs":[ + { + "name":"stdout", + "output_type":"stream", + "text":[ + "mw1:\n", + "\tparameter value\n", + "--------------------------------------------------------------------------------\n", + "IDN :\t{'vendor': 'SignalCore', 'model': 'SC5521A', 'serial': 2684...\n", + "clock_frequency :\t100 (MHz)\n", + "clock_reference :\tinternal \n", + "frequency :\t5e+08 (Hz)\n", + "power :\t0 (dbm)\n", + "rf_mode :\tsingle_tone \n", + "status :\ton \n", + "temperature :\t45.406 (celsius)\n" + ] + } + ], + "source":[ + "sc.print_readable_snapshot(update=True)" + ] + }, + { + "cell_type":"code", + "execution_count":4, + "metadata":{ + + }, + "outputs":[ + { + "data":{ + "text/plain":[ + "{'vendor': 'SignalCore',\n", + " 'model': 'SC5521A',\n", + " 'serial': 268445854,\n", + " 'firmware': 2.0199999809265137,\n", + " 'hardware': 5.0,\n", + " 'manufacture_date': '2021-3-12 at 11h'}" + ] + }, + "execution_count":4, + "metadata":{ + + }, + "output_type":"execute_result" + } + ], + "source":[ + "sc.get_idn()" + ] + }, + { + "cell_type":"markdown", + "metadata":{ + + }, + "source":[ + "# Set parameters" + ] + }, + { + "cell_type":"code", + "execution_count":5, + "metadata":{ + + }, + "outputs":[ + + ], + "source":[ + "sc.frequency(10e9)" + ] + }, + { + "cell_type":"code", + "execution_count":6, + "metadata":{ + + }, + "outputs":[ + { + "data":{ + "text/plain":[ + "10000000000.0" + ] + }, + "execution_count":6, + "metadata":{ + + }, + "output_type":"execute_result" + } + ], + "source":[ + "sc.frequency()" + ] + }, + { + "cell_type":"code", + "execution_count":14, + "metadata":{ + + }, + "outputs":[ + + ], + "source":[ + "sc.power(-10)" + ] + }, + { + "cell_type":"code", + "execution_count":15, + "metadata":{ + + }, + "outputs":[ + { + "data":{ + "text/plain":[ + "-10.0" + ] + }, + "execution_count":15, + "metadata":{ + + }, + "output_type":"execute_result" + } + ], + "source":[ + "sc.power()" + ] + } ], - "source": [ - "import qcodes as qc\n", - "from qcodes_contrib_drivers.drivers.SignalCore.SignalCore import SC5521A" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Device connection\n", - "\n", - "1. Install the set-up software for your device and computer architecture here: https://www.signalcore.com/40ghz_signal-source.html\n", - "2. This will install the needed DLL in the default path: `C:\\Program Files\\SignalCore\\SC5520A\\api\\c\\scipci\\x64\\sc5520a_uhfs.dll`.\n", - "3. The driver will automatically recognize and connect to the signal core connected to the computer." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Connected to: SignalCore SC5521A (serial:268445854, firmware:2.0199999809265137) in 0.06s\n" - ] - } - ], - "source": [ - "sc = SC5521A('mw1')" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "mw1:\n", - "\tparameter value\n", - "--------------------------------------------------------------------------------\n", - "IDN :\t{'vendor': 'SignalCore', 'model': 'SC5521A', 'serial': 2684...\n", - "clock_frequency :\t100 (MHz)\n", - "clock_reference :\tinternal \n", - "frequency :\t5e+08 (Hz)\n", - "power :\t0 (dbm)\n", - "rf_mode :\tsingle_tone \n", - "status :\ton \n", - "temperature :\t45.406 (celsius)\n" - ] - } - ], - "source": [ - "sc.print_readable_snapshot(update=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'vendor': 'SignalCore',\n", - " 'model': 'SC5521A',\n", - " 'serial': 268445854,\n", - " 'firmware': 2.0199999809265137,\n", - " 'hardware': 5.0,\n", - " 'manufacture_date': '2021-3-12 at 11h'}" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sc.get_idn()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Set parameters" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "sc.frequency(10e9)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10000000000.0" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sc.frequency()" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "sc.power(-10)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "-10.0" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sc.power()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 + "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.9" + } }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.9" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat":4, + "nbformat_minor":4 +} \ No newline at end of file From 991ebb5a83b53dcb43cb09783db2a60cedd23e80 Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Thu, 6 Jan 2022 17:00:03 +0100 Subject: [PATCH 03/10] Add exception to ensure windows user of the driver --- .../drivers/SignalCore/SignalCore.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 06bad480c..53fe9b0df 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -1,9 +1,14 @@ import ctypes import os +import sys from typing import Dict, Optional from qcodes import Instrument from qcodes.utils.validators import Enum +# The driver is currently working only on Windows platform +if sys.platform!="win32": + raise EnvironmentError('Driver only worings on windows platform.') + MAXDEVICES = 50 MAXDESCRIPTORSIZE = 9 COMMINTERFACE = ctypes.c_uint8(1) @@ -125,9 +130,9 @@ def __init__(self, name: str, name (str): Name of the instrument. dll_path (str): Path towards the instrument DLL. """ - + (super().__init__)(name, **kwargs) - + # Adapt the path to the computer language dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) @@ -146,40 +151,40 @@ def __init__(self, name: str, if found: raise RuntimeError('Failed to find any device') self._open() - + self.add_parameter(name='temperature', docstring='Return the microwave source internal temperature.', label='Device temperature', unit='celsius', get_cmd=self._get_temperature) - + self.add_parameter(name='status', docstring='.', vals=Enum('on', 'off'), set_cmd=self._set_status, get_cmd=self._get_status) - + self.add_parameter(name='power', docstring='.', label='Power', unit='dbm', set_cmd=self._set_power, get_cmd=self._get_power) - + self.add_parameter(name='frequency', docstring='.', label='Frequency', unit='Hz', set_cmd=self._set_frequency, get_cmd=self._get_frequency) - + self.add_parameter(name='rf_mode', docstring='.', vals=Enum('single_tone', 'sweep'), initial_value='single_tone', set_cmd=self._set_rf_mode, get_cmd=self._get_rf_mode) - + self.add_parameter(name='clock_frequency', docstring='Select the internal clock frequency, 10 or 100MHz.', unit='MHz', @@ -187,7 +192,7 @@ def __init__(self, name: str, initial_value=100, set_cmd=self._set_clock_frequency, get_cmd=self._get_clock_frequency) - + self.add_parameter(name='clock_reference', docstring='Select the clock reference, internal or external.', vals=Enum('internal', 'external'), @@ -212,7 +217,7 @@ def _error_handler(self, msg: int) -> None: Raises: BaseException """ - + if msg!=0: raise BaseException("Couldn't set the devise due to {}.".format(error_dict[str(msg)])) else: From a4e172760878bb375155696b6c890b257e3115c6 Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Fri, 7 Jan 2022 10:43:20 +0100 Subject: [PATCH 04/10] 2nd try to make mypy happy --- .../drivers/SignalCore/SignalCore.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 53fe9b0df..46b51cdfa 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -5,10 +5,6 @@ from qcodes import Instrument from qcodes.utils.validators import Enum -# The driver is currently working only on Windows platform -if sys.platform!="win32": - raise EnvironmentError('Driver only worings on windows platform.') - MAXDEVICES = 50 MAXDESCRIPTORSIZE = 9 COMMINTERFACE = ctypes.c_uint8(1) @@ -133,10 +129,13 @@ def __init__(self, name: str, (super().__init__)(name, **kwargs) - # Adapt the path to the computer language - dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) - - self._dll = ctypes.WinDLL(dll_path) + # The driver is currently working only on Windows platform + if sys.platform=='win32': + # Adapt the path to the computer language + dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) + self._dll = ctypes.WinDLL(dll_path) + else: + raise EnvironmentError('Driver only worings on windows platform.') self._devices_number = ctypes.c_uint() self._pxi10Enable = 0 self._lock_external = 0 @@ -202,7 +201,12 @@ def __init__(self, name: str, self.connect_message() def _open(self) -> None: - self._handle = ctypes.wintypes.HANDLE() + # The driver is currently working only on Windows platform + if sys.platform=='win32': + self._handle = ctypes.wintypes.HANDLE() + else: + raise EnvironmentError('Driver only worings on windows platform.') + self._dll.sc5520a_uhfsOpenDevice(COMMINTERFACE, self.buffer_pointer_array[0], ctypes.c_uint8(1), ctypes.byref(self._handle)) def _close(self) -> None: From 64380116e5cd6023f5c12c7bc7fd5a0c0a764692 Mon Sep 17 00:00:00 2001 From: Etienne Dumur Date: Fri, 7 Jan 2022 10:51:00 +0100 Subject: [PATCH 05/10] 3rd try to make mypy happy --- .../drivers/SignalCore/SignalCore.py | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 46b51cdfa..21fbd87c0 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -5,6 +5,11 @@ from qcodes import Instrument from qcodes.utils.validators import Enum + +# The driver is currently working only on Windows platform +assert sys.platform=='win32' + + MAXDEVICES = 50 MAXDESCRIPTORSIZE = 9 COMMINTERFACE = ctypes.c_uint8(1) @@ -129,13 +134,10 @@ def __init__(self, name: str, (super().__init__)(name, **kwargs) - # The driver is currently working only on Windows platform - if sys.platform=='win32': - # Adapt the path to the computer language - dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) - self._dll = ctypes.WinDLL(dll_path) - else: - raise EnvironmentError('Driver only worings on windows platform.') + # Adapt the path to the computer language + dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) + + self._dll = ctypes.WinDLL(dll_path) self._devices_number = ctypes.c_uint() self._pxi10Enable = 0 self._lock_external = 0 @@ -201,12 +203,7 @@ def __init__(self, name: str, self.connect_message() def _open(self) -> None: - # The driver is currently working only on Windows platform - if sys.platform=='win32': - self._handle = ctypes.wintypes.HANDLE() - else: - raise EnvironmentError('Driver only worings on windows platform.') - + self._handle = ctypes.wintypes.HANDLE() self._dll.sc5520a_uhfsOpenDevice(COMMINTERFACE, self.buffer_pointer_array[0], ctypes.c_uint8(1), ctypes.byref(self._handle)) def _close(self) -> None: From 1a5f89aee6fd18f96ecfaa5378fa148fd569fbb4 Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 7 Jan 2022 11:29:18 +0100 Subject: [PATCH 06/10] try asserting windows platform in driver init --- qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 21fbd87c0..2dd876143 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -6,10 +6,6 @@ from qcodes.utils.validators import Enum -# The driver is currently working only on Windows platform -assert sys.platform=='win32' - - MAXDEVICES = 50 MAXDESCRIPTORSIZE = 9 COMMINTERFACE = ctypes.c_uint8(1) @@ -137,7 +133,10 @@ def __init__(self, name: str, # Adapt the path to the computer language dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) + assert sys.platform == "win32", f"{self.__class__.__name__} is supported only on Windows platform" + self._dll = ctypes.WinDLL(dll_path) + self._devices_number = ctypes.c_uint() self._pxi10Enable = 0 self._lock_external = 0 From 5d821089abfeff62cc5ebc284df307dc8a664990 Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 7 Jan 2022 11:38:37 +0100 Subject: [PATCH 07/10] fix mypy attempt 6 --- qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 2dd876143..6df3f6b19 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -133,9 +133,10 @@ def __init__(self, name: str, # Adapt the path to the computer language dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) - assert sys.platform == "win32", f"{self.__class__.__name__} is supported only on Windows platform" - - self._dll = ctypes.WinDLL(dll_path) + if sys.platform == 'win32': + self._dll = ctypes.WinDLL(dll_path) + else: + raise EnvironmentError(f"{self.__class__.__name__} is supported only on Windows platform") self._devices_number = ctypes.c_uint() self._pxi10Enable = 0 From 8e68f0a6619c1146776cf77dc77c175116370288 Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 7 Jan 2022 11:43:39 +0100 Subject: [PATCH 08/10] move around --- .../drivers/SignalCore/SignalCore.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index 6df3f6b19..be1c676f0 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -130,14 +130,6 @@ def __init__(self, name: str, (super().__init__)(name, **kwargs) - # Adapt the path to the computer language - dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) - - if sys.platform == 'win32': - self._dll = ctypes.WinDLL(dll_path) - else: - raise EnvironmentError(f"{self.__class__.__name__} is supported only on Windows platform") - self._devices_number = ctypes.c_uint() self._pxi10Enable = 0 self._lock_external = 0 @@ -148,6 +140,14 @@ def __init__(self, name: str, self.buffer_pointer_array[device] = ctypes.cast(buffers[device], ctypes.c_char_p) self._buffer_pointer_array_p = ctypes.cast(self.buffer_pointer_array, ctypes.POINTER(ctypes.c_char_p)) + + # Adapt the path to the computer language + dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) + if sys.platform == 'win32': + self._dll = ctypes.WinDLL(dll_path) + else: + raise EnvironmentError(f"{self.__class__.__name__} is supported only on Windows platform") + found = self._dll.sc5520a_uhfsSearchDevices(COMMINTERFACE, self._buffer_pointer_array_p, ctypes.byref(self._devices_number)) if found: raise RuntimeError('Failed to find any device') From 8d13e8141a24e92e50ec12691a87768a5b4adb0a Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 7 Jan 2022 11:47:09 +0100 Subject: [PATCH 09/10] dll_path is os specific --- qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py index be1c676f0..2a4b220ca 100644 --- a/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py +++ b/qcodes_contrib_drivers/drivers/SignalCore/SignalCore.py @@ -142,8 +142,8 @@ def __init__(self, name: str, self._buffer_pointer_array_p = ctypes.cast(self.buffer_pointer_array, ctypes.POINTER(ctypes.c_char_p)) # Adapt the path to the computer language - dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) if sys.platform == 'win32': + dll_path = os.path.join(os.environ['PROGRAMFILES'], dll_path) self._dll = ctypes.WinDLL(dll_path) else: raise EnvironmentError(f"{self.__class__.__name__} is supported only on Windows platform") From d39a275839911107c1903555b515656598f7e26b Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 7 Jan 2022 11:56:54 +0100 Subject: [PATCH 10/10] add nbshipnx execute never to the whole notebook --- docs/examples/SignalCore.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/examples/SignalCore.ipynb b/docs/examples/SignalCore.ipynb index 14913545f..9e05616be 100644 --- a/docs/examples/SignalCore.ipynb +++ b/docs/examples/SignalCore.ipynb @@ -219,6 +219,9 @@ "language":"python", "name":"python3" }, + "nbsphinx":{ + "execute":"never" + }, "language_info":{ "codemirror_mode":{ "name":"ipython", @@ -234,4 +237,4 @@ }, "nbformat":4, "nbformat_minor":4 -} \ No newline at end of file +}