android读取usb设备数据
2017-01-12 15:50
423 查看
main.c
Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := main
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := \
libusbhost \
include $(BUILD_EXECUTABLE)
#include <endian.h> #include <errno.h> #include <stdio.h> #include <stdint.h> #include <string.h> #include <usbhost/usbhost.h> int main(int argc, char **argv) { char buff[64]; int i = 0,out =0; static uint8_t read_ep; struct usb_descriptor_header* desc; struct usb_descriptor_iter iter; struct usb_interface_descriptor *intf = NULL; struct usb_endpoint_descriptor *ep1 = NULL; struct usb_endpoint_descriptor *ep2 = NULL; struct usb_device *p = usb_device_open("/dev/bus/usb/001/002"); int vendorId = usb_device_get_vendor_id(p); int productId = usb_device_get_product_id(p); printf("vid = %x, pid = %x\n",vendorId,productId); usb_descriptor_iter_init(p, &iter); while ((desc = usb_descriptor_iter_next(&iter)) != NULL && (!intf || !ep1 || !ep2)) { if (desc->bDescriptorType == USB_DT_INTERFACE) { intf = (struct usb_interface_descriptor *)desc; } else if (desc->bDescriptorType == USB_DT_ENDPOINT) { if (ep1) ep2 = (struct usb_endpoint_descriptor *)desc; else ep1 = (struct usb_endpoint_descriptor *)desc; } } if (!intf) { printf("interface not found\n"); exit(1); } if (!ep1 || !ep2) { printf("endpoints not found\n"); exit(1); } printf("%d,%d,%d\n",ep1->bEndpointAddress,ep2->bEndpointAddress,intf->bInterfaceNumber); if (usb_device_claim_interface(p, intf->bInterfaceNumber)) { printf("usb_device_claim_interface failed errno2:\n"); exit(1); } if ((ep1->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) { read_ep = ep1->bEndpointAddress; } else { read_ep = ep2->bEndpointAddress; } for(i = 0;i<10;i++){ out = usb_device_bulk_transfer(p,read_ep,buff,64,0); printf("out = %d\n",out); } return 0; }
Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := main
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := \
libusbhost \
include $(BUILD_EXECUTABLE)
相关文章推荐
- Windows下读取USB Hid设备数据的经验总结
- Android设备与外接U盘实现数据读取操作的示例
- android 通过usb 读取数据
- USB HID设备读取数据问题
- Android 读取usb设备
- android设备使用usb串口传输数据
- Android设备与外接U盘实现数据读取操作
- android 通过usb 读取数据
- Android播放器装载读取数据
- zz: 遍历 USB devcie,读取设备描述符 device descriptor
- 基于OHCI的USB主机 —— USB设备描述符数据结构
- Android 从j2ee服务器读取数据乱码
- SMBus读取从设备数据总结
- USB读取设备
- Vista中禁止向USB存储设备写数据简单教程
- Delphi调用WMI读取USB设备的PID和VID【转】
- USB设备读取的相关问题
- Android 软件开发之数据的 新建 储存 读取 删除 详解(十四)
- USB设备读取的相关问题
- 遍历 USB devcie,读取设备描述符 device descriptor