Running a method after the end of the response from serialPort?

38 views Asked by At

I am sending a bunch of commands and receiving a response from the serialPort using JSSC Library. At the end of the response, I get three similar responses but with different sequence numbers? like

  • l1~cdo~100~1~
  • l1~cdo~101~1~
  • l1~cdo~102~1~

The pattern is the same every time but the numbers changes. The last message l1~cdo~102~1~ indicates the end of the response and I have to run a method that prints a receipt after the last response. How can I achieve it?

response is a response from the serialport. is there anyway to capture the last response sequence and create another if statement inside the previous one and compare it like:

  if((response.startswith("l1~cdo~")){

//capturing the response and extracting the sequence
    String number = response.replaceAll("[^0-9]", "");
    StringBuilder builder = new StringBuilder(number);
    builder.deleteCharAt(0);
    builder.deleteCharAt(builder.length() - 1);
        if(response.startsWith("l1~cdo~"+builder)){
            serialPort.printReceipt();
        }
  }

At this point it will run printReceipt 3 times. Thank you!

0

There are 0 answers