diff --git a/src/org/hwo/io/NewSerialPort/NewSerialPort.java b/src/org/hwo/io/NewSerialPort/NewSerialPort.java index c2cb111..ac2d5c4 100644 --- a/src/org/hwo/io/NewSerialPort/NewSerialPort.java +++ b/src/org/hwo/io/NewSerialPort/NewSerialPort.java @@ -16,6 +16,9 @@ import org.hwo.io.SerialPortWINDOWS; import org.hwo.platform.Platform; import org.hwo.platform.natives.NativeLoader; +import static org.hwo.logging.Logging.*; +import static org.hwo.logging.LogLevel.*; + public class NewSerialPort { public static long nsp_RET_OK = 0; // Kein Fehler @@ -288,6 +291,7 @@ public class NewSerialPort { @Override public void write(int arg0) throws IOException{ int r; + boolean retry = true; if (autoOpen && !isOpen()) open(); @@ -295,16 +299,26 @@ public class NewSerialPort { if (!isOpen()) throw new IOException("Port not opened"); - r = nsp_write(nsp, arg0); - if (r<0){ - if (r == nsp_RET_NOTOPEN) - NewSerialPort.this.close(); - if (r == nsp_RET_OTHER){ - NewSerialPort.this.close(); - NewSerialPort.this.open(); - } - - throw new IOException(String.format("nsp_write()=%d", r)); + while (true){ + r = nsp_write(nsp, arg0); + if (r == -11){ // -EAGAIN + try { + Thread.sleep(5); + } catch (InterruptedException e){ + log(e); + } + } else if (r<0){ + if (r == nsp_RET_NOTOPEN) + NewSerialPort.this.close(); + if (r == nsp_RET_OTHER){ + NewSerialPort.this.close(); + NewSerialPort.this.open(); + } + + throw new IOException(String.format("nsp_write()=%d", r)); + } else { + break; + } } } }