Android 下的 USB HID 设备读写

  1. UsbInterface usbInterface = usbDevice.getInterface(0);  
  2. //USBEndpoint为读写数据所需的节点  
  3. UsbEndpoint inEndpoint = usbInterface.getEndpoint(0);  //读数据节点  
  4. UsbEndpoint outEndpoint = usbInterface.getEndpoint(1); //写数据节点  
  5. UsbDeviceConnection connection = usbManager.openDevice(usbDevice);  
  6. connection.claimInterface(usbInterface, true);  
  7.   
  8. //发送数据  
  9. byte[] byte2 = new byte[64];  
  10. int out = connection.bulkTransfer(outEndpoint, cmd, cmd.length, 3000);  
  11.   
  12. //读取数据1   两种方法读取数据  
  13. int ret = connection.bulkTransfer(inEndpoint, byte2, byte2.length, 3000);  
  14. Log.e("ret""ret:"+ret);  
  15. for(Byte byte1 : byte2){  
  16.     System.err.println(byte1);  
  17. }  
  18.   
  19. //读取数据2  
  20. /*int outMax = outEndpoint.getMaxPacketSize(); 
  21. int inMax = inEndpoint.getMaxPacketSize(); 
  22. ByteBuffer byteBuffer = ByteBuffer.allocate(inMax); 
  23. UsbRequest usbRequest = new UsbRequest(); 
  24. usbRequest.initialize(connection, inEndpoint); 
  25. usbRequest.queue(byteBuffer, inMax); 
  26. if(connection.requestWait() == usbRequest){ 
  27.     byte[] retData = byteBuffer.array(); 
  28.     for(Byte byte1 : retData){ 
  29.         System.err.println(byte1); 
  30.     } 
  31. }*/  

原文:http://blog.csdn.net/centralperk/article/details/9312401

 

参考:http://hi.baidu.com/intel88888/item/9a194171438dd9356dc37ca7

转载于:https://www.cnblogs.com/blueice-007/p/3534338.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值