Example #1
0
  /**
   * Starts the main process and listens to Communication errors with device. In case of
   * communication errors, this will re-initiate the main process.
   */
  public void start() {

    reader = new ConcurrentReader(this.comport);
    try {
      reader.start();
    } catch (NoSuchPortException ex) {
      showErrorMessage("NO communication device is connected to " + this.comport + " !", "ERROR!");
      logger.error("NO communication device is connected to " + this.comport, ex); // logger
      return;
    } catch (PortInUseException ex) {
      showErrorMessage(
          "Another program is using the selected port! \n"
              + "Try reconnecting after the other program finishes.",
          "ERROR: Port in use!");
      logger.error("Another program is using the selected port: ", ex); // logger
      return;
    } catch (IOException | TooManyListenersException ex) {
      logger.error("start() method", ex); // logger
      return;
    }

    runner =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                while (true) {
                  try {
                    Thread.sleep(5000);
                    if (!reader.isReaderAlive() || !reader.isWriterAlive()) {
                      reader.stop();
                      logger.info("Reader & Writer Threads are DEAD!"); // logger
                      reader.restart();
                      logger.info("Restarted."); // logger
                    }
                  } catch (InterruptedException ex) {
                    logger.warn("Thread interrupted", ex);
                    return;
                  }
                }
              }
            });
    runner.start();
  }
Example #2
0
 /** Stops the main process by terminating ProcessRunner. */
 public void stop() {
   logger.info("ProcessRunner stopping............");
   runner.interrupt();
   reader.stop();
 }