USBHost with flash drive

Put your problem here if it does not fit any of the other categories.

USBHost with flash drive

Postby timoshenko_av » Tue Apr 17, 2012 10:53 am

Hi,everyone!
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
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final UsbDeviceConnection connection = manager.openDevice(device);
  2. UsbInterface inf = device.getInterface(0);
  3. if (!connection.claimInterface(inf, true)) {
  4.     Log.v("USB", "failed to claim interface");
  5. }
  6. UsbEndpoint epOut = null;
  7. UsbEndpoint epIn = null;
  8. // look for our bulk endpoints
  9. for (int i = 0; i < inf.getEndpointCount(); i++) {
  10.     UsbEndpoint ep = inf.getEndpoint(i);
  11.     if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
  12.         if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
  13.             epOut = ep;
  14.         } else {
  15.             epIn = ep;
  16.         }
  17.     }
  18. }
  19. if (epOut == null || epIn == null) {
  20.   throw new IllegalArgumentException("not all endpoints found");
  21. }
  22. final UsbEndpoint inEndPoint = epIn;
  23.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


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

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ByteBuffer arg1 = ByteBuffer.allocate(512);
  2. UsbRequest request = new UsbRequest();
  3. request.initialize(connection, inEndPoint);
  4. request.queue(arg1, inEndPoint.getMaxPacketSize());
  5. UsbRequest result = connection.requestWait(); // halt here
  6. connection.releaseInterface(inf);
  7. connection.close();
  8.  
Parsed in 0.031 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

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. PendingIntent mPermissionIntent = PendingIntent.getBroadcast(USBHostSampleActivity.this, 0, new Intent(
  2.                                                                 ACTION_USB_PERMISSION), 0);
  3. IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
  4. registerReceiver(mUsbReceiver, filter);
  5. manager.requestPermission(lDevices.get(position),mPermissionIntent);
  6.  
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)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. byte[] b = new byte[0x10];
  2. int cTransfer = connection.controlTransfer(128, 6, 16, 0,b, 12, 0);
  3.  
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!
timoshenko_av
Freshman
Freshman
 
Posts: 8
Joined: Tue Oct 05, 2010 10:02 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 32 guests