Example #1
0
 def kernelDriverActive(self, interface):
     result = libusb1.libusb_kernel_driver_active(self.handle, interface)
     if result == 0:
         is_active = False
     elif result == 1:
         is_active = True
     else:
         raise libusb1.USBError, result
     return is_active
Example #2
0
 def kernelDriverActive(self, interface):
     """
     Tell whether a kernel driver is active on given interface number.
     """
     result = libusb1.libusb_kernel_driver_active(self.__handle, interface)
     if result == 0:
         is_active = False
     elif result == 1:
         is_active = True
     else:
         raise libusb1.USBError(result)
     return is_active
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 #4
0
 def connectToBoard(self, board):
     # open device
     if libusb1.libusb_open(self.device, byref(self.cp2130Handle)) != 0:
         print('Could not open device!')
         return
     # See if a kernel driver is active already, if so detach it and store a flag so we can reattach when we are done
     if libusb1.libusb_kernel_driver_active(self.cp2130Handle, 0) != 0:
         libusb1.libusb_detach_kernel_driver(self.cp2130Handle, 0)
         self.kernelAttached = 1
     # claim the device
     if libusb1.libusb_claim_interface(self.cp2130Handle, 0) != 0:
         print('Could not claim interface!')
         return
     print("Connected to {}".format(board))
     cp2130_libusb_set_spi_word(self.cp2130Handle)
     cp2130_libusb_set_usb_config(self.cp2130Handle)
     self.connStateChanged.emit(True)