libusb_bulk_transfer Description

libusb_bulk_transfer Function Description

  1.  
    API_EXPORTED int libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
  2.  
    unsigned char endpoint, unsigned char *data, int length, int *transferred,
  3.  
    unsigned int timeout)
  4.  
    {
  5.  
    // Call do_sync_bulk_transfer
  6.  
    return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
  7.  
    transferred, timeout, LIBUSB_TRANSFER_TYPE_BULK);
  8.  
    }


Code:

 

    1.  
      static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
    2.  
      unsigned char endpoint, unsigned char *buffer, int length,
    3.  
      int *transferred, unsigned int timeout, unsigned char type)
    4.  
      {
    5.  
      struct libusb_transfer *transfer = libusb_alloc_transfer(0);
    6.  
      int completed = 0;
    7.  
      int r;
    8.  
       
    9.  
      if (!transfer)
    10.  
      return LIBUSB_ERROR_NO_MEM;
    11.  
       
    12.  
      // transmission structure must have its core is the data transmission as well as some of the state is actually a truck
    13.  
      libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, length,
    14.  
      bulk_transfer_cb, &completed, timeout);
    15.  
      transfer->type = type;
    16.  
       
    17.  
      // in Bahrain truck cargo can be set off, apply for transfer
    18.  
      r = libusb_submit_transfer(transfer);
    19.  
      if (r < 0) {
    20.  
      libusb_free_transfer(transfer);
    21.  
      return r;
    22.  
      }
    23.  
       
    24.  
       
    25.  
       
    26.  
      // complete is the completion of the loading of a standard
    27.  
       
    28.  
      while (!completed) {
    29.  
      r = libusb_handle_events(HANDLE_CTX(dev_handle));
    30.  
      if (r < 0) {
    31.  
      if (r == LIBUSB_ERROR_INTERRUPTED)
    32.  
      continue;
    33.  
      libusb_cancel_transfer(transfer);
    34.  
      while (!completed)
    35.  
      if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0)
    36.  
      break;
    37.  
      libusb_free_transfer(transfer);
    38.  
      return r;
    39.  
      }
    40.  
      }
    41.  
       
    42.  
      *transferred = transfer->actual_length;
    43.  
      switch (transfer->status) {
    44.  
      case LIBUSB_TRANSFER_COMPLETED:
    45.  
      r = 0;
    46.  
      break;
    47.  
      case LIBUSB_TRANSFER_TIMED_OUT:
    48.  
      r = LIBUSB_ERROR_TIMEOUT;
    49.  
      break;
    50.  
      case LIBUSB_TRANSFER_STALL:
    51.  
      r = LIBUSB_ERROR_PIPE;
    52.  
      break;
    53.  
      case LIBUSB_TRANSFER_OVERFLOW:
    54.  
      r = LIBUSB_ERROR_OVERFLOW;
    55.  
      break;
    56.  
      case LIBUSB_TRANSFER_NO_DEVICE:
    57.  
      r = LIBUSB_ERROR_NO_DEVICE;
    58.  
      break;
    59.  
      default:
    60.  
      usbi_warn(HANDLE_CTX(dev_handle),
    61.  
      "unrecognised status code %d", transfer->status);
    62.  
      r = LIBUSB_ERROR_OTHER;
    63.  
      }
    64.  
      libusb_free_transfer(transfer);
    65.  
      return r;
    66.  
      }
       
      https://blog.csdn.net/zdyueguanyun/article/details/51192885

Guess you like

Origin www.cnblogs.com/hshy/p/11736716.html