private static void resetAll() {
   core.discharge();
   core = new ComCoreDummy();
   for (Communication c : Communication.values()) {
     c.internal_reset();
   }
   initThread.interrupt();
   Communication.class.notifyAll();
 }
 public static ArrayList<Integer> getPortsSpeeds() {
   return AComCore.getPortsSpeeds();
 }
 public static ArrayList<String> getPortsNames() {
   return AComCore.getPortsNames();
 }
 public static synchronized boolean isSimulation() {
   return core.isSimulation();
 }
 public static synchronized boolean isConnected() {
   return core.isConnected() && I().internal_isConnected() && !initThread.isAlive();
 }
  public static synchronized void connect(final String port, final int speed) {
    // allready connected
    if (isConnected()) {
      doChangedEvent(status);
      return;
    }

    // allready running init
    if (core.isSimulation() && initThread.isAlive()) {
      return;
    }

    // Prepair connection
    resetAll();

    doChangedEvent("Connecting ... ");

    // Do not block GUI:
    initThread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                synchronized (Communication.class) {

                  // Try to open Port
                  try {
                    core =
                        AComCore.openPort(
                            new IReceivedLines() {
                              @Override
                              public void received(String[] lines) {
                                Communication.receive(lines);
                              }
                            },
                            new IDisconnect() {
                              @Override
                              public void disconnect(String status) {
                                synchronized (Communication.class) {
                                  resetAll();
                                  doChangedEvent(status);
                                }
                              }
                            },
                            port,
                            speed);
                  } catch (Exception ex) {
                    resetAll();
                    doChangedEvent(ex.getMessage());
                    return;
                  }
                  try {
                    // Run connect
                    I().internal_connect();

                  } catch (InterruptedException | MyException ex) {
                    Logger.getLogger(Communication.class.getName()).log(Level.SEVERE, null, ex);
                    resetAll();
                    doChangedEvent(ex.getMessage() == null ? status : ex.getMessage());
                    return;
                  }

                  doChangedEvent("Connected!");
                  Communication.class.notify();
                }
              }
            });
    initThread.start();

    // Wait for initThread to be started
    while (initThread.getState() == Thread.State.NEW) {
      try {
        Thread.sleep(1);
      } catch (InterruptedException ex) {
        Logger.getLogger(Communication.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }