private void SetModeCommand(String command, String modeButton) throws IOException {
    System.out.println(command);
    out.write(ConversionUtils.stringToBytes(command + "\n"));

    checkMessageReceived();

    System.out.println(modeButton);
    out.write(ConversionUtils.stringToBytes(modeButton + "\n"));

    checkMessageReceived();
  }
  private void switchModeForSaving(int modeToLoad) {
    try {
      out.write(ConversionUtils.stringToBytes("AT NEXT\n"));

      checkMessageReceived();
      checkMessageReceived();

      out.write(ConversionUtils.stringToBytes("AT LOAD " + modeToLoad + "\n"));

      checkMessageReceived();
      checkMessageReceived();

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 public void SetCommand(String command) throws IOException {
   System.out.println(command);
   out.write(ConversionUtils.stringToBytes(command + "\n"));
   String message = checkMessageReceived();
   //		System.out.println(message);
   if (message.contains("2.0")) {
     System.out.println("Fabi2.0 is detected!");
   } else {
     System.out.println("#ERROR: Only Fabi2.0 is supported!");
   }
 }
  private void saveToEEPROM(int modeToLoad) {
    try {
      System.out.println("save mode to EEPROM");
      out.write(ConversionUtils.stringToBytes("AT SAVE " + modeToLoad + "\n"));

      checkMessageReceived();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
        public void receiveEvent(final String data) {
          SetBusyEvent();
          deleteEEPROM();

          if (selectedConsole == null) {
            selectedConsole = consoles.get(0);
            OutputConsole(selectedConsole);
            SetReadyEvent();
            return;
          }

          int index = consoles.indexOf(selectedConsole);

          if (index < 0) {
            selectedConsole = consoles.get(0);
            OutputConsole(selectedConsole);
            SetReadyEvent();
            return;
          }

          if ((consoles.size() - 1) >= (index + 1)) {
            if (consoles.get(index + 1) != null) {
              selectedConsole = consoles.get(index + 1);

              // setMode(consoles.get(index+1),
              // games.get(index+1).get(0));
            }
          } else if (consoles.get(0) != null) {
            selectedConsole = consoles.get(0);
            // setMode(consoles.get(0), games.get(consoles.get(0)).get(0));
          }

          OutputConsole(selectedConsole);
          opOutGame.sendData(ConversionUtils.stringToBytes(""));
          opOutMode.sendData(ConversionUtils.stringToBytes(""));
          SetReadyEvent();

          loadNewModel(selectedConsole);
        }
  private void deleteEEPROM() {

    try {
      if (out == null) {
        System.out.println("Problem with COM Port!");
        return;
      }
      System.out.println("AT CLEAR");
      out.write(ConversionUtils.stringToBytes("AT CLEAR\n"));
      checkMessageReceived();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  private void switchMode(int modeToLoad) {
    ShowButtons(modeToLoad);
    ShowButtons(modeToLoad);
    try {
      OutputMode(modeToLoad);
      System.out.println("switch Mode");

      out.write(ConversionUtils.stringToBytes("AT LOAD " + modeToLoad + "\n"));

      checkMessageReceived();
      checkMessageReceived();

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void ShowButtons(int modeToLoad) {
    String buttons = "";
    ArrayList<ArrayList<String>> eachMode;
    Map<String, ArrayList<ArrayList<String>>> gameMode;

    gameMode = modes.get(selectedConsole.toUpperCase());
    eachMode = gameMode.get(selectedGame.toUpperCase());

    ArrayList<String> mode = eachMode.get(modeToLoad - 1);
    for (String config : mode) {
      if (config.contains("KEY_CTRL KEY_ESC")) {
        config = "Modus/Zurueck";
      } else if (config.contains("KEY_")) {
        config = config.replace("KEY_", "");
      }
      buttons += config + ",";
    }
    System.out.println("Buttons : " + buttons);
    opOutButtons.sendData(ConversionUtils.stringToBytes(buttons));
  }
 public void loadNewModel(String model) {
   opOutModel.sendData(ConversionUtils.stringToBytes(model + ".acs"));
   etploadModel.raiseEvent();
 }
 public void OutputGame(String text) {
   System.out.print(
       "################################################################################");
   System.out.println("Load Game " + text);
   opOutGame.sendData(ConversionUtils.stringToBytes(text));
 }