NewSerialPort Fixes

thobaben_serialize
Harald Wolff 2016-12-07 09:01:19 +01:00
parent fa3eaffc18
commit 4558ca16b0
1 changed files with 24 additions and 10 deletions

View File

@ -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;
}
}
}
}