SimpleUsbTerminal
SimpleUsbTerminal copied to clipboard
App Crash and Arduino Restart on Closing USB Connection
Hello @kai-morich,
I've been experiencing an issue with the USB connection in my application, which seems to be causing crashes and unintentionally restarting my connected Arduino device whenever the app is closed. This behavior contrasts with a similar app available on the Play Store, apparently built using the same code from this repository, which does not exhibit the same problem.
Issue Details:
-
Behavior Observed: Closing the app leads to an immediate crash of the USB port, followed by a restart of the connected Arduino device.
-
Comparison: In the Play Store app, the USB device closure and the
UsbRequestJNI
closure appear to have a delay between them, unlike in my application where these events occur almost instantaneously.
For instance, in my app logs, the timestamp difference between UsbDeviceConnectionJNI: close
and UsbRequestJNI: close
is very short:
2023-11-14 18:38:44.726 3787-3787/com.example D/UsbDeviceConnectionJNI: close
2023-11-14 18:38:45.477 3787-3800/com.example D/UsbRequestJNI: close
Whereas in the Play Store app, there is a noticeable delay:
2023-11-14 18:39:33.751 21443-21443/de.kai_morich.serial_usb_terminal D/UsbDeviceConnectionJNI: close
2023-11-14 18:39:38.876 21443-21454/de.kai_morich.serial_usb_terminal D/UsbRequestJNI: close
Request: I am seeking guidance or insights into how the USB closure is being handled in the Play Store application. Specifically:
-
Is there a specific mechanism or delay implemented when closing the USB connection?
-
Could the immediate closure in my app be the reason behind the crash and the Arduino restart, and if so, how can I mitigate this?
Any help or suggestions on how to handle the USB connection closure gracefully, similar to how it's done in the Play Store app, would be greatly appreciated.
Thank you for your time and assistance.
both apps are basically identical with regards to connection handling
@kai-morich Thank you for letting me know. I figured out that if these two lines are not set to false, it's leading to a crash upon start. Just before I close, if I make setDTR and setRTS false, it works well.
https://github.com/kai-morich/SimpleUsbTerminal/blob/2ae8796fea3ac8ec1fccd09d3eedb07438ec5344/app/src/main/java/de/kai_morich/simple_usb_terminal/SerialSocket.java#L72-L73