libusb函数
作者:互联网
一、libusb常用数据结构
- libusb_device *list:设备列表
- libusb_device_handle *handle:设备句柄
- struct libusb_device_descriptor desc:设备描述符
- struct libusb_config_descriptor conf:配置描述符
二、libusb常用API函数
1 会话的开启和结束
- int libusb_init(libusb_context **ctx);
- void libusb_exit(libusb_context *ctx);
- ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list);
- void libusb_free_device_list(libusb_device **list, int unref_devices);
3 设备的打开和关闭
- int libusb_open(libusb_device *dev, libusb_device_handle **dev_handle);
- libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
- void libusb_close(libusb_device_handle *dev_handle);
4 描述符的获取和释放
- int libusb_get_device_descriptor(libusb_device *dev, struct libusb_device_descriptor *desc);
- int libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config);
- void libusb_free_config_descriptor(struct libusb_config_descriptor *config);
5 接口
- int libusb_claim_interface(libusb_device_handle *dev_handle, int interface_number);
- int libusb_release_interface(libusb_device_handle *dev_handle, int interface_number);
6 传输方式:Control、Interrupt、Bulk
- int libusb_control_transfer(libusb_device_handle *dev_handle, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, unsigned int timeout);
- int libusb_interrupt_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout);
- int libusb_bulk_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout);
7 内核设备
- int libusb_kernel_driver_active(libusb_device_handle *dev_handle, int interface_number);
- int libusb_attach_kernel_driver(libusb_device_handle *dev_handle, int interface_number);
- int libusb_detach_kernel_driver(libusb_device_handle *dev_handle, int interface_number);
- int libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev_handle, int enable);
8 热插拔
- int libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *callback_handle);
- void libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle callback_handle);
9 其他
- uint8_t libusb_get_bus_number(libusb_device *dev); //获取USB设备总线号
- uint8_t libusb_get_port_number(libusb_device *dev);
- uint8_t libusb_get_device_address(libusb_device *dev); //获取USB设备端口号
- int libusb_get_device_speed(libusb_device *dev);
- int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint);
- int libusb_reset_device(libusb_device_handle *dev_handle);
- int libusb_has_capability(uint32_t capability);
......
使用时记得安装:
sudo apt-get install libusb-dev
sudo apt-get install libusb-1.0-0-dev
标签:handle,函数,get,int,dev,libusb,device 来源: https://www.cnblogs.com/kwinwei/p/14437975.html