예제 #1
0
 def _controlTransfer(self, request_type, request, value, index, data,
                      length, timeout):
     result = libusb1.libusb_control_transfer(self.__handle, request_type,
         request, value, index, data, length, timeout)
     if result < 0:
         raise libusb1.USBError(result)
     return result
예제 #2
0
    def write_command(self, request, data_ptr, length):
        """
        fonction qui envoie une commande de controle vers USB2

        :param request: signature du commande controle
        :param data_ptr: data du commande controle
        :param length: taille de data_ptr
        :return:
        """
        typerequest = self.LIBUSB_RECIPIENT_DEVICE | self.LIBUSB_REQUEST_TYPE_VENDOR | self.LIBUSB_ENDPOINT_OUT
        value = 0
        index = 0
        if (length == 0):
            dat = '\x00'
            dbg = libusb1.libusb_control_transfer(self.handle, typerequest, request, value, index, dat, 1, self.TIMEOUT)
            assert dbg == 1
        else:
            dbg = libusb1.libusb_control_transfer(self.handle, typerequest, request, value, index, data_ptr, length,
                                                  self.TIMEOUT)
            assert dbg == length
예제 #3
0
def cp2130_libusb_set_usb_config(handle):
    buf = c_ubyte * 10
    control_buf_out = buf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x80)
    usbTimeout = 500

    error_code = libusb1.libusb_control_transfer(handle, 0x40, 0x61, 0xA5F1,
                                                 0x000A, control_buf_out,
                                                 sizeof(control_buf_out),
                                                 usbTimeout)
    if error_code != sizeof(control_buf_out):
        print('Error in bulk transfer')
        return False
    return True
예제 #4
0
def cp2130_libusb_get_rtr_state(handle):
    buf = c_ubyte * 1
    control_buf_in = buf()
    usbTimeout = 500

    error_code = libusb1.libusb_control_transfer(handle, 0xC0, 0x36, 0x0000,
                                                 0x0000, control_buf_in,
                                                 sizeof(control_buf_in),
                                                 usbTimeout)
    if error_code != sizeof(control_buf_in):
        print('Error in bulk transfer')
        return False

    return True
예제 #5
0
def cp2130_libusb_set_spi_word(handle):
    buf = c_ubyte * 2
    control_buf_out = buf(0x00, 0x09)
    usbTimeout = 500

    error_code = libusb1.libusb_control_transfer(handle, 0x40, 0x31, 0x0000,
                                                 0x0000, control_buf_out,
                                                 sizeof(control_buf_out),
                                                 usbTimeout)
    if error_code != sizeof(control_buf_out):
        print('Error in bulk transfer')
        return False

    return True
예제 #6
0
def cp2130_libusb_set_usb_config(handle):
    buf = c_ubyte * 10
    control_buf_out = buf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                          0x80)
    usbTimeout = 500

    error_code = libusb1.libusb_control_transfer(handle, 0x40, 0x61, 0xA5F1,
                                                 0x000A, control_buf_out,
                                                 sizeof(control_buf_out),
                                                 usbTimeout)
    if error_code != sizeof(control_buf_out):
        print('Error in bulk transfer')
        return False
    # print('Successfully set value of spi_word on chip:')
    # for i in control_buf_out:
    # 	print(i)
    return True