buffer.append(serial.read());
// when done reading, emit the event if there are any listeners
if (!listeners.isEmpty()) {
// iterate over the listeners and send the data events
SerialDataEvent event = new SerialDataEvent(serial, buffer.toString());
for (SerialDataListener sdl : listeners) {
sdl.dataReceived(event);
}
}
}