Example #1
0
 def getDeviceList(self):
     device_p_p = libusb1.libusb_device_p_p()
     device_list_len = libusb1.libusb_get_device_list(self.context_p,
                                                      byref(device_p_p))
     result = [USBDevice(self, x) for x in device_p_p[:device_list_len]]
     # XXX: causes problems, why ?
     #libusb1.libusb_free_device_list(device_p_p, 1)
     return result
def open_cp2130():
    context = libusb1.libusb_context_p()
    deviceList = libusb1.libusb_device_p_p()
    deviceCount = 0
    deviceDescriptor = libusb1.libusb_device_descriptor()
    device = libusb1.libusb_device_p()
    cp2130Handle = libusb1.libusb_device_handle_p()
    kernelAttached = 0

    if libusb1.libusb_init(byref(context)) != 0:
        print('Could not initialize libusb!')
        exit_cp2130()

    deviceCount = libusb1.libusb_get_device_list(context, byref(deviceList))

    if deviceCount <= 0:
        print('No devices found!')
        exit_cp2130()

    for i in range(0, deviceCount):
        if libusb1.libusb_get_device_descriptor(deviceList[i],
                                                byref(deviceDescriptor)) == 0:
            if (deviceDescriptor.idVendor
                    == 0x10C4) and (deviceDescriptor.idProduct == 0x87A0):
                device = deviceList[i]
                break

    if device == None:
        print('CP2130 device not found!')
        exit_cp2130()

    if libusb1.libusb_open(device, byref(cp2130Handle)) != 0:
        print('Could not open device!')
        exit_cp2130()

    if libusb1.libusb_kernel_driver_active(cp2130Handle, 0) != 0:
        libusb1.libusb_detach_kernel_driver(cp2130Handle, 0)
        kernelAttached = 1

    if libusb1.libusb_claim_interface(cp2130Handle, 0) != 0:
        print('Could not claim interface!')
        exit_cp2130()

    if cp2130_libusb_set_usb_config(cp2130Handle) == False:
        exit_cp2130()
    if cp2130_libusb_set_spi_word(cp2130Handle) == False:
        exit_cp2130()

    print('Successfully opened CP2130!')
    return cp2130Handle, kernelAttached, deviceList, context
Example #3
0
 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
Example #4
0
 def refreshBoards(self):
     dev_list = []
     deviceCount = libusb1.libusb_get_device_list(self.context,
                                                  byref(self.deviceList))
     if deviceCount <= 0:
         print('No devices found!')
     for i in range(0, deviceCount):
         if libusb1.libusb_get_device_descriptor(
                 self.deviceList[i], byref(self.deviceDescriptor)) == 0:
             if (self.deviceDescriptor.idVendor
                     == 0x10C4) and (self.deviceDescriptor.idProduct
                                     == 0x87A0):
                 dev_list.append(self.deviceList[i])
                 self.device = self.deviceList[i]
     # TODO: how to get device desciptor from libusb1?
     if dev_list:
         self.boardsChanged.emit(["cp2130"])
     else:
         self.boardsChanged.emit([])