Skip to content

Commit

Permalink
New feature of closing the Monitor thread when the hardware disconnects
Browse files Browse the repository at this point in the history
This is to address #75 It is a very old bug, predates my interaction
with this codebase.
  • Loading branch information
madhephaestus committed May 6, 2020
1 parent 5a58c6b commit 60aaeea
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
.settings/
*~*
/.gradle/
/hs_err_pid26993.log
1 change: 1 addition & 0 deletions src/main/c/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build
.project
.cproject
/Default/
2 changes: 1 addition & 1 deletion src/main/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LININCLUDE= -I./include -I./include/target -I$(JDKLOCATION)/include -I$(JDKLO
CCLIN32=gcc $(LININCLUDE) -I./include/ubuntu-multilib-fix -O3 -Wall -fmessage-length=0 -fPIC -m32 -MMD
LINKLIN32=gcc -m32 -shared

CCLIN64=gcc $(LININCLUDE) -O3 -Wall -fmessage-length=0 -fPIC -m64 -MMD
CCLIN64=gcc $(LININCLUDE) -O3 -Wall -fmessage-length=0 -fPIC -m64 -MMD
LINKLIN64=g++ -m64 -shared

CCLINARM32=arm-linux-gnueabi-gcc $(LININCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP
Expand Down
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv5.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6_HF.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7_HF.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8_HF.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/ARM_64/libNRJavaSerialv8.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/x86_32/libNRJavaSerial.so
Binary file not shown.
Binary file modified src/main/c/resources/native/linux/x86_64/libNRJavaSerial.so
Binary file not shown.
Binary file modified src/main/c/resources/native/windows/x86_32/libNRJavaSerial.dll
Binary file not shown.
Binary file modified src/main/c/resources/native/windows/x86_64/libNRJavaSerial.dll
Binary file not shown.
10 changes: 9 additions & 1 deletion src/main/c/src/SerialImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3690,7 +3690,7 @@ JNIEXPORT jint JNICALL RXTXPort(nativeavailable)( JNIEnv *env,
jobject jobj )
{
int fd = get_java_var( env, jobj,"fd","I" );
int result;
int result=-1;
/*
char message[80];
Expand Down Expand Up @@ -4265,6 +4265,13 @@ JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj )
do{
report_time_eventLoop( );
do {
if(RXTXPort(nativeavailable)( env, jobj )<0){
report("eventLoop: Hardware Missing\n");
finalize_threads( &eis );
finalize_event_info_struct( &eis );
LEAVE("eventLoop:error");
return;
}
/* nothing goes between this call and select */
if( eis.closing )
{
Expand Down Expand Up @@ -4304,6 +4311,7 @@ JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj )
}
i = 0;
#endif /* WIN32 */

} while ( eis.ret < 0 && errno == EINTR );
if( eis.ret >= 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gnu/io/RXTXPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class RXTXPort extends SerialPort
static
{
try {
z = new Zystem();
z = new Zystem(Zystem.SILENT_MODE);
} catch ( Exception e ) {}

if(debug )
Expand Down
59 changes: 59 additions & 0 deletions test/src/test/ReadTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.TooManyListenersException;

import gnu.io.NRSerialPort;
import gnu.io.Zystem;
public class ReadTest {
public static void main(String [] args) {

String port = "";
for(String s:NRSerialPort.getAvailableSerialPorts()){
System.out.println("Availible port: "+s);
port=s;
}

int baudRate = 115200;
NRSerialPort serial = new NRSerialPort(port, baudRate);
serial.connect();
DataInputStream ins = new DataInputStream(serial.getInputStream());
try {
serial.addEventListener(ev->{
//while(ins.available()==0 && !Thread.interrupted());// wait for a byte
try {
while(ins.available()>0) {// read all bytes

char b = (char) ins.read();
//outs.write((byte)b);
System.out.print(b);

}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
} catch (TooManyListenersException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
// DataOutputStream outs = new DataOutputStream(serial.getOutputStream());
// try{
// //while(ins.available()==0 && !Thread.interrupted());// wait for a byte
// while(!Thread.interrupted()) {// read all bytes
// if(ins.available()>0) {
// char b = (char) ins.read();
// //outs.write((byte)b);
// System.out.print(b);
// }
// Thread.sleep(5);
// }
// }catch(Exception ex){
// ex.printStackTrace();
// }
// serial.disconnect();
}
}

0 comments on commit 60aaeea

Please sign in to comment.