How can I determine the length of received bytes of UsbRequest.queue(..) method?

被刻印的时光 ゝ 提交于 2019-12-04 06:38:36

This was a bug in Android. On afflicted versions, there's no workaround, because the implementation simply doesn't pass the length up.

It was fixed in JB-MR1 (API level 17 onwards).

It seems to me that the current asynchronous USB API has no way to return the read size. 2 "workarounds" use synchronous transfers as there you receive the number of bytes read/written or maybe the protocol you are implementing sends you the number of bytes you'll receive. E.g. i'm currently implementing something where every higher-level packet i receive has the number of bytes in the first 4 bytes of the packet. Based on this number i know if i have to do multiple reads.

You can use request.queue(buffer, bufferLength);. This should solve your problem. Now, you should refer android documentation, it's well documented and helpful.

I believe buffer.limit() should return the number of received bytes. Does that work?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!