-
Notifications
You must be signed in to change notification settings - Fork 55
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
Always try to close a port before opening. #24
Conversation
…ports being locked open when an error occurrs during a run.
Yes, I have tried it many times and it works reliably. I actually took this code from the disconnect method, so I am guessing that the disconnect method is not run when there is an error, so it just aborts with the port still open. Since I wrapped the close statements inside a "try" and catch all errors and just let them fail silently, it does not seem to do any harm. If the port is open, then it gets closed. If the port is closed, then this code just silently fails and proceeds to open the port as usual. And yes, I did get a "null" error originally, which lead me to add the "try" and "catch" bits. I am sure there is a more elegant way of doing this (maybe run the disconnect method instead of my code), but I have no experience with Java and have only dabbled in programming a few other languages. |
Ok, so I will keep this in mind and if there are exceptions, which we cannot fix permanentely, I will change the send-job-method to contain a try-catch block on everything, with a finally-block which calls the disconnect method, even if an exception occurs during the try block. However I'd rather fix the code to not throw any exceptions during normal operation ;). Thanks for your work. I hope you don't mind me closing this request, since it seems somewhat "hacky" to me to just close the port "just in case". |
I don't mind at all. It was most definitely a "hack". I did confirm that Keep in mind that I am trying to help, since I know you are busy. If I am On Mon, Aug 3, 2015 at 11:13 PM Thomas Oster notifications@github.com
|
Hi, you are welcome to help. The right place would not be the catch, but the finally block, look here: https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html. |
I'll look into that tomorrow. It's nearly 1am here so time to sleep. I will
|
This takes care of serial ports being locked open when an error occurs during a run.