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,但是读取未设置标记。有什么方法可以确定确切读取多少个字节?
谢谢
没有找到相关结果
已邀请:
2 个回复
朗排谎纷瘟
怪酞撩匹