-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to catch exception when disconnecting USB-COM device #108
Comments
ATM there is no way to catch that except by using Thread.setDefaultUncaughtExceptionHandler and of course you can modify the PJC code.
Why do you want to catch that exception?
wbr Kusti
… On 6 Aug 2018, at 17:16, jreker ***@***.***> wrote:
Hello,
i am curently experimenting with PJC. I want to use it in a production enviroment.
My problem is, that the lib threws a exception when i disconnect my COM device ( just unplug the cable):
This is the exception i got:
jtermios.windows.JTermiosImpl$Fail
at jtermios.windows.JTermiosImpl$Port.fail(JTermiosImpl.java:100)
at jtermios.windows.JTermiosImpl.select(JTermiosImpl.java:924)
at jtermios.JTermios.select(JTermios.java:474)
at purejavacomm.PureJavaSerialPort$3.run(PureJavaSerialPort.java:1228)
at java.lang.Thread.run(Thread.java:748)
That's good, but i cannot catch the exception because it appears an another thread i think. Is there already a solution for this problem?
Thanks in advance.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I want to catch it, because i want to react when the device is disconnected to set a error message. |
On 7 Aug 2018, at 09:18, jreker ***@***.***> wrote:
I want to catch it, because i want to react when the device is disconnected to set a error message.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
I see.
Well, that is a legitimate wish and request.
At this point in time I think you better just hack the code, add a global catcher
or do not use the event model and implement your own so you can catch the exception
in your code.
Adding an event for unplug would be an extension to JavaComm spec and thus would
need to be carefully considered how it is best done.
wbr Kusti
|
I tried to change your code but without luck. It was not working. The problem is the runnable in the constructor of the class "PureJavaSerialPort". I try to change it to callable but then the code inside the callable was not working as before. My workaround now was that i created a watchdog thread and send periodically data to my serial device so that i will get a exception when it is not possible to send data to the device. I was great when it is possible to integrate an event for unplug or change to code that the exception was rethrown. Thanks |
I also wanted some callback to know if the main thread failed. I also resorted to using an external watch dog of sorts but in my code I do a simple check of the NativeFileDescriptor
I used this in my manager class like this:
|
Hello,
i am curently experimenting with PJC. I want to use it in a production enviroment.
My problem is, that the lib threws a exception when i disconnect my COM device ( just unplug the cable):
This is the exception i got:
That's good, but i cannot catch the exception because it appears an another thread i think. Is there already a solution for this problem?
Thanks in advance.
The text was updated successfully, but these errors were encountered: