- Forum posts: 4
Apr 17, 2012, 11:59:56 AM via Website
Apr 17, 2012 11:59:56 AM via Website
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
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
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 );
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.