How to use the pyvisa.errors 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 / pyvisa / ctwrapper / highlevel.py View on Github external
def _init(self):
        try:
            lib = Library(self.library_path)
        except OSError as exc:
            raise errors.LibraryError.from_exception(exc, self.library_path)

        self.lib = lib

        # Set the argtypes, restype and errcheck for each function
        # of the visa library. Additionally store in `_functions` the
        # name of the functions.
        functions.set_signatures(self.lib, errcheck=self._return_handler)

        logger.debug('Library signatures: %d ok, %d failed',
                     len(getattr(self.lib, '_functions', [])),
                     len(getattr(self.lib, '_functions_failed', [])))

        # Set the library functions as attributes of the object.
        for method_name in getattr(self.lib, '_functions', []):
            setattr(self, method_name, getattr(self.lib, method_name))
github pyvisa / pyvisa / pyvisa / legacy / vpp43.py View on Github external
def check_status(status, func=None, arguments=()):
    """Check return values for errors and warnings."""
    global visa_status
    visa_status = status
    if status < 0:
        raise errors.VisaIOError(status)
    if status in dodgy_completion_codes:
        abbreviation, description = errors.completion_and_error_messages[status]
        warnings.warn("%s: %s" % (abbreviation, description),
                      errors.VisaIOWarning, stacklevel=2)
    return status
github pyvisa / pyvisa / pyvisa / ctwrapper / highlevel.py View on Github external
# Functions that use the first parameter to get a session value.
            if func.__name__ in ('viOpenDefaultRM', ):
                # noinspection PyProtectedMember
                session = session._obj.value

            if isinstance(session, integer_types):
                self._last_status_in_session[session] = ret_value
            else:
                # Functions that might or might have a session in the first argument.
                if func.__name__ not in ('viClose', 'viGetAttribute', 'viSetAttribute', 'viStatusDesc'):
                    raise Exception('Function %r does not seem to be a valid '
                                    'visa function (type args[0] %r)' % (func, type(session)))

        if ret_value < 0:
            raise errors.VisaIOError(ret_value)

        if ret_value in self.issue_warning_on:
            if session and ret_value not in self._ignore_warning_in_session[session]:
                warnings.warn(errors.VisaIOWarning(ret_value), stacklevel=2)

        return ret_value
github pyvisa / pyvisa / pyvisa / resources / resource.py View on Github external
def session(self):
        """Resource session handle.

        :raises: :class:`pyvisa.errors.InvalidSession` if session is closed.
        """
        if self._session is None:
            raise errors.InvalidSession()
        return self._session
github pyvisa / pyvisa / pyvisa / legacy / vpp43.py View on Github external
"peek_8", "poke_16", "poke_32", "poke_8", "printf", "queryf", "read",
    "read_asynchronously", "read_to_file", "read_stb", "scanf",
    "set_attribute", "set_buffer", "sprintf", "sscanf", "status_description",
    "terminate", "uninstall_handler", "unlock", "unmap_address",
    "unmap_trigger", "usb_control_in", "usb_control_out", "vprintf", "vqueryf",
    "vscanf", "vsprintf", "vsscanf", "vxi_command_query", "wait_on_event",
    "write", "write_asynchronously", "write_from_file"]

__all__ = ["visa_library", "get_status"] + visa_functions


# Add all symbols from #visa_exceptions# and #vpp43_constants# to the list of
# exported symbols

__all__.extend((name for name in dir(constants) if not name[0].startswith('_')))
__all__.extend((name for name in dir(errors) if not name[0].startswith('_')))

#: Global status code for the singleton library
visa_status = 0

def get_status():
    return visa_status

#: For these completion codes, warnings are issued.
dodgy_completion_codes = \
    [VI_SUCCESS_MAX_CNT, VI_SUCCESS_DEV_NPRESENT, VI_SUCCESS_SYNC,
    VI_WARN_QUEUE_OVERFLOW, VI_WARN_CONFIG_NLOADED, VI_WARN_NULL_OBJECT,
    VI_WARN_NSUP_ATTR_STATE, VI_WARN_UNKNOWN_STATUS, VI_WARN_NSUP_BUF,
    VI_WARN_EXT_FUNC_NIMPL]


def check_status(status, func=None, arguments=()):
github pyvisa / pyvisa / pyvisa / legacy / vpp43.py View on Github external
"""
        if os.name == 'nt':
            if path:
                self.__lib       = windll.LoadLibrary(path)
                self.__cdecl_lib = cdll.LoadLibrary(path)
            else:
                self.__lib       = windll.visa32
                self.__cdecl_lib = cdll.visa32
        elif os.name == 'posix':
            if not path:
                path = "/usr/local/vxipnp/linux/bin/libvisa.so.7"
            self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)
        else:
            self.__lib = self.__cdecl_lib = None
            raise errors.OSNotSupported(os.name)
        self.__initialize_library_functions()
github pyvisa / pyvisa-sim / pyvisa-sim / highlevel.py View on Github external
"""Returns a tuple of all connected devices matching query.

        :param session:
        :param query: regular expression used to match devices.
        """

        # For each session type, ask for the list of connected resources and merge them into a single list.

        resources = self.devices.list_resources()

        resources = rname.filter(resources, query)

        if resources:
            return resources

        raise errors.VisaIOError(errors.StatusCode.error_resource_not_found.value)
github pyvisa / pyvisa-py / pyvisa-py / tcpip.py View on Github external
def close(self):
        try:
            self.interface.destroy_link(self.link)
        except (errors.VisaIOError, socket.error, rpc.RPCError) as e:
            print("Error closing VISA link: {}".format(e))

        self.interface.close()
        self.link = None
        self.interface = None
github pyvisa / pyvisa / pyvisa / highlevel.py View on Github external
def install_visa_handler(self, session, event_type, handler, user_handle=None):
        """Installs handlers for event callbacks.

        :param session: Unique logical identifier to a session.
        :param event_type: Logical event identifier.
        :param handler: Interpreted as a valid reference to a handler to be installed by a client application.
        :param user_handle: A value specified by an application that can be used for identifying handlers
                            uniquely for an event type.
        :returns: user handle (a ctypes object)
        """
        try:
            new_handler = self.install_handler(session, event_type, handler, user_handle)
        except TypeError as e:
            raise errors.VisaTypeError(str(e))

        self.handlers[session].append(new_handler + (event_type,))
        return new_handler[1]
github pyvisa / pyvisa / pyvisa / highlevel.py View on Github external
def session(self):
        """Resource Manager session handle.

        :raises: :class:`pyvisa.errors.InvalidSession` if session is closed.
        """
        if self._session is None:
            raise errors.InvalidSession()
        return self._session