In spite of having claimedInterface
d, 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;
}
}