コード例 #1
0
    def initialisation(self):
        """
        initialisation de la liaison usb

        :return: un handle sur la liaison usb (self.handle)
        """
        print('Initialisation usb')
        libusb1.libusb_init(NULL)
        libusb1.libusb_set_debug(NULL, 3)
        self.handle = libusb1.libusb_open_device_with_vid_pid(NULL, self.my_vid, self.my_pid)
        libusb1.libusb_claim_interface(self.handle, 0)
        print('Initialisation usb  ........  ok')
コード例 #2
0
ファイル: usb1.py プロジェクト: AlexanderS/linux-minidisc
 def claimInterface(self, interface):
     """
     Claim (= get exclusive access to) given interface number. Required to
     receive/send data.
     """
     result = libusb1.libusb_claim_interface(self.__handle, interface)
     if result:
         raise libusb1.USBError(result)
コード例 #3
0
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
コード例 #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)
コード例 #5
0
ファイル: usb1.py プロジェクト: astraw/python-libusb1
 def claimInterface(self, interface):
     result = libusb1.libusb_claim_interface(self.handle, interface)
     if result:
         raise libusb1.USBError, result