Android的USBHOST闪存驱动器 [英] android USBHost flash drive

查看:202
本文介绍了Android的USBHOST闪存驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使读取外部存储文件系统连接使用OTG线连接到XOOM与ICS应用。 我用这code,以确定IN和OUT端点与闪存设备的通信

I am trying to make application for reading external storage file system connected using OTG cable to XOOM with ICS. i am using this code to determine IN and OUT endpoint for communication with flash device

final UsbDeviceConnection connection = manager.openDevice(device);
UsbInterface inf = device.getInterface(0);
if (!connection.claimInterface(inf, true)) {
    Log.v("USB", "failed to claim interface");
}
UsbEndpoint epOut = null;
UsbEndpoint epIn = null;
// look for our bulk endpoints
for (int i = 0; i < inf.getEndpointCount(); i++) {
    UsbEndpoint ep = inf.getEndpoint(i);
    if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
        if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
            epOut = ep;
        } else {
            epIn = ep;
        }
    }
}
if (epOut == null || epIn == null) {
  throw new IllegalArgumentException("not all endpoints found");
}
final UsbEndpoint inEndPoint = epIn;

它工作正常。 然后我想读前512个字节得到FAT32引导扇区

it works normal. then i am trying to read first 512 bytes to get FAT32 boot sector

ByteBuffer arg1 = ByteBuffer.allocate(512);
UsbRequest request = new UsbRequest();
request.initialize(connection, inEndPoint);
request.queue(arg1, inEndPoint.getMaxPacketSize());
UsbRequest result = connection.requestWait(); // halt here
connection.releaseInterface(inf);
connection.close();

,但它不读取从连接的设备的任何数据。 这一切code在不同的线程挤级的设备的许可后,运行

but it does not read any data from connected device. all this code run on separate thread after granding permission on device

PendingIntent mPermissionIntent = PendingIntent.getBroadcast(USBHostSampleActivity.this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
manager.requestPermission(lDevices.get(position),mPermissionIntent);

在广播接收机我刚入手previous code新线程; 我也试图让呼叫 <一href="http://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#controlTransfer%28int,%20int,%20int,%20int,%20byte%5B%5D,%20int,%20int%29">USBDeviceConnection.controlTransfer

in Broadcast receiver i just start new thread with previous code; i also tried to make call to USBDeviceConnection.controlTransfer

byte[] b = new byte[0x10];
int cTransfer = connection.controlTransfer(128, 6, 16, 0,b, 12, 0);

像中的libusb样品获得f0的数据和/或hwstats但它总是返回-1 我也尝试过使用USBRequst同步bulkTransfers取代异步请求,但结果是一样的。 与这部分Android SDK中的任何人合作? 谢谢!

like in libusb sample to get f0 data and/or hwstats but it always return -1 also i tried replace async request using USBRequst to sync bulkTransfers but result is the same. Have anyone worked with this part of Android SDK? Thanks!

推荐答案

看来你缺少一个整体的协议层;你不能只从设备读取512个字节。我应该将它发送回来?它怎么会知道你要开始阅读在磁盘的开始?

It appears you are missing a whole protocol layer; you can't just read 512 bytes from the device. What should it send back? How could it know you want to start to read at the beginning of the disk?

您实际上如何读取USB-MSC设备中的存储位置取决于设备子类的类型和支持的传输协议。

How you actually read a memory location from USB-MSC device depends on the device sub class type and the supported transport protocol.

这可能是一个普通的闪存盘使用 SCSI透明的指令集 USB海量存储类仅成批(BBB)运输<结合/一>

It is likely that an ordinary flash disk uses the SCSI transparent command set in conjunction with the USB Mass Storage Class Bulk-Only (BBB) Transport.

您必须检查设备描述符,找出您的设备支持。另请参阅<一href="http://www.usb.org/developers/docs/devclass_docs/Mass_Storage_Specification_Overview_v1.4_2-19-2010.pdf"相对=nofollow> MSC设备类概述对所有可能的值,并参考它们的文档。

You have to examine the device descriptor to find out what your device supports. See also the MSC device class overview for all possible values and references to their documentation.

这篇关于Android的USBHOST闪存驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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