Source code for qcodes.instrument_drivers.Minicircuits._minicircuits_usb_spdt
importosfromtypingimportTYPE_CHECKING# QCoDeS importsfromqcodes.instrument_drivers.Minicircuits.Base_SPDTimport(MiniCircuitsSPDTBase,MiniCircuitsSPDTSwitchChannelBase,)ifTYPE_CHECKING:fromtyping_extensionsimportUnpackfromqcodes.instrumentimportInstrumentBaseKWArgstry:importclr# pyright: ignore[reportMissingTypeStubs,reportMissingImports]exceptImportError:raiseImportError("""Module clr not found. Please obtain it by running 'pip install pythonnet' in a qcodes environment terminal""")
[docs]classMiniCircuitsUsbSPDT(MiniCircuitsSPDTBase):CHANNEL_CLASS=MiniCircuitsUsbSPDTSwitchChannelPATH_TO_DRIVER=r"mcl_RF_Switch_Controller64"PATH_TO_DRIVER_45=r"mcl_RF_Switch_Controller_NET45"def__init__(self,name:str,driver_path:str|None=None,serial_number:str|None=None,**kwargs:"Unpack[InstrumentBaseKWArgs]",):""" Mini-Circuits SPDT RF switch Args: name: the name of the instrument driver_path: path to the dll serial_number: the serial number of the device (printed on the sticker on the back side, without s/n) kwargs: kwargs to be passed to Instrument class. """# import .net exception so we can catch it below# we keep this import local so that the module can be imported# without a working .net installclr.AddReference("System.IO")fromSystem.IOimport(# pyright: ignore[reportMissingImports]FileNotFoundException,)super().__init__(name,**kwargs)ifos.name!="nt":raiseImportError("""This driver only works in Windows.""")try:ifdriver_pathisNone:try:clr.AddReference(self.PATH_TO_DRIVER)exceptFileNotFoundError:clr.AddReference(self.PATH_TO_DRIVER_45)else:clr.AddReference(driver_path)except(ImportError,FileNotFoundException):raiseImportError("""Load of mcl_RF_Switch_Controller64.dll or mcl_RF_Switch_Controller_NET45.dll not possible. Make sure the dll file is not blocked by Windows. To unblock right-click the dll to open properties and check the 'unblock' checkmark in the bottom. Check that your python installation is 64bit.""")try:importmcl_RF_Switch_Controller64asmw_driver# pyright: ignore[reportMissingImports]exceptImportError:importmcl_RF_Switch_Controller_NET45asmw_driver# pyright: ignore[reportMissingImports]self.switch=mw_driver.USB_RF_SwitchBox()ifnotself.switch.Connect(serial_number):raiseRuntimeError("Could not connect to device")self.address=self.switch.Get_Address()self.serial_number=self.switch.Read_SN("")[1]self.connect_message()self.add_channels()
[docs]defget_idn(self)->dict[str,str|None]:# the arguments in those functions is the serial number or none if# there is only one switch.fw=self.switch.GetFirmware()MN=self.switch.Read_ModelName("")[1]SN=self.switch.Read_SN("")[1]id_dict={"firmware":fw,"model":MN,"serial":SN,"vendor":"Mini-Circuits"}returnid_dict