How to use the pyvisa.errors.VisaIOError function in PyVISA

To help you get started, we’ve selected a few PyVISA examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyvisa / pyvisa-sim / pyvisa-sim / testsuite / test_all.py View on Github external
def _test_devices_timeouts(self, resource_name):
        inst = self.rm.open_resource(resource_name, timeout=0.1)
        self.assertRaises(VisaIOError, inst.read)
github pyvisa / pyvisa / pyvisa / rname.py View on Github external
It accepts the optional part of the expression.

    .. warning: This function is experimental and unsafe as it uses eval,
                It also might require to open the resource.

    :param resources: iterable of resources.
    :param query: query expression.
    :param open_resource: function to open the resource.
    """

    if '{' in query:
        try:
            query, optional = query.split('{')
            optional, _ = optional.split('}')
        except ValueError:
            raise errors.VisaIOError(constants.VI_ERROR_INV_EXPR)
    else:
        optional = None

    filtered = filter(resources, query)

    if not optional:
        return filtered

    optional = optional.replace('&&', 'and').replace('||', 'or').replace('!', 'not ')
    optional = optional.replace('VI_', 'res.VI_')

    class AttrGetter():

        def __init__(self, resource_name):
            self.resource_name = resource_name
            self.parsed = parse_resource_name(resource_name)
github PyFixate / Fixate / src / fixate / core / config_util.py View on Github external
def _test_config_dict(self, config_dict):
        visa_resources = config_dict["INSTRUMENTS"]["visa"]
        serial_resources = config_dict["INSTRUMENTS"]["serial"]
        for idn, visa_resource_name in visa_resources:
            try:
                new_idn = visa_id_query(visa_resource_name)
            except (VisaIOError, FxConfigError):
                self._test_print_error(
                    visa_resource_name, "Error opening or responding to IDN"
                )
            except Exception as e:
                self.perror(e)
            else:
                if new_idn.strip() == idn.strip():
                    self._test_print_ok(visa_resource_name, idn.strip())
                else:
                    self._test_print_error(
                        visa_resource_name, "IDN Response does not match"
                    )

        for port, params in serial_resources.items():
            idn, baudrate = params
            try:
github LISE-B26 / pylabcontrol / src / instruments / microwave_generator.py View on Github external
def is_connected(self):
        #COMMENT_ME
        try:
            self.srs.query('*IDN?') # simple call to check connection
            return True
        except pyvisa.errors.VisaIOError:
            return False
github pyvisa / pyvisa / pyvisa / resources / resource.py View on Github external
with self._resource_manager.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT):
            self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)

            if status == constants.VI_SUCCESS_DEV_NPRESENT:
                # The device was not ready when we opened the session.
                # Now it gets five seconds more to become ready.
                # Every 0.1 seconds we probe it with viClear.
                start_time = time.time()
                sleep_time = 0.1
                try_time = 5
                while time.time() - start_time < try_time:
                    time.sleep(sleep_time)
                    try:
                        self.clear()
                        break
                    except errors.VisaIOError as error:
                        if error.error_code != constants.VI_ERROR_NLISTENERS:
                            raise

        self._logging_extra['session'] = self.session
        logger.debug('%s - is open with session %s',
                     self._resource_name, self.session,
                     extra=self._logging_extra)