6

I use a thread to send data to my usb-device (not data-storage) and get the return-data from device.

It worked fine in the first 5 minute. Data in, data out. (I almost start to sing in the sixth minute.)

Then suddenly it lost the connection.

There are the logcat message:

    java.lang.IllegalArgumentException: device /dev/bus/usb/001/002 does not exist or is restricted
    at android.os.Parcel.readException(Parcel.java:1331)
    at android.os.Parcel.readException(Parcel.java:1281)
    at android.hardware.usb.IUsbManager$Stub$Proxy.openDevice(IUsbManager.java:340)
    at android.hardware.usb.UsbManager.openDevice(UsbManager.java:255)

So, I check the code of UsbManager, trying to find out what is the IUsbManager...

Cool. An interface... and there is zero information about what it is. That is why I am here.

Has anyone with any clue???

5
  • Hello, I get this same exception when i restart my usb-device. I suspect your permission to use the device is "re-requested". When this happens to me I have to re-connect the usb cable. I haven't found any fixes to this yet though. Commented Aug 4, 2014 at 9:36
  • Have u got the solution? I m getting same exception while trying to connect usb CDC class. Commented Jan 7, 2015 at 5:35
  • You need to release your UsbConnection. I can't give a exacly number. It's about ten times data-sending then one time releasing. (And get a UsbConnection again....)
    – hsu.tw
    Commented Nov 25, 2015 at 4:05
  • @ErikSoderstrom what do you mean with "re-requested"? Btw, experiencing the same problem... Did you find a solution...?
    – User
    Commented May 31, 2017 at 19:55
  • Sorry. Not re-request. I should say ... re-open ( UsbManager.openDeivice)\
    – hsu.tw
    Commented Oct 3, 2017 at 7:49

1 Answer 1

2

The app should be listening to the UsbManager.ACTION_USB_DEVICE_ATTACHED and UsbManager.ACTION_USB_DEVICE_DETACHED Intents. It should attempt to open the device received from the attached intent.

The error usually happens when the app tries to re-open the connection to a UsbDevice. When the UsbDevice reconnects it is assigned a new hardware address (Old: /dev/bus/usb/001/002, New: /dev/bus/usb/001/003).

1
  • OMG So the connection to DEVICE can be disconnect. Then we need to wait for the listener get new DEVICE and continue the task.
    – hsu.tw
    Commented Jan 3, 2021 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.