class PortReader implements SerialPortEventListener {
public static MainScreenController ms_controller;
@Override
public void serialEvent(SerialPortEvent event) {
if(event.isRXCHAR() && event.getEventValue() > 0){
try {
String text = serialPort.readString();
Platform.runLater(new Runnable() {
@Override
public void run() {
ms_controller.main_label.setText(text);
}
});
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
}
}
public class MainScreenController extends PortReader implements Initializable {
@FXML
public Label main_label;
@Override
public void initialize(URL url, ResourceBundle rb) {
PortReader.ms_controller = this;
serialStart();
}
}