Skip to content

Commit 60aaeea

Browse files
committed
New feature of closing the Monitor thread when the hardware disconnects
This is to address #75 It is a very old bug, predates my interaction with this codebase.
1 parent 5a58c6b commit 60aaeea

18 files changed

+72
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
.settings/
88
*~*
99
/.gradle/
10+
/hs_err_pid26993.log

src/main/c/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/build
22
.project
33
.cproject
4+
/Default/

src/main/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LININCLUDE= -I./include -I./include/target -I$(JDKLOCATION)/include -I$(JDKLO
2323
CCLIN32=gcc $(LININCLUDE) -I./include/ubuntu-multilib-fix -O3 -Wall -fmessage-length=0 -fPIC -m32 -MMD
2424
LINKLIN32=gcc -m32 -shared
2525

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

2929
CCLINARM32=arm-linux-gnueabi-gcc $(LININCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/main/c/src/SerialImp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3690,7 +3690,7 @@ JNIEXPORT jint JNICALL RXTXPort(nativeavailable)( JNIEnv *env,
36903690
jobject jobj )
36913691
{
36923692
int fd = get_java_var( env, jobj,"fd","I" );
3693-
int result;
3693+
int result=-1;
36943694
/*
36953695
char message[80];
36963696
@@ -4265,6 +4265,13 @@ JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj )
42654265
do{
42664266
report_time_eventLoop( );
42674267
do {
4268+
if(RXTXPort(nativeavailable)( env, jobj )<0){
4269+
report("eventLoop: Hardware Missing\n");
4270+
finalize_threads( &eis );
4271+
finalize_event_info_struct( &eis );
4272+
LEAVE("eventLoop:error");
4273+
return;
4274+
}
42684275
/* nothing goes between this call and select */
42694276
if( eis.closing )
42704277
{
@@ -4304,6 +4311,7 @@ JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj )
43044311
}
43054312
i = 0;
43064313
#endif /* WIN32 */
4314+
43074315
} while ( eis.ret < 0 && errno == EINTR );
43084316
if( eis.ret >= 0 )
43094317
{

src/main/java/gnu/io/RXTXPort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class RXTXPort extends SerialPort
8686
static
8787
{
8888
try {
89-
z = new Zystem();
89+
z = new Zystem(Zystem.SILENT_MODE);
9090
} catch ( Exception e ) {}
9191

9292
if(debug )

test/src/test/ReadTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package test;
2+
import java.io.DataInputStream;
3+
import java.io.DataOutputStream;
4+
import java.io.IOException;
5+
import java.util.TooManyListenersException;
6+
7+
import gnu.io.NRSerialPort;
8+
import gnu.io.Zystem;
9+
public class ReadTest {
10+
public static void main(String [] args) {
11+
12+
String port = "";
13+
for(String s:NRSerialPort.getAvailableSerialPorts()){
14+
System.out.println("Availible port: "+s);
15+
port=s;
16+
}
17+
18+
int baudRate = 115200;
19+
NRSerialPort serial = new NRSerialPort(port, baudRate);
20+
serial.connect();
21+
DataInputStream ins = new DataInputStream(serial.getInputStream());
22+
try {
23+
serial.addEventListener(ev->{
24+
//while(ins.available()==0 && !Thread.interrupted());// wait for a byte
25+
try {
26+
while(ins.available()>0) {// read all bytes
27+
28+
char b = (char) ins.read();
29+
//outs.write((byte)b);
30+
System.out.print(b);
31+
32+
}
33+
} catch (IOException e) {
34+
// TODO Auto-generated catch block
35+
e.printStackTrace();
36+
}
37+
});
38+
} catch (TooManyListenersException e) {
39+
// TODO Auto-generated catch block
40+
e.printStackTrace();
41+
}
42+
//
43+
// DataOutputStream outs = new DataOutputStream(serial.getOutputStream());
44+
// try{
45+
// //while(ins.available()==0 && !Thread.interrupted());// wait for a byte
46+
// while(!Thread.interrupted()) {// read all bytes
47+
// if(ins.available()>0) {
48+
// char b = (char) ins.read();
49+
// //outs.write((byte)b);
50+
// System.out.print(b);
51+
// }
52+
// Thread.sleep(5);
53+
// }
54+
// }catch(Exception ex){
55+
// ex.printStackTrace();
56+
// }
57+
// serial.disconnect();
58+
}
59+
}

0 commit comments

Comments
 (0)