USB HOST UsbDeviceConnection.bulkTransfer() returns -1 every

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

USB HOST UsbDeviceConnection.bulkTransfer() returns -1 every

Postby audiflitzer » Wed Apr 18, 2012 2:44 pm

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 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, 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 see my code
Code: Select all
manager = (UsbManager) getSystemService(Context.USB_SERVICE);

HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<String> deviceIterator = deviceList.keySet().iterator();
Iterator<UsbDevice> iterUsbDevice = deviceList.values().iterator();

if(iterUsbDevice.hasNext())
{
    Log.d("USB", " Iter has USB Device");
    device = iterUsbDevice.next();

     if(manager.hasPermission(device))
     {
      Log.d("USB", " Permission OK");
      }
     else
     {
           Log.d("USB", " Permission faild");

           manager.requestPermission(device, mPermissionIntent);

            if(manager.hasPermission(device))
            {
                   Log.d("USB", "Now is Permission OK");
            }
     }

      Log.d("USB", deviceIterator.next());

      Log.d("USB", String.valueOf(device.getInterfaceCount()));
      UsbInterface usbInterface = device.getInterface(0);

       Log.d("USB", String.valueOf(usbInterface.getEndpointCount()));
       usbEndpoint = usbInterface.getEndpoint(0);


       usbDeviceConnection = manager.openDevice(device);
        if(usbDeviceConnection.getFileDescriptor() == -1)
        {
             Log.d("USB", "Fails to open DeviceConnection");
        }
       else
       {
            Log.d("USB", "DeviceConnection open");
       }


        if(usbDeviceConnection.releaseInterface(usbInterface))
        {
             Log.d("USB", "Released OK");
        }
        else
        {
            Log.d("USB", "Released fails");
        }


      if(usbDeviceConnection.claimInterface(usbInterface, true))
      {
          Log.d("USB", "Claim OK");
      }
     else
     {
         Log.d("USB", "Claim fails");
     }


Now the code in the Thread

Code: Select all
final Thread usbThread = new Thread(new Runnable()
{
public void run()
{
int value = 0;

buf[0] = 22;
//int numberValue;
//usbDeviceConnection.controlTransfer(0x40, 0x11, 0, 0, null, 0, 100);

while(true)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

synchronized(this)
{

number = usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 1, 0);

if(number < 0)
{
Log.d("USB", "Bulk Transfer fails -> " + number);
}
else
{
Log.d("USB", "Bulk Transfer OK");
}
}


number = usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 1, 100);

if(number < 0)
{
Log.d("Ewgenij", "Bulk Transfer fails -> " + number);
}
else
{
Log.d("Ewgenij", "Bulk Transfer OK");
}

}
}
}
);
audiflitzer
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Apr 18, 2012 2:33 pm

Top

Re: USB HOST UsbDeviceConnection.bulkTransfer() returns -1 e

Postby UncleG » Mon Jun 04, 2012 7:47 am

Hello,
I have a similar problem like Yours, but not with galaxy nexus and one of the tablet on the market.
Everytime I want to read data from USB using usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 1, 500); (in loop) I received -1. I'm 100% sure that there are data in the incoming buffor.
But if I use for example usbDeviceConnection.bulkTransfer(usbEndpoint, buf, 100, 500); I can read some of the data. Anybody knows why there is such difference ? @audiflitzer have You found any solution ?
Thanks and best regards,
UncleG
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jun 04, 2012 7:37 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests