Beispiel #1
0
 def getStringDescriptor(self, descriptor, lang_id):
     """
     Fetch description string for given descriptor and in given language.
     Use getSupportedLanguageList to know which languages are available.
     Return value is an unicode string.
     Return None if there is no such descriptor on device.
     """
     descriptor_string = create_unicode_buffer(
         STRING_LENGTH / sizeof(c_wchar))
     result = libusb1.libusb_get_string_descriptor(self.__handle,
         descriptor, lang_id, descriptor_string, sizeof(descriptor_string))
     if result == libusb1.LIBUSB_ERROR_NOT_FOUND:
         return None
     if result < 0:
         raise libusb1.USBError(result)
     return descriptor_string.value
Beispiel #2
0
 def getSupportedLanguageList(self):
     """
     Return a list of USB language identifiers (as integers) supported by
     current device for its string descriptors.
     """
     descriptor_string = create_binary_buffer(STRING_LENGTH)
     result = libusb1.libusb_get_string_descriptor(self.__handle,
         0, 0, descriptor_string, sizeof(descriptor_string))
     if result < 0:
         if result == libusb1.LIBUSB_ERROR_PIPE:
             # From libusb_control_transfer doc:
             # control request not supported by the device
             return []
         raise libusb1.USBError(result)
     length = cast(descriptor_string, POINTER(c_ubyte))[0]
     langid_list = cast(descriptor_string, POINTER(c_uint16))
     result = []
     append = result.append
     for offset in xrange(1, length / 2):
         append(libusb1.libusb_le16_to_cpu(langid_list[offset]))
     return result