Android异步USB读取ByteBuffer,但无法确定大小

|| 我正在使用最近添加的Android USB API从Android 3.1 OS(在Motorola Xoom上)上基于FTDI的USB设备读取字节:http://developer.android.com/guide/topics/usb/host。 html 但是,执行异步读取时遇到了问题。
        ByteBuffer bb = ByteBuffer.allocate(128);
        UsbRequest request = new UsbRequest();
        request.initialize(deviceConnection, deviceInterface.getEndpoint(0));
        boolean sent = request.queue(bb, 128);
        request = deviceConnection.requestWait();
        if(request.getEndpoint() == deviceInterface.getEndpoint(0)) {
            // Send a message to the Activity with the read array
            Message msg = usbTest.handleAsyncMessage.obtainMessage();
            msg.obj = bb.array()
            usbTest.handleAsyncMessage.sendMessage(msg);
        }
此功能从设备正确读取字节。但是,它没有告诉我读取了多少。 bb.position()始终返回0,而bb.remaining()始终返回128。我无法确保我的读取将返回128个字节(可能读取,例如请求设备的状态,仅发送回12个字节左右),而且我无法确定读取从何处结束以及ByteBuffer中的垃圾开始。我尝试倒带ByteBuffer,但是读取未设置标记。有什么方法可以确定确切读取多少个字节? 谢谢     
已邀请:
        我不确定这是您的问题,但是在处理端点0时您似乎必须做一些特殊的事情。从UsbRequest的javadocs中:   此类不支持端点0上的请求。可以将controlTransfer(int,int,int,int,byte [],int,int)用于终结点零请求。     
        显然你不能。 Android的USB支持的缺点。 :( 请参阅如何确定UsbRequest.queue(..)方法的已接收字节长度?     

要回复问题请先登录注册