How to use the libusb1.libusb_device_p_p function in libusb1

To help you get started, we’ve selected a few libusb1 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 Tinkerforge / brickd / src / brickd / libusb / usb1.py View on Github external
    @_validContext
    def getDeviceList(self, skip_on_error=False):
        """
        Return a list of all USB devices currently plugged in, as USBDevice
        instances.

        skip_on_error (bool)
            If True, catch errors and just skip to next device.
        """
        device_p_p = libusb1.libusb_device_p_p()
        libusb_device_p = libusb1.libusb_device_p
        device_list_len = libusb1.libusb_get_device_list(self.__context_p,
                                                         byref(device_p_p))
        if device_list_len < 0:
            raise libusb1.USBError(device_list_len)
        result = []
        append = result.append
        for device_p in device_p_p[:device_list_len]:
            try:
                # Instanciate our own libusb_device_p object so we can free
                # libusb-provided device list. Is this a bug in ctypes that it
                # doesn't copy pointer value (=pointed memory address) ? At
                # least, it's not so convenient and forces using such weird
                # code.
                device = USBDevice(self, libusb_device_p(device_p.contents))
            except libusb1.USBError, exc:
github kozec / sc-controller / scc / lib / usb1.py View on Github external
def getDeviceIterator(self, skip_on_error=False):
        """
        Return an iterator over all USB devices currently plugged in, as USBDevice
        instances.

        skip_on_error (bool)
            If True, ignore devices which raise USBError.
        """
        device_p_p = libusb1.libusb_device_p_p()
        libusb_device_p = libusb1.libusb_device_p
        device_list_len = libusb1.libusb_get_device_list(self.__context_p,
                                                         byref(device_p_p))
        mayRaiseUSBError(device_list_len)
        try:
            for device_p in device_p_p[:device_list_len]:
                try:
                    # Instanciate our own libusb_device_p object so we can free
                    # libusb-provided device list. Is this a bug in ctypes that
                    # it doesn't copy pointer value (=pointed memory address) ?
                    # At least, it's not so convenient and forces using such
                    # weird code.
                    device = USBDevice(self, libusb_device_p(device_p.contents))
                except USBError:
                    if not skip_on_error:
                        raise
github glaubitz / linux-minidisc / netmd / usb1.py View on Github external
def getDeviceList(self):
        """
        Return a list of all USB devices currently plugged in, as USBDevice
        instances.
        """
        device_p_p = libusb1.libusb_device_p_p()
        libusb_device_p = libusb1.libusb_device_p
        device_list_len = libusb1.libusb_get_device_list(self.__context_p,
                                                         byref(device_p_p))
        # Instanciate our own libusb_device_p object so we can free
        # libusb-provided device list. Is this a bug in ctypes that it doesn't
        # copy pointer value (=pointed memory address) ? At least, it's not so
        # convenient and forces using such weird code.
        result = [USBDevice(self, libusb_device_p(x.contents))
            for x in device_p_p[:device_list_len]]
        libusb1.libusb_free_device_list(device_p_p, 0)
        return result