Example #1
0
  public String Write_USB_Port(byte[] message_press) {
    String message = "";

    if (connection != null) {
      try {
        // port.write(message,10);
        // byte[] Release =new byte[]{ (byte)0x48, 0x0d };
        port.write(message_press, 100);
        message = " Sent: " + new String(message_press);
        Log.v(TAG, "Value Writing to the Press: " + new String(message_press));
        SystemClock.sleep(110);
        // new Thread(new Runnable() {
        //     @Override
        //     public void run() {
        //         try {
        //             Thread.sleep(1500);

        //         } catch (InterruptedException e) {
        //             e.printStackTrace();
        //         }
        //     }
        // }).start();
        // SystemClock.sleep(400);
        // Thread.sleep(400);
        // port.write(message_release, 100);

        // HeaderText.append(" Also Sent: " + new String(message_release));
        // port.write(concat(message,Release),10);

      } catch (IOException e) {
        Log.v(TAG, "Error Sending Command!");
        message = "Couldn't Send message";
        // alertView("Port Error", "Can't Send Message");
      }
      try {
        port.close();
        Log.v(TAG, "Port Successfully Closed");

      } catch (IOException e) {
        Log.v(TAG, "Couldn't close Port");
        // alertView("Port Error", "Can't Close Port");
      }

    } else {
      Log.v(TAG, "Not Connected to USB!");
      message = "Not Connected to USB";
    }
    return message;
  }