1

In spite of having claimedInterfaced, having correct permissions etc, when controlTransfer() is called it returns -1. Logcat shows nothing interesting. I'm using this code as a guide.

Looking at the source, here and here, I know that the device is open properly (getFileDescriptor() returns a proper value). This means that the ioctl call is failing. I have no access to the errno.

Any ideas?

private static UsbInterface getSerialInterface(UsbDevice device)
{
    for (int i = device.getInterfaceCount() - 1; i >= 0; i--)
    {
        UsbInterface iface = device.getInterface(i);
        if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
            return iface;
    }
    return null;
}

private byte[] getLineEncoding(int baudRate) {
    final byte[] lineEncodingRequest = { (byte) 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 };
    if (baudRate != 9600)
        throw new UnsupportedOperationException("Bad Baud rate.");
}


private boolean openSerialEndpoints(UsbDevice device)
{
    mConnection = mManager.openDevice(device);
    if (mConnection == null) return false;
    UsbInterface iface = getSerialInterface(device);
    if (iface == null) {
        closeSerialEndpoints();
        return false;
    }
    if (!mConnection.claimInterface(iface, true)) {
        Log.e(TAG, "Claiming interface failed!");
        closeSerialEndpoints();
        return false;
    }
    Log.d(TAG, "controlTransfer.");
    if (mConnection.getFileDescriptor() == -1)
        Log.d(TAG, "NOt Opened!!");
    // Arduino setup.
    if (mConnection.controlTransfer(0x21, 0x22, 0, 0, null, 0, 0) <= 0) {
        Log.d(TAG, "Control transfer 1 failed.");    // This fails
        return false;
    }
    if (mConnection.controlTransfer(0x21, 0x20, 0, 0, getLineEncoding(9600), 7, 0) <= 0) {
        Log.d(TAG, "Control transfer 2 failed.");
        return false;
    }
 }
nishantjr
  • 1,788
  • 1
  • 15
  • 39
  • Worth noting that this is an Android USB APIs question - it's not really an Arduino question at all as it interacts with only factory functionality of the Arduino, so *should not* be a candidate for migration to the Arduino site. – Chris Stratton Jun 05 '14 at 15:18
  • @ChrisStratton even so, I didn't realize that arduino had it's own SE! – nishantjr Jun 05 '14 at 15:29

0 Answers0