예제 #1
0
  protected void flushSerialBuffer() throws RunnerException, SerialException {
    // Cleanup the serial buffer
    try {
      Serial serialPort = new Serial();
      byte[] readBuffer;
      while (serialPort.available() > 0) {
        readBuffer = serialPort.readBytes();
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
        }
      }

      serialPort.setDTR(false);
      serialPort.setRTS(false);

      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
      }

      serialPort.setDTR(true);
      serialPort.setRTS(true);

      serialPort.dispose();
    } catch (SerialNotFoundException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RunnerException(e.getMessage());
    }
  }
예제 #2
0
 /**
  * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently
  *     being used.
  */
 @SuppressWarnings({"rawtypes"})
 private static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
   HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
   Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
   while (thePorts.hasMoreElements()) {
     CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
     switch (com.getPortType()) {
       case CommPortIdentifier.PORT_SERIAL:
         try {
           CommPort thePort = com.open("CommUtil", 50);
           thePort.close();
           h.add(com);
         } catch (PortInUseException e) {
           System.out.println("Port, " + com.getName() + ", is in use.");
         } catch (Exception e) {
           System.err.println("Failed to open port " + com.getName());
           e.printStackTrace();
         }
     }
   }
   return h;
 }
예제 #3
0
  /** Send data to Serial Port (e.g FTDI module) */
  public void send(Data aData) throws IOException, BCDPrecisionException {
    try {
      /* Get frequency as BCD */
      Long frequencyBCD = aData.getDataAsBCD();

      /* Log */
      System.out.println(
          "Sending: " + frequencyBCD + ". It is 0x" + Long.toHexString(frequencyBCD) + " in BCD.");

      /* Send frequency */
      outputStream.write(Data.intToByteArray(frequencyBCD));
    } catch (BCDPrecisionException e) {
      System.err.println(
          "Impossible to send: "
              + e.getValue()
              + " using current precision. Try to send: "
              + e.getPossibleValue());

      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #4
0
  protected boolean executeUploadCommand(Collection commandDownloader) throws RunnerException {
    firstErrorFound = false; // haven't found any errors yet
    secondErrorFound = false;
    notFoundError = false;
    int result = 0; // pre-initialized to quiet a bogus warning from jikes

    String userdir = System.getProperty("user.dir") + File.separator;

    try {
      String[] commandArray = new String[commandDownloader.size()];
      commandDownloader.toArray(commandArray);

      String avrBasePath;

      if (Base.isLinux()) {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/");
      } else {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/avr/bin/");
      }

      commandArray[0] = avrBasePath + commandArray[0];

      if (verbose || Preferences.getBoolean("upload.verbose")) {
        for (int i = 0; i < commandArray.length; i++) {
          System.out.print(commandArray[i] + " ");
        }
        System.out.println();
      }
      Process process = Runtime.getRuntime().exec(commandArray);
      new MessageSiphon(process.getInputStream(), this);
      new MessageSiphon(process.getErrorStream(), this);

      // wait for the process to finish.  if interrupted
      // before waitFor returns, continue waiting
      //
      boolean compiling = true;
      while (compiling) {
        try {
          result = process.waitFor();
          compiling = false;
        } catch (InterruptedException intExc) {
        }
      }
      if (exception != null) {
        exception.hideStackTrace();
        throw exception;
      }
      if (result != 0) return false;
    } catch (Exception e) {
      String msg = e.getMessage();
      if ((msg != null)
          && (msg.indexOf("uisp: not found") != -1)
          && (msg.indexOf("avrdude: not found") != -1)) {
        // System.err.println("uisp is missing");
        // JOptionPane.showMessageDialog(editor.base,
        //                              "Could not find the compiler.\n" +
        //                              "uisp is missing from your PATH,\n" +
        //                              "see readme.txt for help.",
        //                              "Compiler error",
        //                              JOptionPane.ERROR_MESSAGE);
        return false;
      } else {
        e.printStackTrace();
        result = -1;
      }
    }
    // System.out.println("result2 is "+result);
    // if the result isn't a known, expected value it means that something
    // is fairly wrong, one possibility is that jikes has crashed.
    //
    if (exception != null) throw exception;

    if ((result != 0) && (result != 1)) {
      exception = new RunnerException(SUPER_BADNESS);
      // editor.error(exception);
      // PdeBase.openURL(BUGS_URL);
      // throw new PdeException(SUPER_BADNESS);
    }

    return (result == 0); // ? true : false;
  }
예제 #5
0
  // open a serial connection to a device.  We won't know it's the robot until
  public int OpenPort(String portName) {
    if (portOpened && portName.equals(recentPort)) return 0;

    ClosePort();

    Log("<font color='green'>Connecting to " + portName + "...</font>\n");

    // find the port
    try {
      portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    } catch (Exception e) {
      Log("<span style='color:red'>Ports could not be identified:" + e.getMessage() + "</span>\n");
      e.printStackTrace();
      return 1;
    }

    if (portIdentifier.isCurrentlyOwned()) {
      Log(
          "<span style='color:red'>Error: Another program is currently using this port."
              + "</span>\n");
      return 2;
    }

    // open the port
    try {
      commPort = portIdentifier.open("DrawbotGUI", 2000);
    } catch (Exception e) {
      Log("Port could not be opened:" + e.getMessage() + NL);
      e.printStackTrace();
      return 3;
    }

    if ((commPort instanceof SerialPort) == false) {
      Log("<span style='color:red'>Only serial ports are handled by this example." + "</span>\n");
      return 4;
    }

    // set the port parameters (like baud rate)
    serialPort = (SerialPort) commPort;
    try {
      serialPort.setSerialPortParams(
          BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    } catch (Exception e) {
      Log("<span style='color:red'>Port could not be configured:" + e.getMessage() + "</span>\n");
      return 5;
    }

    try {
      in = serialPort.getInputStream();
      out = serialPort.getOutputStream();
    } catch (Exception e) {
      Log("<span style='color:red'>Streams could not be opened:" + e.getMessage() + "</span>\n");
      return 6;
    }

    try {
      serialPort.addEventListener(this);
      serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException e) {
      Log("<span style='color:red'>Streams could not be opened:" + e.getMessage() + "</span>\n");
      return 7;
    }

    Log("<span style='green'>Opened.</span>\n");
    SetRecentPort(portName);
    portOpened = true;
    UpdateMenuBar();

    return 0;
  }
  // --------------------------getDecryptedRecieptData-------------------------------------------------------------
  // public String getDebitCmd(String stCardRndNo, String stTerRndNo, String stAmt, String stPurse)
  // throws Exception {
  public String getDecryptedRecieptData(ETerminalDataDto objETerminalDataDto) throws Exception {

    // ETerminalDataDto objETerminalDataDto=new ETerminalDataDto();

    String strDecryptedRecieptDataRefNo = "";
    String strDecryptedRecieptData = "";
    String strResHeader = "";

    // String strDebitCmd=null;
    try {
      ezlink.info(
          "\n-------SerialManager--------------START----4 decrypting RecieptData-------------------");
      ezlink.info("getDecryptedRecieptData Request received in " + SerialManager.class.getName());
      // Commet this after testing with main method;
      // serialDemo.initConfig()
      // serialDemo.connection.sendMessage(ISOUtil.hex2byte("020079600037000002007024058000C10004164999770007848180000000000000011111011000100309020037003237303031393630313638313638313035323934202020000334343400063031313030320388"));

      // Debit command
      byte[] decRecieptData = null;
      try {
        decRecieptData =
            connection.sendMessage(
                ISOUtil.hex2byte(
                    HeaderUtil.getReqRecieptData(
                        objETerminalDataDto.getRecieptData(),
                        objETerminalDataDto.getTerminalSessionKey(),
                        objETerminalDataDto.getDebitSessionKey(),
                        objETerminalDataDto.getCan(),
                        objETerminalDataDto.getEzLinkString(),
                        "")));
      } catch (Exception e) {
        e.printStackTrace();
      }
      System.out.println("Decrypted Reciept Data=" + ISOUtil.hexString(decRecieptData));
      ezlink.info("Decrypted Reciept Data= : " + ISOUtil.hexString(decRecieptData));
      String strResponse = ISOUtil.hexString(decRecieptData);
      ezlink.info("+++Decrypted Reciept Data strResponse Length : " + strResponse.length());
      ezlink.info("+++Decrypted Reciept Data strResponse  : " + strResponse);
      //          if (strResponse.length() == 222) {
      // ezlink.info("+++Inside IF  :
      // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" );

      strResHeader = strResponse.substring(0, 34);
      strDecryptedRecieptDataRefNo = strResponse.substring(44, 68); // 24

      strDecryptedRecieptData = strResponse.substring(78, strResponse.length() - 2);

      System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
      System.out.println("Last two digits: " + strResponse.substring(strResponse.length() - 2));
      System.out.println("Response length : " + strResponse.length());
      System.out.println("Response from terminal DC : " + strResponse);
      System.out.println("Decrypted Ezlink String : " + strDecryptedRecieptData);
      System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      ezlink.info(
          "\n--------SERIAL MANAGER-------RESPONSE----4DecryptedRecieptData----------------");
      ezlink.info("strResHeader : " + strResHeader);

      ezlink.info("strDecryptedRecieptDataRefNo : " + strDecryptedRecieptDataRefNo);
      ezlink.info("strDecryptedRecieptData : " + strDecryptedRecieptData);
      ezlink.info("\n--------SERIAL MANAGER-------RESPONSE--------------------");

      // strDebitCmd = "250315021403" + stTerRndNo + strActDebitCmd + strUserData;
      // System.out.println("strDebitCmd= " + strDebitCmd + "  Len  " + strDebitCmd.length());
      // ezlink.info("strDebitCmd= " + strDebitCmd + " Len : " + strDebitCmd.length());

      /*
                  } else {
                      //ezlink.info("+++Inside IF  : ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" );
                      System.out.println("Response from the Terminal not received fully...");
                      ezlink.info("Response from the Terminal not received fully...!!!!!!!");
                  }
      */
    } catch (Exception exp) {
      System.out.println(exp);
      ezlink.error(new Object(), exp);
      throw exp;
    }

    return strDecryptedRecieptData;
  }