I wrote a app to communcate with my own device via USB host. The code piece like this
UsbDeviceConnection connection = mUsbManager.openDevice(mDevice);
if (connection == null) {
Log.d(TAG, "open device failed");
break;
}
Log.d(TAG, "Opening the usb device success");
if (!connection.claimInterface(ui, true)) {
connection.close();
Log.d(TAG, "Usb claim interface failed");
break;
}
The logcat shows
D/UsbhostModbusAdapter: Opening the usb device success
D/UsbDeviceConnectionJNI: close
D/UsbhostModbusAdapter: Usb claim interface failed
I noticed the device was closed by JNI after openDevice called. So what happed between openDevice and claimInterface? Is it a hardware problem?
PS: Sometime the same device can claim successful and send/receive data OK. It depend on the open operation when plug into the phone. When first open is ok, then close and reopen always ok. But if first open not ok, then it will never open ok.
You have not explained the event of calling this code.
This can happen if
1. your part of code is being called twice back to back without closing previous connection.
2. When your activity is destroyed then you are missing call to connection.close() due to which previous connection is keeping the device occupied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With