Serial library - catch port busy


I work with a bluetooth serial device and I regularly get the message: Error opening serial port... : Port Busy.

When I retry a few times I can get a connection. Is there a way that I can catch the error in my program itself and retry the connection.

So when this happens I could run something like:

port = new Serial(this, Serial.list()[portNumber], 9600); 


  • Hi, I'm workin with the same thing about connecting the mobile device through bluetooth serial port and I always get the error message just like yours. Error opening serial port...: Port busy.

    After I disconnected the bluetooth between my mac and the mobile, the println(Serial.list()); still listed the serial port which should be appeared when connecting. I don't get it. Can you tell me how to solve this problem?

    Thanks.螢幕快照 2014-10-19 上午2.42.15

  • I have the same problem but only with windows 8, my code working on win 7. I use BT connection but when I restart the sketch I got an error "Port busy" only computer restart helps. So, if anyone know how to release the port on windows 8, please give me a solution. I tried the @kasperkamperman's solution and not working for my case.

  • Hi wrzaskun, I have the same issue of you as I posted here

    Have you solved in some way?

    Please if you have suggestions tell me.

  • First check the correct port number you are trying to access and then if problem of port busy persists requiring you to restart, easy way is to uninstall & re-install the device from Windows Device Manager. At least you don't have to restart your computer.

  • edited January 2017

    Try this, it's just a workaround-

    boolean connect(int portNumber, int baudRate, int limit){
      int tries = 0;
      while(tries < limit){
          port = new Serial(this, Serial.list()[portNumber], baudRate);
        }catch(Exception e){
      if(tries < limit){
        println("Successful in " + str(tries + 1) + " tries.");
        return true;
        System.err.println("Unsucessful. Reached limit.");
        return false;
Sign In or Register to comment.