Пример #1
0
    def isLive(self):
        """ Attempts VISA connection to instrument, and checks whether
            :meth:`~lightlab.equipment.visa_bases.visa_object.instrID`
            matches :data:`id_string`.

            Produces a warning if it is live but the id_string is wrong.

            Returns:
                (bool): True if "live", False otherwise.
        """
        try:
            driver = self.driver_object
            query_id = driver.instrID()
            logger.info("Found %s in %s.", self.name, self.address)
            if self.id_string is not None:
                if self.id_string == query_id:
                    logger.info("id_string of %s is accurate", self.name)
                    return True
                else:
                    logger.warning("%s: %s, expected %s", self.address,
                                   query_id, self.id_string)
                    return False
            else:
                logger.debug("Cannot authenticate %s in %s.",
                             self.name, self.address)
                return True
        except pyvisa.VisaIOError as err:
            logger.warning(err)
            return False
Пример #2
0
 def is_valid(self, reset=True):
     if reset:
         self._valid = None
     if self._valid is None:
         self._valid = self.validate()
         # Only print info is it is validated now.
         if self._valid:
             logger.info("%s was just verified and it is live.", self)
         else:
             logger.info("%s was just verified and it is offline.", self)
     return self._valid
Пример #3
0
    def __contains__(self, item):

        if isinstance(item, Instrument):
            instrument_search = item in self.instruments
            if not instrument_search:
                logger.info("%s not found in %s's instruments.", item, self)
            return instrument_search
        elif isinstance(item, Device):
            device_search = item in self.devices
            if not device_search:
                logger.info("%s not found in %s's devices.", item, self)
            return device_search
        else:
            logger.debug("%s is neither an Instrument nor a Device", item)
            return False
Пример #4
0
    def checkInstrumentsLive(self):
        """ Checks whether all instruments are "live".

        Instrument status is checked with the :meth:`Instrument.isLive` method

        Returns:
            (bool): True if all instruments are live, False otherwise


        """
        all_live = True
        for instrument in self.instruments:
            if instrument.isLive():
                logger.info("%s is live.", instrument)
            else:
                all_live = False
        return all_live
Пример #5
0
    def updateHost(self, *hosts):
        """ Updates hosts in the hosts list.

        Checks the number of instrumentation_servers.
        There should be exactly one.

        Args:
            *(Host): hosts

        Raises:
            RuntimeError: Raised if duplicate names are found.
            TypeError: Raised if host is not of type :class:`~lightlab.laboratory.instruments.bases.Host`


        """
        localhost_name = None
        old_hostnames = []
        for old_host in self.hosts.values():
            old_hostnames.append(old_host.name)
            if isinstance(old_host, LocalHost):
                if localhost_name is not None:
                    logger.warning('Duplicate localhost found in lab.hosts')
                localhost_name = old_host.name
        for new_host in hosts:
            # Updating localhost
            if (isinstance(new_host, LocalHost)
                    and localhost_name is not None):
                # Check for localhost clash
                if new_host.name != localhost_name:
                    logger.warning(
                        'Localhost is already present: ' + '%s\n' +
                        'Not updating host %s!', localhost_name, new_host.name)
                    continue
                else:
                    localhost_name = new_host.name
            # Will an update happen?
            if new_host.name in old_hostnames:
                logger.info('Overwriting host: %s', new_host.name)
                # Will it end up removing the localhost?
                if (new_host.name == localhost_name
                        and not isinstance(new_host, LocalHost)):
                    localhost_name = None
            self.hosts[new_host.name] = new_host
        if localhost_name is None:
            logger.warning('Localhost not yet present')
Пример #6
0
    def findGpibAddressById(self, id_string_search, use_cached=True):
        """ Finds a gpib address using :meth:`get_all_gpib_id`, given
        an identity string.

        Args:
            id_string_search (str): identity string
            use_cached (bool): query only if not cached, default True

        Returns:
            str: address if found.

        Raises:
            NotFoundError: If the instrument is not found.

        """
        gpib_ids = self.get_all_gpib_id(use_cached=use_cached)
        for gpib_address, id_string in gpib_ids.items():
            if id_string_search == id_string:
                logger.info("Found %s in %s.", id_string_search, gpib_address)
                return gpib_address
        logger.warning("%s not found in %s", id_string_search, self)
        raise NotFoundError(
            "{} not found in {}".format(id_string_search, self))
Пример #7
0
 def __contains__(self, item):
     instrument_search = item in self.instruments
     if not instrument_search:
         logger.info("%s not found in %s's instruments.", item, self)
     return instrument_search