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
Using java Syntax Highlighting
- 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;
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
it works normal.
then i am trying to read first 512 bytes to get FAT32 boot sector
Using java Syntax Highlighting
- 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();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
but it does not read any data from connected device.
all this code run on separate thread after granding permission on device
Using java Syntax Highlighting
- 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);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
in Broadcast receiver i just start new thread with previous code;
i also tried to make call to
USBDeviceConnection.controlTransfer
http://developer.android.com/reference/ ... ansfer(int, int, int, int, byte[], int, int)
Using java Syntax Highlighting
- byte[] b = new byte[0x10];
- int cTransfer = connection.controlTransfer(128, 6, 16, 0,b, 12, 0);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
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!


