コード例 #1
0
ファイル: usb1.py プロジェクト: AlexanderS/linux-minidisc
 def __init__(self, context, device_p):
     """
     You should not instanciate this class directly.
     Call LibUSBContext methods to receive instances of this class.
     """
     # Important: device_p refcount must be incremented before being given
     # to this constructor. This class will decrement refcount upon
     # destruction.
     self.__context = context
     self.device_p = device_p
     # Fetch device descriptor
     device_descriptor = libusb1.libusb_device_descriptor()
     result = libusb1.libusb_get_device_descriptor(device_p,
         byref(device_descriptor))
     if result:
         raise libusb1.USBError(result)
     self.device_descriptor = device_descriptor
     # Fetch all configuration descriptors
     self.__configuration_descriptor_list = []
     append = self.__configuration_descriptor_list.append
     for configuration_id in xrange(device_descriptor.bNumConfigurations):
         config = libusb1.libusb_config_descriptor_p()
         result = libusb1.libusb_get_config_descriptor(device_p,
             configuration_id, byref(config))
         if result == libusb1.LIBUSB_ERROR_NOT_FOUND:
             # Some devices (ex windows' root hubs) tell they have one
             # configuration, but they have no configuration descriptor.
             continue
         if result:
             raise libusb1.USBError(result)
         append(config.contents)
コード例 #2
0
ファイル: usb1.py プロジェクト: astraw/python-libusb1
 def __init__(self, context, device_p):
     self.context = context
     libusb1.libusb_ref_device(device_p)
     self.device_p = device_p
     # Fetch device descriptor
     device_descriptor = libusb1.libusb_device_descriptor()
     result = libusb1.libusb_get_device_descriptor(device_p,
         byref(device_descriptor))
     if result:
         raise libusb1.USBError, result
     self.device_descriptor = device_descriptor
     # Fetch all configuration descriptors
     self.configuration_descriptor_list = []
     append = self.configuration_descriptor_list.append
     for configuration_id in xrange(device_descriptor.bNumConfigurations):
         config = libusb1.libusb_config_descriptor_p()
         result = libusb1.libusb_get_config_descriptor(device_p,
             configuration_id, byref(config))
         if result:
             raise libusb1.USBError, result
         append(config.contents)