How check if a Port is busy and how prevent a crash when trying to a busy port.

edited March 2017 in Arduino

I have written some code which automatically connects to every COM port on your PC and listens to it for 2.5 seconds. If the computer receives a or several byte(s) it stays connected with that COM port. Otherwise it moves to the next. And it works quite nicely, it also works when you plug in an Arduino or something when the program is already running.

However when I try to connect with a COM port which is 'busy', the program crashes. I won't be dealing with already connected COM ports but I do like to know how I can:

  1. verifiy that I am connected with a COM port or not? (when I yank out an USB cable for example)
  2. check if a COM port is busy or not? (check if I can connect with that COM port or not)

3. deal with the error you get when you try to connect with a busy COM port? (special Event Handler?) RuntimeException solves dat problem.

Sign In or Register to comment.