I run a USB connection in an AsyncTask. Under some conditions if I try to use the connection the bulk transfer function never returns. If I kill the AsyncTask the connection ceases to function unless I restart the machine.
Log.d(TAG, "trying to connect");
boolean connected = con.claimInterface(device.getInterface(0), true);
Log.d(TAG, "connected: " + connected);
Log.d(TAG, "trying to transfer cmd");
int outGoingBytes = con.bulkTransfer(endPointOut, cmd, cmd.length, 0);
Log.d(TAG, "outGoingBytes: " + outGoingBytes);
The last log is never reached.
Is there a way to programatically release the interface so I can reestablish a connection?
This is the logcat error
E/UsbDeviceConnectionJNI: device is closed in native_claim_interface
答案 0 :(得分:0)
Try to increase the timeout passed, you are passing 0, put 2000 millis or something like that.
con.bulkTransfer(endPointOut, cmd, cmd.length, 2000);
I don't know for sure, hope someone with more experience can give a answer, but for release the communication you can call close().
According to the documentation:
Releases all system resources related to the device. Once the object is closed it cannot be used again. The client must call openDevice(UsbDevice) again to retrieve a new instance to reestablish communication with the device.