Google Galaxy Nexus — USB HOST UsbDeviceConnection.bulkTransfer() returns -1 every time / UsbRequest.queue() doesnt work, too

  • Replies:7
Eugen G.
  • Forum posts: 4

Apr 17, 2012, 11:59:56 AM via Website

I have a problem with my galaxy nexus 4.0.4. I try to connect to my Device over the USB.
I have done all initializations without failure. The UsbDeviceConnection.controlTransfer() function works fine in both directions.

However if I call UsbDeviceConnection.bulkTransfer() it always returns -1.

Has anyone encountered the same issue? If code is mandated I'll post it!

If I use UsbRequest.queue() following with UsbDeviceConnection.requestWait(), the same problem occurs and no data will be transfered.

If I try to communicate with the named function that doesn't work because my device doesn't generate an interrupt. It looks like no data leaves the Android device with these functions!

Who have experience?

I hope to get some answers or help!
Below my code.


Init code

1manager = (UsbManager) getSystemService(Context.USB_SERVICE);
2
3 HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
4 Iterator<String> deviceIterator = deviceList.keySet().iterator();
5 Iterator<UsbDevice> iterUsbDevice = deviceList.values().iterator();
6
7 if(iterUsbDevice.hasNext())
8 {
9 Log.d("USB", " Iter has USB Device");
10 device = iterUsbDevice.next();
11
12 if(manager.hasPermission(device))
13 {
14 Log.d("USB", " Permission OK");
15 }
16 else
17 {
18 Log.d("USB", " Permission faild");
19
20 manager.requestPermission(device, mPermissionIntent);
21
22 if(manager.hasPermission(device))
23 {
24 Log.d("USB", "Now is Permission OK");
25 }
26 }
27
28 Log.d("USB", deviceIterator.next());
29
30 Log.d("USB", String.valueOf(device.getInterfaceCount()));
31 UsbInterface usbInterface = device.getInterface(0);
32
33 Log.d("USB", String.valueOf(usbInterface.getEndpointCount()));
34 usbEndpoint = usbInterface.getEndpoint(0);
35
36
37 usbDeviceConnection = manager.openDevice(device);
38 if(usbDeviceConnection.getFileDescriptor() == -1)
39 {
40 Log.d("USB", "Fails to open DeviceConnection");
41 }
42 else
43 {
44 Log.d("USB", "DeviceConnection open");
45 }
46
47
48 if(usbDeviceConnection.releaseInterface(usbInterface))
49 {
50 Log.d("USB", "Released OK");
51 }
52 else
53 {
54 Log.d("USB", "Released fails");
55 }
56
57
58 if(usbDeviceConnection.claimInterface(usbInterface, true))
59 {
60 Log.d("USB", "Claim OK");
61 }
62 else
63 {
64 Log.d("USB", "Claim fails");
65 }

Now the code in the thread

1final Thread usbThread = new Thread(new Runnable()
2 {
3 public void run()
4 {
5 int value = 0;
6
7 buf[0] = 22;
8 //int numberValue;
9 //usbDeviceConnection.controlTransfer(0x40, 0x11, 0, 0, null, 0, 100);
10
11 while(true)
12 {
13 try
14 {
15 Thread.sleep(1000);
16 }
17 catch (InterruptedException e)
18 {
19 // TODO Auto-generated catch block
20 e.printStackTrace();
21 }
22
23 synchronized(this)
24 {
25
26 number = usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 1, 0);
27
28 if(number < 0)
29 {
30 Log.d("USB", "Bulk Transfer fails -> " + number);
31 }
32 else
33 {
34 Log.d("USB", "Bulk Transfer OK");
35 }
36 }
37
38
39 number = usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 1, 100);
40
41 if(number < 0)
42 {
43 Log.d("Ewgenij", "Bulk Transfer fails -> " + number);
44 }
45 else
46 {
47 Log.d("Ewgenij", "Bulk Transfer OK");
48 }
49
50 }
51 }
52 }
53 );

Reply
Eric McBride
  • Forum posts: 1,790

Apr 17, 2012, 3:07:19 PM via Website

Sounds like you need a dev. Jeremiah, you around to help out on this?

Reply
dev me
  • Forum posts: 1

Apr 17, 2012, 6:04:56 PM via Website

Hello,
i am really interested in this topic. I'm developing an application which needs to send and receive data with a RF usb dongle.
I encounter almost the same problems : UsbDeviceConnection.bulkTransfer() always returns -1 except the first time i call it (returns 1 when i write data to the usb dongle ) but when i read data, fonction result is always failed (-1).
I have the same problem with the UsbDeviceConnection.controlTransfer() function.

Is anyone able to help us ? do we need to clear something (like flags) between 2 data exchange ?

[working on Samsung Galaxy 7.0 Plus, Android 3.2]

Reply
Eugen G.
  • Forum posts: 4

Apr 17, 2012, 7:22:28 PM via Website

Eric McBride
Sounds like you need a dev. Jeremiah, you around to help out on this?

What do you mean with "dev". Write own driver for android?

Reply
Jeremiah
  • Forum posts: 775

Apr 17, 2012, 9:10:58 PM via Website

Eugen G.
Eric McBride
Sounds like you need a dev. Jeremiah, you around to help out on this?

What do you mean with "dev". Write own driver for android?

He means you need a developer to help you. I don't have any experience with usb on android, so best I can suggest is posting on a more developer centered forums such as http://www.anddev.org/index.php or XDA Developers.

Reply
Pramod Kumar
  • Forum posts: 1

May 31, 2015, 6:59:20 AM via Website

Hi,
Did you guys get an answer to your question ? I am having the same issue. Any help would be greatly appreciated.

Thanks
Pramod

Reply
vinay
  • Forum posts: 14

Dec 3, 2015, 3:40:15 PM via Website

What do you mean with dev

Reply
David Lu
  • Forum posts: 15

Dec 3, 2015, 4:33:34 PM via Website

Hello guys,
Did you guys get an answer to your question yet ? I am having an issue. Any help from anyone would be greatly appreciated.

Thank You

Reply