Beispiel #1
0
    def setControl(self, request_type, request, value, index, buffer_or_len,
            callback=None, user_data=None, timeout=0):
        """
        Setup transfer for control use.

        request_type, request, value, index: See USBDeviceHandle.controlWrite.
        buffer_or_len: either a string (when sending data), or expected data
          length (when receiving data)
        callback: function to call upon event. Called with transfer as
          parameter, return value ignored.
        user_data: to pass some data to/from callback
        timeout: in milliseconds, how long to wait for devices acknowledgement
          or data. Set to 0 to disable.
        """
        if self.__submitted:
            raise ValueError('Cannot alter a submitted transfer')
        if isinstance(buffer_or_len, basestring):
            length = len(buffer_or_len)
            string_buffer = create_binary_buffer(
                ' ' * libusb1.LIBUSB_CONTROL_SETUP_SIZE + buffer_or_len)
        else:
            length = buffer_or_len
            string_buffer = create_binary_buffer(length + \
                libusb1.LIBUSB_CONTROL_SETUP_SIZE)
        self.__initialized = False
        libusb1.libusb_fill_control_setup(string_buffer, request_type,
            request, value, index, length)
        libusb1.libusb_fill_control_transfer(self.__transfer, self.__handle,
            string_buffer, self.__ctypesCallbackWrapper, user_data, timeout)
        self.__callback = callback
        self.__initialized = True
Beispiel #2
0
 def fillControlTransfer(self, transfer, setup, callback,
                         user_data, timeout):
     libusb1.libusb_fill_control_transfer(transfer, self.handle,
         setup, libusb1.libusb_transfer_cb_fn_p(callback), user_data,
         timeout)