forked from LupusNobilis/java-org.hwo
NewSerialPort Fixes
parent
fa3eaffc18
commit
4558ca16b0
|
@ -16,6 +16,9 @@ import org.hwo.io.SerialPortWINDOWS;
|
||||||
import org.hwo.platform.Platform;
|
import org.hwo.platform.Platform;
|
||||||
import org.hwo.platform.natives.NativeLoader;
|
import org.hwo.platform.natives.NativeLoader;
|
||||||
|
|
||||||
|
import static org.hwo.logging.Logging.*;
|
||||||
|
import static org.hwo.logging.LogLevel.*;
|
||||||
|
|
||||||
public class NewSerialPort {
|
public class NewSerialPort {
|
||||||
|
|
||||||
public static long nsp_RET_OK = 0; // Kein Fehler
|
public static long nsp_RET_OK = 0; // Kein Fehler
|
||||||
|
@ -288,6 +291,7 @@ public class NewSerialPort {
|
||||||
@Override
|
@Override
|
||||||
public void write(int arg0) throws IOException{
|
public void write(int arg0) throws IOException{
|
||||||
int r;
|
int r;
|
||||||
|
boolean retry = true;
|
||||||
|
|
||||||
if (autoOpen && !isOpen())
|
if (autoOpen && !isOpen())
|
||||||
open();
|
open();
|
||||||
|
@ -295,16 +299,26 @@ public class NewSerialPort {
|
||||||
if (!isOpen())
|
if (!isOpen())
|
||||||
throw new IOException("Port not opened");
|
throw new IOException("Port not opened");
|
||||||
|
|
||||||
r = nsp_write(nsp, arg0);
|
while (true){
|
||||||
if (r<0){
|
r = nsp_write(nsp, arg0);
|
||||||
if (r == nsp_RET_NOTOPEN)
|
if (r == -11){ // -EAGAIN
|
||||||
NewSerialPort.this.close();
|
try {
|
||||||
if (r == nsp_RET_OTHER){
|
Thread.sleep(5);
|
||||||
NewSerialPort.this.close();
|
} catch (InterruptedException e){
|
||||||
NewSerialPort.this.open();
|
log(e);
|
||||||
}
|
}
|
||||||
|
} else if (r<0){
|
||||||
throw new IOException(String.format("nsp_write()=%d", r));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue