给我一个libusb异步接收的示例代码
时间: 2023-03-13 08:55:00 浏览: 113
异步传输代码实例
下面是一个libusb异步接收的示例代码:#include <libusb-1.0/libusb.h>int main(void)
{
libusb_context *ctx = NULL;
int r; r = libusb_init(&ctx);
if (r < 0)
return r; libusb_device_handle *handle;
handle = libusb_open_device_with_vid_pid(ctx, 0x1234, 0x5678);
if (handle == NULL)
return -1; r = libusb_claim_interface(handle, 0);
if (r < 0)
return r; /* Register callback function for data reception */
libusb_register_callback(ctx, LIBUSB_TRANSFER_TYPE_INTERRUPT,
libusb_interrupt_callback, NULL); /* Start asynchronous data reception */
libusb_interrupt_start(handle, 0); libusb_close(handle);
libusb_exit(ctx); return 0;
}
阅读全文