Exemplo n.º 1
0
 def _open(self, type=None, serial=None):
     if self._handle != None:
         self._close()
     for dev in usb.get_device_list():
         desc = dev.descriptor
         if desc.idVendor==0x04D8 \
            and desc.idProduct==0xFBC3 \
            and (type==None or desc.bcdDevice==_bcd(type)) \
            and (serial==None or desc.iSerialNumber!=0):
             with self._io__Lock:
                 handle = usb.open(dev)  # Need to open the device to query string descriptors
                 try:    
                     ## s = usb.get_string( handle, desc.iSerialNumber )
                     s = _repeat( usb.get_string, handle, desc.iSerialNumber )
                     if (serial==None or s.endswith( str(serial) )):
                         ##usb.set_configuration( handle, 1 )
                         _repeat( usb.set_configuration, handle, 0 )  # Workaround for xHCI bug
                         _repeat( usb.set_configuration, handle, 1 ) 
                         _repeat( usb.claim_interface, handle, 0 )
                         self._handle = handle
                         self._serial = s
                         self._type = _bin(desc.bcdDevice)
                         nepts = dev.config[0].interface[0].altsetting[0].bNumEndpoints
                         for i in range(nepts):
                             ep = dev.config[0].interface[0].altsetting[0].\
                                     endpoint[i].bEndpointAddress
                             size = dev.config[0].interface[0].altsetting[0].\
                                     endpoint[i].wMaxPacketSize
                             if (ep&0x80): self._ep_in, self._size_in = ep, size
                             else: self._ep_out, self._size_out = ep, size
                         return
                 except:
                     usb.close(handle)
                     raise
     raise Exception('Device not found.')
Exemplo n.º 2
0
def mbug_list(type=None):
    """Return a list of all attached MBUG devices of a certain type."""
    found = []
    for dev in usb.get_device_list():
        desc = dev.descriptor
        if desc.idVendor==0x04D8 \
           and desc.idProduct==0xFBC3\
           and (type==None or desc.bcdDevice==_bcd(type)):
                handle = usb.open(dev)
                try:
                    ## s = usb.get_string( handle, desc.iSerialNumber )
                    s = _repeat( usb.get_string, handle, desc.iSerialNumber  )
                    if s!=None: found.append(s)
                finally:
                    usb.close(handle)   
    return found