- UsbInterface usbInterface = usbDevice.getInterface(0);
- //USBEndpoint为读写数据所需的节点
- UsbEndpoint inEndpoint = usbInterface.getEndpoint(0); //读数据节点
- UsbEndpoint outEndpoint = usbInterface.getEndpoint(1); //写数据节点
- UsbDeviceConnection connection = usbManager.openDevice(usbDevice);
- connection.claimInterface(usbInterface, true);
- //发送数据
- byte[] byte2 = new byte[64];
- int out = connection.bulkTransfer(outEndpoint, cmd, cmd.length, 3000);
- //读取数据1 两种方法读取数据
- int ret = connection.bulkTransfer(inEndpoint, byte2, byte2.length, 3000);
- Log.e("ret", "ret:"+ret);
- for(Byte byte1 : byte2){
- System.err.println(byte1);
- }
- //读取数据2
- /*int outMax = outEndpoint.getMaxPacketSize();
- int inMax = inEndpoint.getMaxPacketSize();
- ByteBuffer byteBuffer = ByteBuffer.allocate(inMax);
- UsbRequest usbRequest = new UsbRequest();
- usbRequest.initialize(connection, inEndpoint);
- usbRequest.queue(byteBuffer, inMax);
- if(connection.requestWait() == usbRequest){
- byte[] retData = byteBuffer.array();
- for(Byte byte1 : retData){
- System.err.println(byte1);
- }
- }*/
参考:http://hi.baidu.com/intel88888/item/9a194171438dd9356dc37ca7
原文:http://www.cnblogs.com/blueice-007/p/3534338.html