WIP170315

thobaben_serialize
Harald Wolff 2017-03-15 11:37:56 +01:00
parent efca7b8466
commit 4b42b2d53d
9 changed files with 23 additions and 14 deletions

View File

@ -5,7 +5,7 @@
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="org.hwo/src/native"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="contrib/javassist-3.15.0-GA.jar"/>
<classpathentry kind="lib" path="contrib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="contrib/cglib-nodep-3.1.jar"/>

View File

@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -30,6 +30,7 @@ public class NewSerialPort {
public static long nsp_RET_OTHER = -99; // Unbekannter Fehler
public static long EAGAIN;
String portName;
int baudRate;
@ -164,6 +165,7 @@ public class NewSerialPort {
}
public void setTimeOut(int timeout){
this.timeout = timeout;
log(DEBUG,"NSP: setTimeOut( %d )",timeout);
nsp_setup_timeout(nsp, timeout);
}
@ -264,20 +266,22 @@ public class NewSerialPort {
private static native int nsp_read_bytes(long nsp,byte[] bytes,int offset,int len);
private static native int nsp_write_bytes(long nsp,byte[] bytes,int offset,int len);
private static native int nsp_EAGAIN();
static {
NativeLoader.loadLibrary("nsp");
}
EAGAIN = nsp_EAGAIN();
}
public class NewSerialPortInputStream extends InputStream
{
@Override
public int read() throws IOException {
if (autoOpen && !isOpen())
open();
log(DEBUGDETAIL,"NSP::read()");
int ch = nsp_read(nsp);
if (ch < 0){
if (ch == nsp_RET_TIMEOUT)
@ -299,9 +303,11 @@ public class NewSerialPort {
@Override
public int read(byte[] b, int off, int len) throws IOException {
//log(DEBUGDETAIL,"NSP::read()");
int nRead = nsp_read_bytes(nsp, b, off, len);
if (nRead < 0){
if (nRead == -11){ // -EAGAIN (timeout, keine zeichen verfügbar)
if (nRead == EAGAIN){ // -EAGAIN (timeout, keine zeichen verfügbar)
return 0;
};
throw new IOException(String.format("nsp_read_bytes() returned %d", nRead));
@ -359,10 +365,13 @@ public class NewSerialPort {
public void write(byte[] b, int off, int len) throws IOException {
int nWritten = 0;
for (int redo=0;redo<5;redo++){
log(DEBUGDETAIL,"NSP::write(...)");
for (int redo=0; redo < 5 ; redo++){
nWritten = nsp_write_bytes(nsp, b, off, len);
if (nWritten == -11){
if (nWritten == EAGAIN){
try {
log(DEBUGDETAIL,"SL-TX-EAGAIN... [%d]",redo);
Thread.sleep(5);
} catch (Exception e){
@ -405,10 +414,10 @@ public class NewSerialPort {
for (int i = 1; i < 32; i++)
{
sp.setPortName(String.format("COM%d:",i));
sp.setPortName(String.format("COM%d",i));
if (sp.open())
{
portNames.add(String.format("COM%d:",i));
portNames.add(String.format("COM%d",i));
sp.close();
}
}