Android的bulkTransfer返回-1读取数据,但确实有些缓冲区中的数据时, [英] Android bulkTransfer return -1 when read data but there is really some data in the buffer

查看:7571
本文介绍了Android的bulkTransfer返回-1读取数据,但确实有些缓冲区中的数据时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的Galaxy Tab P7300一个应用程序通过OTG线的关键(SCSI设备)进行通信。可以读取数据首次与bulkTransfer(),而不是在下一次即可。然后我用Ellisys视觉USB嗅探数据,我发现,真正的关键返回13个字节的数据。但在Android客户端(GT-P7300)我收到了-1回报bulkTransfer。我已经用完了我的想法。感谢任何人都可以给我一片线索。

I write a app in galaxy tab p7300 to communicate with a key (scsi device) via otg cable. I can read data first time with bulkTransfer(),but can not the next time . Then I use Ellisys Visual USB to sniff data and I find that the key really return 13 bytes data. But in the android client (GT-P7300) I receive -1 that bulkTransfer return. I have run out my idea. Thanks for anybody that can give me a piece of clues.

推荐答案

在使用USB批量传输,这里是事情的清单来检查时,交易失败

When using the USB Bulk transfer, here is a list of things to check when transaction fails

一)验证端点的方向您已经通过了bulkTransfer功能

a) Verify the direction of the endpoint you have passed the bulkTransfer function

二)确保缓冲区有足够的长度来存储接收数据

b) ensure that the buffer has sufficient length to store incoming data

三)长度字段也许是最重要的。如果您知道响应的确切大小,使用它。

c) The length field is perhaps the most important. If you know the exact size of the response, use it.

D)在超时参数即可。如果您将查询发送到该设备并没有提供足够的超时听响应时,bulkTransfer可以返回-1。

d) The Timeout parameter. If you send a query to the device and do not provide enough timeout when listening to the response, the bulkTransfer can return -1.

它看起来像超时是影响你的情况的行为。我的建议是使用的确切字节数为每个响应的长度字段,并使用较长的超时(如1000),所以你给足够的时间批量请求来完成的。

It looks like the timeout is affecting behavior in your Case. My suggestion is to use the exact number of bytes in the length fields for each response, and use a longer timeout (like 1000) so you give enough time for the bulk request to complete.

这篇关于Android的bulkTransfer返回-1读取数据,但确实有些缓冲区中的数据时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆