refactoring
This commit is contained in:
parent
ffdd799f6c
commit
78dae10218
|
@ -62,7 +62,7 @@ public class SerialIoStream implements IoStream {
|
|||
public void setDataListener(DataListener listener) {
|
||||
try {
|
||||
SerialPortReader reader = new SerialPortReader(serialPort, listener);
|
||||
serialPort.addEventListener(reader);
|
||||
serialPort.addEventListener(reader.getSerialPortEventListener());
|
||||
reader.readInitial();
|
||||
} catch (SerialPortException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
* Date: 12/25/12
|
||||
* (c) Andrey Belomutskiy
|
||||
*/
|
||||
public class SerialPortReader implements SerialPortEventListener {
|
||||
public class SerialPortReader {
|
||||
private static final int[] SLEEP_DURATIONS = {2, 20, 50, 100};
|
||||
private final SerialPort serialPort;
|
||||
private DataListener listener;
|
||||
|
@ -61,6 +61,9 @@ public class SerialPortReader implements SerialPortEventListener {
|
|||
return null;
|
||||
}
|
||||
|
||||
private SerialPortEventListener serialPortEventListener = new SerialPortEventListener() {
|
||||
|
||||
|
||||
public void serialEvent(SerialPortEvent spe) {
|
||||
if (spe.isRXCHAR() || spe.isRXFLAG()) {
|
||||
// event-based serial read implementation does not work well on Windows 10 for some reason
|
||||
|
@ -74,6 +77,7 @@ public class SerialPortReader implements SerialPortEventListener {
|
|||
FileLog.MAIN.logLine("less expected SerialPortReader serialEvent " + spe.getEventType());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// private void handleRx(SerialPortEvent spe) throws SerialPortException {
|
||||
// if (spe.getEventValue() > 0) {
|
||||
|
@ -92,4 +96,8 @@ public class SerialPortReader implements SerialPortEventListener {
|
|||
listener.onDataArrived(data);
|
||||
}
|
||||
}
|
||||
|
||||
public SerialPortEventListener getSerialPortEventListener() {
|
||||
return serialPortEventListener;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue