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

posted on 2014-01-26 18:52  梦星尘  阅读(9244)  评论(0编辑  收藏  举报