Here is the code snippet
Here i am initiating an Action Listener
try {
port_seleted.addEventListener(this);
} catch (TooManyListenersException e) {
System.out.println("too many Listeners!");
}
port_seleted.notifyOnDataAvailable(true);
Here the below method is called when i receive the data
public void serialEvent(SerialPortEvent Ack_Rec) {
boolean first_flash = false;
if (Ack_Rec.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
while (input_data.available() > 0) {
input_data.read(rec_ack);
}
} catch (IOException e) {
System.out.println("IO Exception in SerialEvent");
}
I am not receiving the data properly, i.e
if I send some data as " Hello How are you doing today" it is received as "Hello h" "ow" " are you" " doin" "g today"
i.e the Serial event method is being called multiple times, i.e it is exiting the while loop before complete data is read.
If i insert a delay
try {
while (input_data.available() > 0) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
input_data.read(rec_ack);
}
} catch (IOException e) {
System.out.println("IO Exception in SerialEvent");
}
as shown above, it is working fine. Please help me how to remove the delay, as it is decreasing the efficiency!