def visible(self) -> t.List[str]: """Get a list of devices visible to the data server. Returns: List of all connected devices. """ return ziPython.ziDiscovery().findAll()
def _create_device(self, serial: str) -> tk_devices.BaseInstrument: """Creates a new device object. Maps the device type to the correct instrument class (The default is the ``BaseInstrument`` which is a generic instrument class that supports all devices). Warning: The device must already be connected to the data server Args: serial: Device serial Returns: Newly created instrument object Raises: RuntimeError: If the device is not connected to the data server """ try: return super()._create_device(serial) except RuntimeError as error: if "ZIAPINotFoundException" in error.args[0]: discovery = ziPython.ziDiscovery() discovery.find(serial) dev_type = discovery.get(serial)["devicetype"] raise RuntimeError( "Can only connect HF2 devices to an HF2 data " f"server. {serial} identifies itself as a {dev_type}." ) from error raise
def _discover(self): """Run API discovery routines, and return port and apilevel to allow connection""" try: disc = ziPython.ziDiscovery() device = disc.findAll()[0] dev_info = disc.get(device) port = dev_info['serverport'] apilevel = dev_info['apilevel'] self._name = dev_info['deviceid'].lower() self.last_action = 'Lock-in found' return port, apilevel except Exception as e: self.last_action = 'Lock-in not found. %s' % (str(e)) return 8005, 1
def __init__( self, name: str, device_type: DeviceTypes, serial: str, discovery=None, **kwargs ) -> None: if not isinstance(serial, str): _logger.error( f"Serial must be a string", _logger.ExceptionTypes.ToolkitError ) self._config = InstrumentConfiguration() self._config.instrument.name = name self._config.instrument.config.device_type = device_type self._config.instrument.config.serial = serial self._config.instrument.config.interface = kwargs.get("interface", "1GbE") self._config.api_config.host = kwargs.get("host", "localhost") self._config.api_config.port = kwargs.get("port", 8004) self._config.api_config.api = kwargs.get("api", 6) self._controller = DeviceConnection( self, discovery if discovery is not None else zi.ziDiscovery() ) self._nodetree = None self._options = None
def __init__(self, dev='DEV8040'): # Start ZI DAQ server self._discovery = zi.ziDiscovery() self.device_id = self._discovery.find(dev) device_props = self._discovery.get(self.device_id)
def UHF_init_demod(device_id = 'dev2148', demod_c = 0, out_c = 0): """ Connecting to the device specified by device_id and setting initial parameters through LabOne GUI Arguments: device_id (str): The ID of the device to run the example with. For example, 'dev2148'. demod_c (int): One of {0 - 7} demodulators of UHF LI out_c (int): One of {0,1} output channels of UHF LI Raises: RuntimeError: If the device is not connected to the Data Server. """ global daq # Creating global variable for accesing the UHFLI from other functions global device # Creating global variable for accesing the UHFLI from other functions # Create an instance of the ziDiscovery class. d = ziPython.ziDiscovery() # Determine the device identifier from it's ID. device = d.find(device_id).lower() # Get the device's default connectivity properties. props = d.get(device) # The maximum API level supported by this example. apilevel_example = 5 # The maximum API level supported by the device class, e.g., MF. apilevel_device = props['apilevel'] # Ensure we run the example using a supported API level. apilevel = min(apilevel_device, apilevel_example) # See the LabOne Programming Manual for an explanation of API levels. # Create a connection to a Zurich Instruments Data Server (an API session) # using the device's default connectivity properties. daq = ziPython.ziDAQServer(props['serveraddress'], props['serverport'], apilevel) # Check that the device is visible to the Data Server if device not in utils.devices(daq): raise RuntimeError("The specified device `%s` is not visible to the Data Server, " % device_id + "please ensure the device is connected by using the LabOne User Interface " + "or ziControl (HF2 Instruments).") # find out whether the device is an HF2 or a UHF devtype = daq.getByte('/%s/features/devtype' % device) options = daq.getByte('/%s/features/options' % device) # Create a base configuration: disable all outputs, demods and scopes general_setting = [ ['/%s/demods/*/rate' % device, 0], ['/%s/demods/*/trigger' % device, 0], ['/%s/sigouts/*/enables/*' % device, 0]] if re.match('HF2', devtype): general_setting.append(['/%s/scopes/*/trigchannel' % device, -1]) else: # UHFLI pass #general_setting.append(['/%s/demods/*/enable' % device, 0]) #general_setting.append(['/%s/scopes/*/enable' % device, 0]) daq.set(general_setting) raw_input("Set the UHF LI parameters in user interface dialog! Press enter to continue...") # Wait for user to set the device parametrs from user interface daq.setInt('/%s/demods/%s/enable' % (device, demod_c) , 1) # Enable demodulator daq.setInt('/%s/demods/%s/rate' % (device, demod_c), 100000) # Set the demodulator sampling rate # Unsubscribe any streaming data daq.unsubscribe('*') # Path to UHF LI readout node made globally for using in other functions global path_demod path_demod = '/%s/demods/%d/sample' % (device, demod_c) global path_demod_enable path_demod_enable = '/%s/demods/%d/enable' % (device, demod_c) # Path to UHF LI demodulator trigger node made globally for using in other functions global path_demod_trig path_demod_trig = '/%s/demods/%d/trigger' % (device, demod_c) # Perform a global synchronisation between the device and the data server: # Ensure that 1. the settings have taken effect on the device before issuing # the poll() command and 2. clear the API's data buffers. Note: the sync() # must be issued after waiting for the demodulator filter to settle above. daq.sync() # Subscribe to the demodulator's sample path = path_demod daq.subscribe(path) # Get output amplitude # made globally for using in other functions global out_ampl out_ampl = daq.getDouble('/%s/sigouts/%s/amplitudes/3' % (device, out_c))/np.sqrt(2) # Get sampling rate # made globally for using in other functions global sampling_rate sampling_rate = daq.getDouble('/%s/demods/%s/rate' % (device, demod_c)) # Get time constant in seconds # made globally for using in other functions global TC TC = daq.getDouble('/%s/demods/%s/timeconstant' % (device, demod_c))
def UHF_init_scope(device_id = 'dev2148'): """ Connecting to the device specified by device_id and setting initial parameters through LabOne GUI Arguments: device_id (str): The ID of the device to run the example with. For example, 'dev2148'. Raises: RuntimeError: If the device is not connected to the Data Server. """ global daq # Creating global variable for accesing the UHFLI from other functions global device # Creating global variable for accesing the UHFLI from other functions # Create an instance of the ziDiscovery class. d = ziPython.ziDiscovery() # Determine the device identifier from it's ID. device = d.find(device_id).lower() # Get the device's default connectivity properties. props = d.get(device) # The maximum API level supported by this example. apilevel_example = 5 # The maximum API level supported by the device class, e.g., MF. apilevel_device = props['apilevel'] # Ensure we run the example using a supported API level. apilevel = min(apilevel_device, apilevel_example) # See the LabOne Programming Manual for an explanation of API levels. # Create a connection to a Zurich Instruments Data Server (an API session) # using the device's default connectivity properties. daq = ziPython.ziDAQServer(props['serveraddress'], props['serverport'], apilevel) # Check that the device is visible to the Data Server if device not in utils.devices(daq): raise RuntimeError("The specified device `%s` is not visible to the Data Server, " % device_id + "please ensure the device is connected by using the LabOne User Interface " + "or ziControl (HF2 Instruments).") # find out whether the device is an HF2 or a UHF devtype = daq.getByte('/%s/features/devtype' % device) options = daq.getByte('/%s/features/options' % device) # Create a base configuration: disable all outputs, demods and scopes general_setting = [ ['/%s/demods/*/rate' % device, 0], ['/%s/demods/*/trigger' % device, 0], ['/%s/sigouts/*/enables/*' % device, 0]] if re.match('HF2', devtype): general_setting.append(['/%s/scopes/*/trigchannel' % device, -1]) else: # UHFLI pass #general_setting.append(['/%s/demods/*/enable' % device, 0]) #general_setting.append(['/%s/scopes/*/enable' % device, 0]) daq.set(general_setting) raw_input("Set the UHF LI parameters in user interface dialog! Press enter to continue...") # Wait for user to set the device parametrs from user interface
def connect_device(self, devicename, required_options=None, required_err_msg='', exp_dependencie=False): import zhinst.utils as utils import zhinst.ziPython as ziPython # This function finds and connect the zurich device with serial number : devicename api_level = 6 # dev_type = 'UHFLI' dev_type = 'MFLI' # Create an instance of the ziDiscovery class. d = ziPython.ziDiscovery() # Determine the device identifier from it's ID. device_id = d.find(devicename).lower() # Get the device's connectivity properties. props = d.get(device_id) if not props['discoverable']: messagebox.showinfo( message="The specified device `{}` is not discoverable ". format(devicename) + "from the API. Please ensure the device is powered-on and visible using the LabOne User" + "Interface or ziControl.", title='Information') else: if not re.search(dev_type, props['devicetype']): messagebox.showinfo( message= "Required device type not satisfied. Device type `{}` does not match the" + "required device type:`{}`. {}".format( props['devicetype'], dev_type, required_err_msg)) if required_options: assert isinstance(required_options, list), "The keyword argument must be a list of string each entry" \ "specifying a device option." def regex_option_diff(required_options, device_options): """Return the options in required_options (as regex) that are not found in the device_options list. """ missing_options = [] for option in required_options: if not re.search(option, '/'.join(device_options)): missing_options += required_options return missing_options if props['devicetype'] == 'UHFAWG': # Note(16.12): This maintains backwards compatibility of this function. installed_options = props['options'] + ['AWG'] else: installed_options = props['options'] missing_options = regex_option_diff(required_options, installed_options) if missing_options: raise Exception( "Required option set not satisfied. The specified device `{}` has the `{}` options " "installed but is missing the required options `{}`. {}" .format(device_id, props['options'], missing_options, required_err_msg)) # The maximum API level supported by the device class, e.g., MF. apilevel_device = props['apilevel'] # Ensure that we connect on an compatible API Level (from where create_api_session() was called). apilevel = min(apilevel_device, api_level) # Creating a Daq server for the device with the parameters found daq = ziPython.ziDAQServer(props['serveraddress'], props['serverport'], apilevel) messagebox.showinfo( message='Zurich Instrument device {} is connected'.format( device_id), title='Information') self.info = {'daq': daq, 'device': device_id, 'prop': props} self.default = utils.default_output_mixer_channel( self.info['prop']) self.node_branch = daq.listNodes('/%s/' % device_id, 0) reset_settings = [['/%s/demods/*/enable' % device_id, 0], ['/%s/demods/*/trigger' % device_id, 0], ['/%s/sigout/*/enables/*' % device_id, 0], ['/%s/scopes/*/enable' % device_id, 0]] daq.set(reset_settings) daq.sync() if self.mainf: experiments = self.mainf.Frame[4].experiment_dict for experiment in experiments: experiments[experiment].update_options('Zurich')