View | Details | Raw Unified | Return to bug 200179
Collapse All | Expand All

(-)Makefile (+2 lines)
Lines 13-18 Link Here
13
MAINTAINER=	mirror176@cox.net
13
MAINTAINER=	mirror176@cox.net
14
COMMENT=	Native interface to serial ports in Java
14
COMMENT=	Native interface to serial ports in Java
15
15
16
LIB_DEPENDS=    libpthread.so.1:${PORTSDIR}/emulators/linux_base-c6
17
16
USES=		gmake libtool zip
18
USES=		gmake libtool zip
17
USE_JAVA=	yes
19
USE_JAVA=	yes
18
JAVA_VERSION=	1.6+
20
JAVA_VERSION=	1.6+
(-)files/patch-src-ParallelImp.c (-5 / +3 lines)
Lines 1-8 Link Here
1
$FreeBSD: /tmp/pcvs/ports/comms/rxtx/files/patch-src-ParallelImp.c,v 1.1 2011-09-17 14:55:56 pawel Exp $
1
--- src/ParallelImp.c.orig	2008-11-27 20:01:48.000000000 +0000
2
2
+++ src/ParallelImp.c	2015-05-11 16:52:36.000000000 +0100
3
--- src/ParallelImp.c.orig	Fri Apr  9 23:31:09 2004
3
@@ -265,9 +265,6 @@
4
+++ src/ParallelImp.c	Fri Apr  9 23:35:01 2004
5
@@ -222,9 +222,6 @@
6
 #if defined(__linux__)
4
 #if defined(__linux__)
7
 	return( status & LP_BUSY ? JNI_TRUE : JNI_FALSE );
5
 	return( status & LP_BUSY ? JNI_TRUE : JNI_FALSE );
8
 #endif
6
 #endif
(-)files/patch-src-SerialImp.c (+6145 lines)
Line 0 Link Here
1
--- src/SerialImp.c.orig	2009-02-04 22:06:16.000000000 +0000
2
+++ src/SerialImp.c	2015-05-11 16:52:36.000000000 +0100
3
@@ -1,60 +1,79 @@
4
 /*-------------------------------------------------------------------------
5
-|   RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
6
-|   RXTX is a native interface to serial ports in java.
7
-|   Copyright 1997-2009 by Trent Jarvi tjarvi@qbang.org and others who
8
-|   actually wrote it.  See individual source files for more information.
9
+|	RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
10
+|	RXTX is a native interface to serial ports in java.
11
+|	Copyright 1997-2009 by Trent Jarvi tjarvi@qbang.org and others who
12
+|	actually wrote it.  See individual source files for more information.
13
 |
14
-|   A copy of the LGPL v 2.1 may be found at
15
-|   http://www.gnu.org/licenses/lgpl.txt on March 4th 2007.  A copy is
16
-|   here for your convenience.
17
+|	A copy of the LGPL v 2.1 may be found at
18
+|	http://www.gnu.org/licenses/lgpl.txt on March 4th 2007.  A copy is
19
+|	here for your convenience.
20
 |
21
-|   This library is free software; you can redistribute it and/or
22
-|   modify it under the terms of the GNU Lesser General Public
23
-|   License as published by the Free Software Foundation; either
24
-|   version 2.1 of the License, or (at your option) any later version.
25
+|	This library is free software; you can redistribute it and/or
26
+|	modify it under the terms of the GNU Lesser General Public
27
+|	License as published by the Free Software Foundation; either
28
+|	version 2.1 of the License, or (at your option) any later version.
29
 |
30
-|   This library is distributed in the hope that it will be useful,
31
-|   but WITHOUT ANY WARRANTY; without even the implied warranty of
32
-|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33
-|   Lesser General Public License for more details.
34
+|	This library is distributed in the hope that it will be useful,
35
+|	but WITHOUT ANY WARRANTY; without even the implied warranty of
36
+|	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
37
+|	Lesser General Public License for more details.
38
 |
39
-|   An executable that contains no derivative of any portion of RXTX, but
40
-|   is designed to work with RXTX by being dynamically linked with it,
41
-|   is considered a "work that uses the Library" subject to the terms and
42
-|   conditions of the GNU Lesser General Public License.
43
+|	An executable that contains no derivative of any portion of RXTX, but
44
+|	is designed to work with RXTX by being dynamically linked with it,
45
+|	is considered a "work that uses the Library" subject to the terms and
46
+|	conditions of the GNU Lesser General Public License.
47
 |
48
-|   The following has been added to the RXTX License to remove
49
-|   any confusion about linking to RXTX.   We want to allow in part what
50
-|   section 5, paragraph 2 of the LGPL does not permit in the special
51
-|   case of linking over a controlled interface.  The intent is to add a
52
-|   Java Specification Request or standards body defined interface in the
53
-|   future as another exception but one is not currently available.
54
+|	The following has been added to the RXTX License to remove
55
+|	any confusion about linking to RXTX.	We want to allow in part what
56
+|	section 5, paragraph 2 of the LGPL does not permit in the special
57
+|	case of linking over a controlled interface.  The intent is to add a
58
+|	Java Specification Request or standards body defined interface in the
59
+|	future as another exception but one is not currently available.
60
 |
61
-|   http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
62
+|	http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
63
 |
64
-|   As a special exception, the copyright holders of RXTX give you
65
-|   permission to link RXTX with independent modules that communicate with
66
-|   RXTX solely through the Sun Microsytems CommAPI interface version 2,
67
-|   regardless of the license terms of these independent modules, and to copy
68
-|   and distribute the resulting combined work under terms of your choice,
69
-|   provided that every copy of the combined work is accompanied by a complete
70
-|   copy of the source code of RXTX (the version of RXTX used to produce the
71
-|   combined work), being distributed under the terms of the GNU Lesser General
72
-|   Public License plus this exception.  An independent module is a
73
-|   module which is not derived from or based on RXTX.
74
+|	As a special exception, the copyright holders of RXTX give you
75
+|	permission to link RXTX with independent modules that communicate with
76
+|	RXTX solely through the Sun Microsytems CommAPI interface version 2,
77
+|	regardless of the license terms of these independent modules, and to copy
78
+|	and distribute the resulting combined work under terms of your choice,
79
+|	provided that every copy of the combined work is accompanied by a complete
80
+|	copy of the source code of RXTX (the version of RXTX used to produce the
81
+|	combined work), being distributed under the terms of the GNU Lesser General
82
+|	Public License plus this exception.  An independent module is a
83
+|	module which is not derived from or based on RXTX.
84
 |
85
-|   Note that people who make modified versions of RXTX are not obligated
86
-|   to grant this special exception for their modified versions; it is
87
-|   their choice whether to do so.  The GNU Lesser General Public License
88
-|   gives permission to release a modified version without this exception; this
89
-|   exception also makes it possible to release a modified version which
90
-|   carries forward this exception.
91
+|	Note that people who make modified versions of RXTX are not obligated
92
+|	to grant this special exception for their modified versions; it is
93
+|	their choice whether to do so.  The GNU Lesser General Public License
94
+|	gives permission to release a modified version without this exception; this
95
+|	exception also makes it possible to release a modified version which
96
+|	carries forward this exception.
97
 |
98
-|   You should have received a copy of the GNU Lesser General Public
99
-|   License along with this library; if not, write to the Free
100
-|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
101
-|   All trademarks belong to their respective owners.
102
+|	You should have received a copy of the GNU Lesser General Public
103
+|	License along with this library; if not, write to the Free
104
+|	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
105
+|	All trademarks belong to their respective owners.
106
 --------------------------------------------------------------------------*/
107
+/**
108
+ *	9th May 2015 - james.c.elstone (at) ntlworld.com:
109
+ *		
110
+ *		Added STDOUT debug stream, so can see when used with OpenJDK in
111
+ *		console terminal.  Useful for seeing events interleaved, with OS
112
+ *		activity.  Just put '#define DEBUG_STDOUT' just below...
113
+ *		
114
+ *		Altered behaviour of SIGABRT in RXTXPort(interruptEventLoop)
115
+ *		to prevent Core Dump from being performed on POSIX compliant OS.
116
+ * 
117
+ * 		Sorted out null termination on all debug strings!
118
+ * 		
119
+ *		Clearing of char array for sprintfs, driver enumerated multilpe
120
+ *		times, leaving the content behind in places.
121
+ *		
122
+ **/
123
+
124
+//#define DEBUG_STDOUT
125
+
126
 #if defined(__MWERKS__) /* dima */
127
 #include "RXTXPort.h" /* dima */
128
 #else  /* dima */
129
@@ -64,7 +83,7 @@
130
 #include "gnu_io_RXTXPort.h"
131
 #endif /* dima */
132
 #ifdef __LCC__ /* windows lcc compiler for fd_set. probably wrong */
133
-#   include<winsock.h>
134
+#	include<winsock.h>
135
 #endif /* __LCC__ */
136
 #include <time.h>
137
 #include <stdio.h>
138
@@ -91,23 +110,23 @@
139
 #ifdef HAVE_TERMIOS_H
140
 #	include <termios.h>
141
 #endif /* HAVE_TERMIOS_H */
142
-#   include <signal.h>
143
+#	include <signal.h>
144
 #ifdef HAVE_SIGNAL_H
145
-#   include <signal.h>
146
+#	include <signal.h>
147
 #endif /* HAVE_SIGNAL_H */
148
 #ifdef HAVE_SYS_SIGNAL_H
149
-#   include <sys/signal.h>
150
+#	include <sys/signal.h>
151
 #endif /* HAVE_SYS_SIGNAL_H */
152
 #include <sys/types.h>
153
 #ifdef HAVE_SYS_TIME_H
154
-#   include <sys/time.h>
155
+#	include <sys/time.h>
156
 #endif /* HAVE_SYS_TIME_H */
157
-#   include <fcntl.h>
158
+#	include <fcntl.h>
159
 #ifdef HAVE_SYS_FCNTL_H
160
-#   include <sys/fcntl.h>
161
+#	include <sys/fcntl.h>
162
 #endif /* HAVE_SYS_FCNTL_H */
163
 #ifdef HAVE_SYS_FILE_H
164
-#   include <sys/file.h>
165
+#	include <sys/file.h>
166
 #endif /* HAVE_SYS_FILE_H */
167
 #ifdef LFS  /* File Lock Server */
168
 #	include <sys/socket.h>
169
@@ -167,59 +186,59 @@
170
 /*----------------------------------------------------------
171
 cfmakeraw
172
 
173
-   accept:      termios to be set to raw
174
-   perform:     initializes the termios structure.
175
-   return:      int 0 on success
176
-   exceptions:  none
177
-   comments:    this is how linux cfmakeraw works.
178
-		termios(3) manpage
179
+	accept:		termios to be set to raw
180
+	perform:	initializes the termios structure.
181
+	return:		int 0 on success
182
+	exceptions: none
183
+	comments:	this is how linux cfmakeraw works.
184
+				termios(3) manpage
185
 ----------------------------------------------------------*/
186
 
187
 int cfmakeraw ( struct termios *term )
188
 {
189
-	ENTER( "cfmakeraw" );
190
+	report( "Entering - cfmakeraw\n" );
191
 	term->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
192
 	term->c_oflag &= ~OPOST;
193
 	term->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
194
 	term->c_cflag &= ~(CSIZE|PARENB);
195
 	term->c_cflag |= CS8;
196
-	LEAVE( "cfmakeraw" );
197
+	report( "Leaving - cfmakeraw\n" );
198
 	return( 0 );
199
 }
200
 #endif /* __sun__  || __hpux__ */
201
 
202
 #ifdef DEBUG_TIMING
203
-struct timeval snow, enow, seloop, eeloop;
204
-#define report_time_eventLoop( ) { \
205
-	if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \
206
+	struct timeval snow, enow, seloop, eeloop;
207
+	#define report_time_eventLoop( ) { \
208
+		if ( seloop.tv_sec == eeloop.tv_sec && seloop.tv_usec == eeloop.tv_usec ) \
209
+		{ \
210
+			gettimeofday(&eeloop, NULL); \
211
+			seloop.tv_sec = eeloop.tv_sec; \
212
+			seloop.tv_usec = eeloop.tv_usec; \
213
+			printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \
214
+		} \
215
+	}
216
+	#define report_time( ) \
217
 	{ \
218
-		gettimeofday(&eeloop, NULL); \
219
-		seloop.tv_sec = eeloop.tv_sec; \
220
-		seloop.tv_usec = eeloop.tv_usec; \
221
-		printf("%8i sec : %8i usec\n", eeloop.tv_sec - seloop.tv_sec, eeloop.tv_usec - seloop.tv_usec); \
222
-	} \
223
-}
224
-#define report_time( ) \
225
-{ \
226
-	struct timeval now; \
227
-	gettimeofday(&now, NULL); \
228
-	mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \
229
-}
230
-#define report_time_start( ) \
231
-{ \
232
-	gettimeofday(&snow, NULL); \
233
-	mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \
234
-}
235
-#define report_time_end( ) \
236
-{ \
237
-	gettimeofday(&enow, NULL); \
238
-	mexPrintf("%8i sec : %8i usec\n", enow.tv_sec - snow.tv_sec, enow.tv_sec - snow.tv_sec?snow.tv_usec-enow.tv_usec:enow.tv_usec - snow.tv_usec); \
239
-}
240
+		struct timeval now; \
241
+		gettimeofday(&now, NULL); \
242
+		mexPrintf("%8s : %5i : %8i sec : %8i usec\n", __TIME__, __LINE__, now.tv_sec, now.tv_usec); \
243
+	}
244
+	#define report_time_start( ) \
245
+	{ \
246
+		gettimeofday(&snow, NULL); \
247
+		mexPrintf("%8s : %5i : %8i sec : %8i usec", __TIME__, __LINE__, snow.tv_sec, snow.tv_usec); \
248
+	}
249
+	#define report_time_end( ) \
250
+	{ \
251
+		gettimeofday(&enow, NULL); \
252
+		mexPrintf("%8i sec : %8i usec\n", enow.tv_sec - snow.tv_sec, enow.tv_sec - snow.tv_sec?snow.tv_usec-enow.tv_usec:enow.tv_usec - snow.tv_usec); \
253
+	}
254
 #else
255
-#define report_time_eventLoop( ){};
256
-#define report_time( ) {}
257
-#define report_time_start( ) {}
258
-#define report_time_end( ) {}
259
+	#define report_time_eventLoop( ){};
260
+	#define report_time( ) {}
261
+	#define report_time_start( ) {}
262
+	#define report_time_end( ) {}
263
 #endif /* DEBUG_TIMING */
264
 
265
 
266
@@ -229,16 +248,16 @@
267
 /*----------------------------------------------------------
268
 RXTXPort.Initialize
269
 
270
-   accept:      The JNIEnv and jobj of the thread, the original eis.
271
-   perform:     fill in the needed variables with this threads values
272
-   return:      none
273
-   exceptions:  none
274
-   comments:    java variables (especially JNIEnv) should not be shared
275
-		between threads.  Right now we build a local struct with
276
-		the thread's info before using the variabls.  This is
277
-		especially true for send_event.
278
-
279
-		See also JNI_OnLoad() if the thread does not have the values
280
+	accept:		The JNIEnv and jobj of the thread, the original eis.
281
+	perform:	fill in the needed variables with this threads values
282
+	return:		none
283
+	exceptions: none
284
+	comments:	java variables (especially JNIEnv) should not be shared
285
+				between threads.  Right now we build a local struct with
286
+				the thread's info before using the variabls.  This is
287
+				especially true for send_event.
288
+				
289
+	See also JNI_OnLoad() if the thread does not have the values
290
 ----------------------------------------------------------*/
291
 struct event_info_struct build_threadsafe_eis(
292
 	JNIEnv *env,
293
@@ -264,13 +283,13 @@
294
 /*----------------------------------------------------------
295
 RXTXPort.Initialize
296
 
297
-   accept:      none
298
-   perform:     Initialize the native library
299
-   return:      none
300
-   exceptions:  none
301
-   comments:    Basically this just causes rxtx to ignore signals.  signal
302
-		handlers where tried but the VM (circa 1.1) did not like it.
303
-
304
+	accept:		none
305
+	perform:	Initialize the native library
306
+	return:		none
307
+	exceptions:	none
308
+	comments:	Basically this just causes rxtx to ignore signals.  signal
309
+				handlers where tried but the VM (circa 1.1) did not like it.
310
+				
311
 		It also allows for some sanity checks on linux boxes if DEBUG
312
 		is enabled.
313
 ----------------------------------------------------------*/
314
@@ -284,9 +303,9 @@
315
 	char message[80];
316
 #endif /* DEBUG && __linux__ */
317
 	/* This bit of code checks to see if there is a signal handler installed
318
-	   for SIGIO, and installs SIG_IGN if there is not.  This is necessary
319
-	   for the native threads jdk, but we don't want to do it with green
320
-	   threads, because it slows things down.  Go figure. */
321
+		for SIGIO, and installs SIG_IGN if there is not.  This is necessary
322
+		for the native threads jdk, but we don't want to do it with green
323
+		threads, because it slows things down.  Go figure. */
324
 
325
 	/* POSIX signal handling functions */
326
 #if !defined(WIN32)
327
@@ -306,7 +325,7 @@
328
 		sigaction(SIGIO, &new_action, NULL);
329
 	}
330
 #endif /* !WIN32 */
331
-	ENTER( "RXTXPort:Initialize" );
332
+	report( "Entering - RXTXPort:Initialize\n" );
333
 #ifdef PRERELEASE
334
 	/*  this is just for avoiding confusion while testing new libraries */
335
 #ifdef DEBUG_MW
336
@@ -322,32 +341,33 @@
337
 	/* Lets let people who upgraded kernels know they may have problems */
338
 	if (uname (&name) == -1)
339
 	{
340
-		report( "RXTX WARNING:  cannot get system name\n" );
341
-		LEAVE( "RXTXPort:Initialize" );
342
+		report( "RXTX WARNING:	cannot get system name\n" );
343
+		report( "Leaving - RXTXPort:Initialize\n" );
344
 		return;
345
 	}
346
 	if(strcmp(name.release,UTS_RELEASE)!=0)
347
 	{
348
-		sprintf( message, LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
349
+		memset(&message[0], 0, sizeof(message));
350
+		sprintf( message, "%s%s%s\n", LINUX_KERNEL_VERSION_ERROR, UTS_RELEASE,
351
 			name.release );
352
 		report( message );
353
 		getchar();
354
 	}
355
-	LEAVE( "RXTXPort:Initialize" );
356
+	report( "Leaving - RXTXPort:Initialize\n" );
357
 #endif /* DEBUG && __linux__ */
358
 }
359
 
360
 /*----------------------------------------------------------
361
 RXTXPort.find_preopened_ports
362
-   accept:      The device to find if preopened.  ie "/dev/ttyS0"
363
-   perform:     find the filedescriptor if preopened
364
-   return:      fd
365
-   exceptions:  none
366
-   comments:    see
367
-			RXTXPort.nativeStaticSetDSR
368
-			RXTXPort.nativeStaticSetDTR
369
-			RXTXPort.nativeStaticSetRTS
370
-			RXTXPort.nativeStaticSetSerialPortParams
371
+	accept:		The device to find if preopened.  ie "/dev/ttyS0"
372
+	perform:	find the filedescriptor if preopened
373
+	return:		fd
374
+	exceptions:	none
375
+	comments:	see
376
+				RXTXPort.nativeStaticSetDSR
377
+				RXTXPort.nativeStaticSetDTR
378
+				RXTXPort.nativeStaticSetRTS
379
+				RXTXPort.nativeStaticSetSerialPortParams
380
 		This is used so people can setDTR low before calling the
381
 		Java open().
382
 ----------------------------------------------------------*/
383
@@ -401,13 +421,13 @@
384
 /*----------------------------------------------------------
385
 configure_port
386
 
387
-   accept:      env, file descriptor
388
-   perform:     set the termios struct to sane settings and
389
-   return:      0 on success
390
-   exceptions:  IOExcepiton
391
-   comments:    Very often people complain about not being able to get past
392
-                this function and it turns out to be permissions on the
393
-                device file or bios has the device disabled.
394
+	accept:		Env, file descriptor
395
+	perform:	set the termios struct to sane settings and
396
+	return:		0 on success
397
+	exceptions:	IOExcepiton
398
+	comments:	Very often people complain about not being able to get past
399
+				this function and it turns out to be permissions on the
400
+				device file or bios has the device disabled.
401
 ----------------------------------------------------------*/
402
 int configure_port( int fd )
403
 {
404
@@ -446,31 +466,31 @@
405
 /*----------------------------------------------------------
406
 get_java_baudrate
407
 
408
-   accept:      the native speed setting
409
-   perform:     translate the native speed to a Java speed
410
-   return:      the Java speed
411
-   exceptions:  none
412
-   comments:    This is used by open() (indirectly) and
413
-		nativeStaticGetBaudRate()
414
+	accept:		the native speed setting
415
+	perform:	translate the native speed to a Java speed
416
+	return:		the Java speed
417
+	exceptions:	none
418
+	comments:	This is used by open() (indirectly) and
419
+				nativeStaticGetBaudRate()
420
 ----------------------------------------------------------*/
421
 int get_java_baudrate( int native_speed )
422
 {
423
 	switch( native_speed )
424
 	{
425
-		case B0:     return 0;
426
-		case B50:    return 50;
427
-		case B75:    return 75;
428
-		case B110:   return 110;
429
-		case B134:   return 134;
430
-		case B150:   return 150;
431
-		case B200:   return 200;
432
-		case B300:   return 300;
433
-		case B600:   return 600;
434
-		case B1200:  return 1200;
435
-		case B1800:  return 1800;
436
-		case B2400:  return 2400;
437
-		case B4800:  return 4800;
438
-		case B9600:  return 9600;
439
+		case B0:	return 0;
440
+		case B50:	return 50;
441
+		case B75:	return 75;
442
+		case B110:	return 110;
443
+		case B134:	return 134;
444
+		case B150:	return 150;
445
+		case B200:	return 200;
446
+		case B300:	return 300;
447
+		case B600:	return 600;
448
+		case B1200:	return 1200;
449
+		case B1800:	return 1800;
450
+		case B2400:	return 2400;
451
+		case B4800:	return 4800;
452
+		case B9600:	return 9600;
453
 #ifdef B14400
454
 		case B14400: return 14400;
455
 #endif /* B14400 */
456
@@ -536,13 +556,13 @@
457
 /*----------------------------------------------------------
458
 set_java_vars
459
 
460
-   accept:      fd of the preopened device
461
-   perform:     Now that the object is instatiated, set the Java variables
462
-		to the preopened states.
463
-   return:      none
464
-   exceptions:  none
465
-   comments:    preopened refers to the fact that the serial port has
466
-		been configured before the Java open() has been called.
467
+	accept:		fd of the preopened device
468
+	perform:	Now that the object is instatiated, set the Java variables
469
+				to the preopened states.
470
+	return:		none
471
+	exceptions:	none
472
+	comments:	preopened refers to the fact that the serial port has
473
+				been configured before the Java open() has been called.
474
 ----------------------------------------------------------*/
475
 
476
 void set_java_vars( JNIEnv *env, jobject jobj, int fd )
477
@@ -570,10 +590,10 @@
478
 
479
 
480
 	switch( ttyset.c_cflag&CSIZE ) {
481
-		case CS5:  databits = JDATABITS_5; break;
482
-		case CS6:  databits = JDATABITS_6; break;
483
-		case CS7:  databits = JDATABITS_7; break;
484
-		case CS8:  databits = JDATABITS_8; break;
485
+		case CS5:	databits = JDATABITS_5; break;
486
+		case CS6:	databits = JDATABITS_6; break;
487
+		case CS7:	databits = JDATABITS_7; break;
488
+		case CS8:	databits = JDATABITS_8; break;
489
 	}
490
 #ifdef CMSPAR
491
 	switch( ttyset.c_cflag&(PARENB|PARODD|CMSPAR ) ) {
492
@@ -588,9 +608,9 @@
493
 		case PARENB | CMSPAR: jparity = JPARITY_SPACE; break;
494
 #endif /* CMSPAR */
495
 	}
496
-        switch( ttyset.c_cflag&(CSTOPB) ) {
497
-                case 0: stop_bits = STOPBITS_1; break;
498
-                case CSTOPB:
499
+	 switch( ttyset.c_cflag&(CSTOPB) ) {
500
+			case 0: stop_bits = STOPBITS_1; break;
501
+			case CSTOPB:
502
 			if ( (ttyset.c_cflag & CSIZE) ==  CS5 ) {
503
 				stop_bits = STOPBITS_1_5;
504
 			}
505
@@ -598,7 +618,7 @@
506
 				stop_bits = STOPBITS_2;
507
 			}
508
 			break;
509
-        }
510
+	 }
511
 /*
512
 dima writes:
513
 
514
@@ -616,9 +636,9 @@
515
 
516
 */
517
 #if defined(CBAUD)/* dima */
518
-    	baudrate = ttyset.c_cflag&CBAUD;
519
+		baudrate = ttyset.c_cflag&CBAUD;
520
 #else
521
-    	baudrate = cfgetispeed(&ttyset);
522
+		baudrate = cfgetispeed(&ttyset);
523
 #endif
524
 	(*env)->SetIntField(env, jobj, jfspeed,
525
 		( jint ) get_java_baudrate(baudrate) );
526
@@ -629,14 +649,14 @@
527
 /*----------------------------------------------------------
528
 RXTXPort.open
529
 
530
-   accept:      The device to open.  ie "/dev/ttyS0"
531
-   perform:     open the device, set the termios struct to sane settings and
532
-                return the filedescriptor
533
-   return:      fd
534
-   exceptions:  IOExcepiton
535
-   comments:    Very often people complain about not being able to get past
536
-                this function and it turns out to be permissions on the
537
-                device file or bios has the device disabled.
538
+	accept:		The device to open.  ie "/dev/ttyS0"
539
+	perform:	open the device, set the termios struct to sane settings and
540
+				return the filedescriptor
541
+	return:		fd
542
+	exceptions:	IOExcepiton
543
+	comments:	Very often people complain about not being able to get past
544
+				this function and it turns out to be permissions on the
545
+				device file or bios has the device disabled.
546
 ----------------------------------------------------------*/
547
 JNIEXPORT jint JNICALL RXTXPort(open)(
548
 	JNIEnv *env,
549
@@ -676,9 +696,10 @@
550
 			system_does_not_lock	Win32
551
 	*/
552
 
553
-	ENTER( "RXTXPort:open" );
554
+	report( "Entering - RXTXPort:open\n" );
555
 	if ( LOCK( filename, pid ) )
556
 	{
557
+		memset(&message[0], 0, sizeof(message));
558
 		sprintf( message, "open: locking has failed for %s\n",
559
 			filename );
560
 		report( message );
561
@@ -686,6 +707,7 @@
562
 	}
563
 	else
564
 	{
565
+		memset(&message[0], 0, sizeof(message));
566
 		sprintf( message, "open: locking worked for %s\n", filename );
567
 		report( message );
568
 	}
569
@@ -703,36 +725,36 @@
570
 	}  while (fd < 0 && errno==EINTR);
571
 
572
 #ifdef OPEN_EXCL
573
-       /*
574
-       Note that open() follows POSIX semantics: multiple open() calls to
575
-       the same file will succeed unless the TIOCEXCL ioctl is issued.
576
-       This will prevent additional opens except by root-owned processes.
577
-       See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
578
-       */
579
-
580
-       if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))
581
-       {
582
-               sprintf( message, "open: exclusive access denied for %s\n",
583
-                       filename );
584
-               report( message );
585
-               report_error( message );
586
-
587
-               close(fd);
588
-               goto fail;
589
-       }
590
+	/*
591
+	Note that open() follows POSIX semantics: multiple open() calls to
592
+	the same file will succeed unless the TIOCEXCL ioctl is issued.
593
+	This will prevent additional opens except by root-owned processes.
594
+	See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
595
+	*/
596
+
597
+	if (fd >= 0 && (ioctl(fd, TIOCEXCL) == -1))
598
+	{
599
+			memset(&message[0], 0, sizeof(message));
600
+			sprintf( message, "open: exclusive access denied for %s\n", filename );
601
+			report( message );
602
+			report_error( message );
603
+			close(fd);
604
+			goto fail;
605
+	}
606
 #endif /* OPEN_EXCL */
607
 
608
 	if( configure_port( fd ) ) goto fail;
609
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
610
+	memset(&message[0], 0, sizeof(message));
611
 	sprintf( message, "open: fd returned is %i\n", fd );
612
 	report( message );
613
-	LEAVE( "RXTXPort:open" );
614
+	report( "Leaving - RXTXPort:open\n" );
615
 	report_time_end( );
616
 	return (jint)fd;
617
 
618
 fail:
619
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
620
-	LEAVE( "RXTXPort:open" );
621
+	report( "Leaving - RXTXPort:open\n" );
622
 	throw_java_exception( env, PORT_IN_USE_EXCEPTION, "open",
623
 		strerror( errno ) );
624
 	return -1;
625
@@ -741,10 +763,10 @@
626
 /*----------------------------------------------------------
627
 RXTXPort.nativeClose
628
 
629
-   accept:      none
630
-   perform:     get the fd from the java end and close it
631
-   return:      none
632
-   exceptions:  none
633
+	accept:		none
634
+	perform:	get the fd from the java end and close it
635
+	return:		none
636
+	exceptions:	none
637
 ----------------------------------------------------------*/
638
 JNIEXPORT void JNICALL RXTXPort(nativeClose)( JNIEnv *env,
639
 	jobject jobj,jstring jstr )
640
@@ -764,7 +786,7 @@
641
 		(*env)->ExceptionDescribe( env );
642
 		(*env)->ExceptionClear( env );
643
 		(*env)->DeleteLocalRef( env, jclazz );
644
-		report("nativeClose: Close not detecting thread pid");
645
+		report("nativeClose: Close not detecting thread pid\n");
646
 		return;
647
 	}
648
 	report("<nativeClose: pid\n");
649
@@ -777,14 +799,14 @@
650
 			system_does_not_unlock	Win32
651
 	*/
652
 
653
-	ENTER( "RXTXPort:nativeClose" );
654
+	report( "Entering - RXTXPort:nativeClose\n" );
655
 	if (fd > 0)
656
 	{
657
 		report("nativeClose: discarding remaining data (tcflush)\n");
658
 		/* discard any incoming+outgoing data not yet read/sent */
659
 		tcflush(fd, TCIOFLUSH);
660
  		do {
661
-			report("nativeClose:  calling close\n");
662
+			report("nativeClose:	calling close\n");
663
 			result=CLOSE (fd);
664
 		}  while ( result < 0 && errno == EINTR );
665
 		UNLOCK( filename, pid );
666
@@ -793,7 +815,7 @@
667
 	(*env)->DeleteLocalRef( env, jclazz );
668
 	report("nativeClose: release filename\n");
669
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
670
-	LEAVE( "RXTXPort:nativeClose" );
671
+	report( "Leaving - RXTXPort:nativeClose\n" );
672
 	report_time_end( );
673
 	return;
674
 }
675
@@ -801,15 +823,15 @@
676
 /*----------------------------------------------------------
677
  RXTXPort.set_port_params
678
 
679
-   accept:     env, fd, speed, data bits, stop bits, parity
680
-   perform:    set the serial port parameters
681
-   return:     1 on error
682
-   exceptions: UnsupportedCommOperationException
683
-   comments:   There is a static method and an instance method that use this
684
-		function.  The static method gets a fd first.  The instance
685
-		method can get the fd from the object.
686
+	accept:		env, fd, speed, data bits, stop bits, parity
687
+	perform:	set the serial port parameters
688
+	return:		1 on error
689
+	exceptions: UnsupportedCommOperationException
690
+	comments:	There is a static method and an instance method that use this
691
+				function.  The static method gets a fd first.  The instance
692
+				method can get the fd from the object.
693
 
694
-		see:  nativeSetSerialPortParams & nativeStaticSerialPortParams
695
+	see:		nativeSetSerialPortParams & nativeStaticSerialPortParams
696
 ----------------------------------------------------------*/
697
 int set_port_params( JNIEnv *env, int fd, int cspeed, int dataBits,
698
 			int stopBits, int parity )
699
@@ -864,36 +886,36 @@
700
 		ioctl( fd, TIOCMSET, &result );
701
 	}
702
 	/*
703
-	   B38400 is a special case in Linux for custom baud rates.
704
+		B38400 is a special case in Linux for custom baud rates.
705
 
706
-	   We just treat this as a custom speed for now.  If you take this ifdef
707
-	   out and select baud rates 38400 then 28800 then 38400, you will get
708
-	   a final baud rate of 28800 because you did not update the divisor.
709
+		We just treat this as a custom speed for now.  If you take this ifdef
710
+		out and select baud rates 38400 then 28800 then 38400, you will get
711
+		a final baud rate of 28800 because you did not update the divisor.
712
 
713
-	   See the next ifdef below for the divisor.
714
+		See the next ifdef below for the divisor.
715
 	*/
716
 #if defined(TIOCGSERIAL)
717
 	if ( cspeed == B38400 )
718
 		cspeed = 38400;
719
 #endif /* TIOCGSERIAL */
720
-	if(     cfsetispeed( &ttyset, cspeed ) < 0 ||
721
+	if(	cfsetispeed( &ttyset, cspeed ) < 0 ||
722
 		cfsetospeed( &ttyset, cspeed ) < 0 )
723
 	{
724
 		/*
725
-		    Some people need to set the baud rate to ones not defined
726
-		    in termios.h
727
+			Some people need to set the baud rate to ones not defined
728
+			in termios.h
729
 
730
-		    This includes some baud rates which are supported by CommAPI
731
-		    in Unix ( 14400, 28800, 128000, 256000 )
732
+			This includes some baud rates which are supported by CommAPI
733
+			in Unix ( 14400, 28800, 128000, 256000 )
734
 
735
-		    If the above fails, we assume this is not a defined
736
-		    baud rate on Unix.  With Win32, It is assumed the kernel
737
-		    will do this for us.
738
+			If the above fails, we assume this is not a defined
739
+			baud rate on Unix.  With Win32, It is assumed the kernel
740
+			will do this for us.
741
 
742
-		    The baud_base and desired speed are used to
743
-		    calculate a custom divisor.
744
+			The baud_base and desired speed are used to
745
+			calculate a custom divisor.
746
 
747
-		    On linux the setserial man page covers this.
748
+			On linux the setserial man page covers this.
749
 		*/
750
 
751
 #if defined(TIOCGSERIAL)
752
@@ -905,7 +927,7 @@
753
 		sstruct.custom_divisor = ( sstruct.baud_base/cspeed );
754
 		cspeed = B38400;
755
 #endif /* TIOCGSERIAL */
756
-		if(     cfsetispeed( &ttyset, cspeed ) < 0 ||
757
+		if(	cfsetispeed( &ttyset, cspeed ) < 0 ||
758
 			cfsetospeed( &ttyset, cspeed ) < 0 )
759
 		{
760
 			/* OK, we tried everything */
761
@@ -933,10 +955,10 @@
762
 /*----------------------------------------------------------
763
  RXTXPort.nativeSetSerialPortParams
764
 
765
-   accept:     speed, data bits, stop bits, parity
766
-   perform:    set the serial port parameters
767
-   return:     jboolean 1 on error
768
-   exceptions: UnsupportedCommOperationException
769
+	accept:		speed, data bits, stop bits, parity
770
+	perform:	set the serial port parameters
771
+	return:		jboolean 1 on error
772
+	exceptions: UnsupportedCommOperationException
773
 ----------------------------------------------------------*/
774
 JNIEXPORT jboolean JNICALL RXTXPort(nativeSetSerialPortParams)(
775
 	JNIEnv *env, jobject jobj, jint speed, jint dataBits, jint stopBits,
776
@@ -945,15 +967,15 @@
777
 	int fd = get_java_var( env, jobj,"fd","I" );
778
 	int cspeed = translate_speed( env, speed );
779
 
780
-	ENTER( "RXTXPort:nativeSetSerialPortParams" );
781
+	report( "Entering - RXTXPort:nativeSetSerialPortParams\n" );
782
 	report_time_start( );
783
 
784
 	if (cspeed < 0 )
785
 	{
786
 		report(" invalid cspeed\n");
787
 /*
788
-    For some reason the native exceptions are not being caught.  Moving this
789
-    to the Java side fixed the issue.  taj.
790
+	For some reason the native exceptions are not being caught.  Moving this
791
+	to the Java side fixed the issue.  taj.
792
 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
793
 			"", "BaudRate could not be set to the specified value" );
794
 */
795
@@ -964,17 +986,17 @@
796
 	if( set_port_params( env, fd, cspeed, dataBits, stopBits, parity ) )
797
 	{
798
 		report("set_port_params failed\n");
799
-		LEAVE( "RXTXPort:nativeSetSerialPortParams" );
800
+		report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" );
801
 /*
802
-    For some reason the native exceptions are not being caught.  Moving this
803
-    to the Java side fixed the issue.  taj.
804
+	For some reason the native exceptions are not being caught.  Moving this
805
+	to the Java side fixed the issue.  taj.
806
 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
807
 			"nativeSetSerialPortParams", strerror( errno ) );
808
 */
809
 		return(1);
810
 	}
811
 
812
-	LEAVE( "RXTXPort:nativeSetSerialPortParams" );
813
+	report( "Leaving - RXTXPort:nativeSetSerialPortParams\n" );
814
 	report_time_end( );
815
 	return(0);
816
 }
817
@@ -982,17 +1004,17 @@
818
 /*----------------------------------------------------------
819
  translate_speed
820
 
821
-   accept:     speed in bits-per-second
822
-   perform:    convert bits-per-second to a speed_t constant
823
-   return:     speed_t constant
824
-   exceptions: returns -1 and the calling method throws the exception so
825
-	       it may be caught in java.
826
-   comments:   Only the lowest level code should know about
827
-               the magic constants.
828
+	accept:		speed in bits-per-second
829
+	perform:	convert bits-per-second to a speed_t constant
830
+	return:		speed_t constant
831
+	exceptions: returns -1 and the calling method throws the exception so
832
+				it may be caught in java.
833
+	comments:	Only the lowest level code should know about
834
+				the magic constants.
835
 ----------------------------------------------------------*/
836
 int translate_speed( JNIEnv *env, jint speed )
837
 {
838
-	LEAVE( "RXTXPort:translate_speed" );
839
+	report( "Leaving - RXTXPort:translate_speed\n" );
840
 	switch( speed ) {
841
 		case 0:		return B0;
842
 		case 50:	return B50;
843
@@ -1072,7 +1094,7 @@
844
 	if( speed >= 0 ) return speed;
845
 	else
846
 	{
847
-		LEAVE( "RXTXPort:translate_speed: Error condition" );
848
+		report( "Leaving - RXTXPort:translate_speed: Error condition\n" );
849
 		return -1;
850
 	}
851
 }
852
@@ -1080,16 +1102,16 @@
853
 /*----------------------------------------------------------
854
  translate_data_bits
855
 
856
-   accept:     gnu.io.SerialPort.DATABITS_* constant
857
-   perform:    set proper termios c_cflag bits
858
-   return:     1 on error
859
-   exceptions: UnsupportedCommOperationException
860
+	accept:		gnu.io.SerialPort.DATABITS_* constant
861
+	perform:	set proper termios c_cflag bits
862
+	return:		1 on error
863
+	exceptions: UnsupportedCommOperationException
864
 ----------------------------------------------------------*/
865
 int translate_data_bits( JNIEnv *env, tcflag_t *cflag, jint dataBits )
866
 {
867
 	int temp = (*cflag) & ~CSIZE;
868
 
869
-	ENTER( "translate_date_bits" );
870
+	report( "Entering - translate_date_bits\n" );
871
 	switch( dataBits ) {
872
 		case JDATABITS_5:
873
 			(*cflag) = temp | CS5;
874
@@ -1105,10 +1127,10 @@
875
 			return 0;
876
 	}
877
 
878
-	LEAVE( "RXTXPort:translate_date_bits" );
879
+	report( "Leaving - RXTXPort:translate_date_bits\n" );
880
 /*
881
-    For some reason the native exceptions are not being caught.  Moving this
882
-    to the Java side fixed the issue.  taj.
883
+	For some reason the native exceptions are not being caught.  Moving this
884
+	to the Java side fixed the issue.  taj.
885
 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
886
 		"", "databit value not supported" );
887
 */
888
@@ -1118,20 +1140,20 @@
889
 /*----------------------------------------------------------
890
  translate_stop_bits
891
 
892
-   accept:     gnu.io.SerialPort.STOPBITS_* constant
893
-   perform:    set proper termios c_cflag bits
894
-   return:     1 on error
895
-   exceptions: UnsupportedCommOperationException
896
-   comments:   If you specify 5 data bits and 2 stop bits, the port will
897
-               allegedly use 1.5 stop bits.  Does anyone care?
898
+	accept:		gnu.io.SerialPort.STOPBITS_* constant
899
+	perform:	set proper termios c_cflag bits
900
+	return:		1 on error
901
+	exceptions: UnsupportedCommOperationException
902
+	comments:	If you specify 5 data bits and 2 stop bits, the port will
903
+				allegedly use 1.5 stop bits.  Does anyone care?
904
 ----------------------------------------------------------*/
905
 int translate_stop_bits( JNIEnv *env, tcflag_t *cflag, jint stopBits )
906
 {
907
-	ENTER( "translate_stop_bits" );
908
+	report( "Entering - translate_stop_bits\n" );
909
 	switch( stopBits ) {
910
 		case STOPBITS_1:
911
 			(*cflag) &= ~CSTOPB;
912
-			LEAVE( "RXTXPort:translate_stop_bits" );
913
+			report( "Leaving - RXTXPort:translate_stop_bits\n" );
914
 			return 0;
915
 		/*  ok.. lets try putting it in and see if anyone notices */
916
 		case STOPBITS_1_5:
917
@@ -1141,14 +1163,14 @@
918
 			return 0;
919
 		case STOPBITS_2:
920
 			(*cflag) |= CSTOPB;
921
-			LEAVE( "RXTXPort:translate_stop_bits" );
922
+			report( "Leaving - RXTXPort:translate_stop_bits\n" );
923
 			return 0;
924
 	}
925
 
926
-	LEAVE( "RXTXPort:translate_stop_bits" );
927
+	report( "Leaving - RXTXPort:translate_stop_bits\n" );
928
 /*
929
-    For some reason the native exceptions are not being caught.  Moving this
930
-    to the Java side fixed the issue.  taj.
931
+	For some reason the native exceptions are not being caught.  Moving this
932
+	to the Java side fixed the issue.  taj.
933
 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
934
 		"", "stopbit value not supported" );
935
 */
936
@@ -1181,7 +1203,7 @@
937
 
938
 	if( tcgetattr( fd, &ttyset ) < 0 )
939
 	{
940
-		report("nativeGetParity:  tcgetattr failed\n");
941
+		report("nativeGetParity:	tcgetattr failed\n");
942
 		return( -1 );
943
 	}
944
 #ifdef  CMSPAR
945
@@ -1215,49 +1237,49 @@
946
 /*----------------------------------------------------------
947
  translate_parity
948
 
949
-   accept:     javax.comm.SerialPort.PARITY_* constant
950
-   perform:    set proper termios c_cflag bits
951
-   return:     1 on error
952
-   exceptions: UnsupportedCommOperationException
953
-   comments:   The CMSPAR bit should be used for 'mark' and 'space' parity,
954
-               but it's not in glibc's includes.  Oh well, rarely used anyway.
955
+	accept:		javax.comm.SerialPort.PARITY_* constant
956
+	perform:	set proper termios c_cflag bits
957
+	return:		1 on error
958
+	exceptions:	UnsupportedCommOperationException
959
+	comments:	The CMSPAR bit should be used for 'mark' and 'space' parity,
960
+				but it's not in glibc's includes.  Oh well, rarely used anyway.
961
 ----------------------------------------------------------*/
962
 int translate_parity( JNIEnv *env, tcflag_t *cflag, jint parity )
963
 {
964
-	ENTER( "translate_parity" );
965
+	report( "Entering - translate_parity\n" );
966
 #ifdef CMSPAR
967
 	(*cflag) &= ~(PARENB | PARODD | CMSPAR );
968
 #endif /* CMSPAR */
969
 	switch( parity ) {
970
 		case JPARITY_NONE:
971
-			LEAVE( "translate_parity" );
972
+			report( "Leaving - translate_parity\n" );
973
 			return 0;
974
 		case JPARITY_EVEN:
975
 			(*cflag) |= PARENB;
976
-			LEAVE( "translate_parity" );
977
+			report( "Leaving - translate_parity\n" );
978
 			return 0;
979
 		case JPARITY_ODD:
980
 			(*cflag) |= PARENB | PARODD;
981
-			LEAVE( "translate_parity" );
982
+			report( "Leaving - translate_parity\n" );
983
 			return 0;
984
 #ifdef CMSPAR
985
 		case JPARITY_MARK:
986
 			(*cflag) |= PARENB | PARODD | CMSPAR;
987
-			LEAVE( "translate_parity" );
988
+			report( "Leaving - translate_parity\n" );
989
 			return 0;
990
 		case JPARITY_SPACE:
991
 			(*cflag) |= PARENB | CMSPAR;
992
-			LEAVE( "translate_parity" );
993
+			report( "Leaving - translate_parity\n" );
994
 			return 0;
995
 #endif /* CMSPAR */
996
 		default:
997
 			printf("Parity missed %i\n", (int) parity );
998
 	}
999
 
1000
-	LEAVE( "translate_parity" );
1001
+	report( "Leaving - translate_parity\n" );
1002
 /*
1003
-    For some reason the native exceptions are not being caught.  Moving this
1004
-    to the Java side fixed the issue.  taj.
1005
+	For some reason the native exceptions are not being caught.  Moving this
1006
+	to the Java side fixed the issue.  taj.
1007
 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
1008
 		"", "parity value not supported" );
1009
 */
1010
@@ -1267,48 +1289,63 @@
1011
 /*----------------------------------------------------------
1012
 drain_loop()
1013
 
1014
-   accept:
1015
-   perform:	call tcdrain() and report an event when it succeds
1016
-   return:      none
1017
-   exceptions:
1018
-   comments:
1019
+	accept:
1020
+	perform:	call tcdrain() and report an event when it succeds
1021
+	return:		none
1022
+	exceptions:
1023
+	comments:
1024
 ----------------------------------------------------------*/
1025
 void *drain_loop( void *arg )
1026
 {
1027
+	report("Entering - drain_loop\n");	
1028
 	struct event_info_struct *eis = ( struct event_info_struct * ) arg;
1029
 	/* char msg[80]; */
1030
 	int i;
1031
+	
1032
+	report_verbose("drain_loop: pthread detaching\n");
1033
 	pthread_detach( pthread_self() );
1034
-
1035
+	
1036
+	report_verbose("drain_loop: begining for loop\n");
1037
 	for(i=0;;i++)
1038
 	{
1039
-		report_verbose("drain_loop:  looping\n");
1040
+		report_verbose("drain_loop: looping\n");
1041
 		if( eis->eventloop_interrupted )
1042
 		{
1043
+			report_verbose("drain_loop: EventLoop Interrupted\n");
1044
 			goto end;
1045
 		}
1046
-#if defined(__sun__)
1047
-	/* FIXME: No time to test on all OS's for production */
1048
-		if (usleep(5000)) {
1049
-			report("drain_loop:  received EINTR");
1050
-		}
1051
-#else
1052
-		if (usleep(1000000)) {
1053
-			report("drain_loop:  received EINTR");
1054
-		}
1055
-#endif /* __sun__ */
1056
+		
1057
+		#if defined(__sun__)
1058
+			/* FIXME: No time to test on all OS's for production */
1059
+			report_verbose("drain_loop: SUN: Sleeping now\n");
1060
+			if (usleep(5000)) {
1061
+				report("***drain_loop: received EINTR\n");
1062
+			}
1063
+		#else
1064
+			report_verbose("drain_loop: Sleeping now\n");
1065
+			if (usleep(1000000)) {
1066
+				report("***drain_loop: received EINTR\n");
1067
+			}
1068
+		#endif /* __sun__ */
1069
+		
1070
+		report_verbose("***drain_loop: Out of sleep loop\n");
1071
 		/*
1072
 		system_wait();
1073
 		*/
1074
+		
1075
 		if( eis->eventloop_interrupted )
1076
 		{
1077
+			report_verbose("*** drain_loop: Interupted\n");
1078
+			eis->closing = 1;
1079
 			goto end;
1080
 		}
1081
+		
1082
 		if( tcdrain( eis->fd ) == 0 )
1083
 		{
1084
 			if( eis && eis->writing )
1085
 			{
1086
 				/*
1087
+				memset(&msg[0], 0, sizeof(msg));
1088
 				sprintf(msg, "drain_loop: setting OUTPUT_BUFFER_EMPTY\n" );
1089
 				report( msg );
1090
 				*/
1091
@@ -1321,17 +1358,17 @@
1092
 				{
1093
 					goto end;
1094
 				}
1095
-				report_verbose("drain_loop:  writing not set\n");
1096
+				report_verbose("drain_loop: writing not set\n");
1097
 			}
1098
 		}
1099
 		else if (errno != EINTR)
1100
 		{
1101
-			report("drain_loop:  tcdrain bad fd\n");
1102
+			report("drain_loop:	tcdrain bad fd\n");
1103
 			goto end;
1104
 		}
1105
 		else
1106
 		{
1107
-			report("drain_loop:  received EINTR in tcdrain\n");
1108
+			report("drain_loop:	received EINTR in tcdrain\n");
1109
 		}
1110
 	}
1111
 end:
1112
@@ -1344,12 +1381,12 @@
1113
 /*----------------------------------------------------------
1114
 finalize_threads( )
1115
 
1116
-   accept:      event_info_struct used to access java and communicate with
1117
-	        eventLoop().
1118
-   perform:     see comments
1119
-   return:      none
1120
-   exceptions:  none
1121
-   comments:
1122
+	accept:		event_info_struct used to access java and communicate with
1123
+				eventLoop().
1124
+	perform:	see comments
1125
+	return:		none
1126
+	exceptions:	none
1127
+	comments:
1128
 	The is the pthread spawned on systems that can't access the
1129
 	LSR (Line Status Register).  Without access to the LSR rxtx
1130
 	cannot detect when the output buffer is empty in the Monitor
1131
@@ -1361,14 +1398,14 @@
1132
 ----------------------------------------------------------*/
1133
 void finalize_threads( struct event_info_struct *eis )
1134
 {
1135
-#if     !defined(TIOCSERGETLSR) && !defined( WIN32 )
1136
+#if	!defined(TIOCSERGETLSR) && !defined( WIN32 )
1137
 	/* used to shut down any remaining write threads */
1138
 
1139
 	eis->output_buffer_empty_flag = 0;
1140
-	ENTER("finalize_threads\n");
1141
+	report("Entering - finalize_threads\n");
1142
 
1143
 	/* need to clean up again after working events */
1144
-	LEAVE("---------------- finalize_threads ---------------");
1145
+	report("Leaving - ---------------- finalize_threads ---------------\n");
1146
 #endif /* TIOCSERGETLSR & !WIN32 */
1147
 }
1148
 
1149
@@ -1377,6 +1414,8 @@
1150
 {
1151
 	/*
1152
 	char msg[80];
1153
+	
1154
+	memset(&msg[0], 0, sizeof(msg));
1155
 	sprintf( msg, "RXTX Recieved Signal %i\n", signo );
1156
 	report_error( msg );
1157
 	*/
1158
@@ -1386,17 +1425,19 @@
1159
 /*----------------------------------------------------------
1160
 init_threads( )
1161
 
1162
-   accept:      none
1163
-   perform:
1164
-   return:      none
1165
-   exceptions:  none
1166
-   comments:
1167
-   this function is called from the event_loop or in other words
1168
-   from the monitor thread. On systems !WIN32 and without TIOCSERGETLSR
1169
-   it will create a new thread looping a call to tcdrain.
1170
+	accept:		none
1171
+	perform:
1172
+	return:		none
1173
+	exceptions:	none
1174
+	comments:
1175
+				this function is called from the event_loop or in other
1176
+				words from the monitor thread. On systems !WIN32 and 
1177
+				without TIOCSERGETLSR it will create a new thread
1178
+				looping a call to tcdrain.
1179
 ----------------------------------------------------------*/
1180
 int init_threads( struct event_info_struct *eis )
1181
 {
1182
+	report("Entering - init_threads\n");
1183
 	jfieldID jeis;
1184
 #if !defined(TIOCSERGETLSR) & !defined(WIN32)
1185
 	sigset_t newmask, oldmask;
1186
@@ -1404,7 +1445,7 @@
1187
 	pthread_t tid;
1188
 
1189
 	report_time_start( );
1190
-	report("init_threads:  start\n");
1191
+	report("init_threads:	start\n");
1192
 	/* ignore child thread status changes */
1193
 	sigemptyset(&newmask);
1194
 	sigaddset(&newmask, SIGCHLD);
1195
@@ -1412,14 +1453,17 @@
1196
 	/* install our own signal hander */
1197
 	newaction.sa_handler = warn_sig_abort;
1198
 	sigemptyset( &newaction.sa_mask );
1199
-#ifdef SA_INTERRUPT
1200
-	newaction.sa_flags = SA_INTERRUPT;
1201
-#endif /* SA_INTERRUPT */
1202
-#ifdef SA_RESTART
1203
-	/* JOE: do not demand restart! we are handling EINTR */
1204
-/*	newaction.sa_flags = SA_RESTART;*/
1205
-#endif /* SA_RESTART */
1206
-
1207
+	#ifdef SA_INTERRUPT
1208
+		newaction.sa_flags = SA_INTERRUPT;
1209
+	#endif /* SA_INTERRUPT */
1210
+	#ifdef SA_RESTART
1211
+		/* JOE: do not demand restart! we are handling EINTR */
1212
+		/*	newaction.sa_flags = SA_RESTART;*/
1213
+	#endif /* SA_RESTART */
1214
+
1215
+	/**
1216
+	*	POSIX SIGABRT behaviour not changed in original code!!
1217
+	**/
1218
 	sigaction(SIGABRT, &newaction, &oldaction);
1219
 	sigaction(SIGCHLD, &newaction, &oldaction);
1220
 	sigaction(SIGALRM, &newaction, &oldaction);
1221
@@ -1443,23 +1487,25 @@
1222
 	pthread_detach( tid );
1223
 	eis->drain_tid = tid;
1224
 #endif /* TIOCSERGETLSR */
1225
+
1226
 	report("init_threads: get eis\n");
1227
 	jeis  = (*eis->env)->GetFieldID( eis->env, eis->jclazz, "eis", "J" );
1228
 	report("init_threads: set eis\n");
1229
 	(*eis->env)->SetLongField(eis->env, *eis->jobj, jeis, ( size_t ) eis );
1230
-	report("init_threads:  stop\n");
1231
+	report("init_threads:	stop\n");
1232
 	report_time_end( );
1233
+	report("Leaving - init_threads\n");
1234
 	return( 1 );
1235
 }
1236
 
1237
 /*----------------------------------------------------------
1238
 RXTXPort.writeByte
1239
 
1240
-   accept:      byte to write (passed as int)
1241
-                jboolean interrupted (no events if true)
1242
-   perform:     write a single byte to the port
1243
-   return:      none
1244
-   exceptions:  IOException
1245
+	accept:		byte to write (passed as int)
1246
+				jboolean interrupted (no events if true)
1247
+	perform:	write a single byte to the port
1248
+	return:		none
1249
+	exceptions:	IOException
1250
 ----------------------------------------------------------*/
1251
 JNIEXPORT void JNICALL RXTXPort(writeByte)( JNIEnv *env,
1252
 	jobject jobj, jint ji, jboolean interrupted )
1253
@@ -1476,8 +1522,9 @@
1254
 #endif /* __sun__ */
1255
 
1256
 	report_time_start();
1257
-	ENTER( "RXTXPort:writeByte" );
1258
+	report( "Entering - RXTXPort:writeByte\n" );
1259
 	do {
1260
+		memset(&msg[0], 0, sizeof(msg));
1261
 		sprintf( msg, "writeByte %c>>\n", byte );
1262
 		report( msg );
1263
 		result=WRITE (fd, (void * ) &byte, sizeof(unsigned char));
1264
@@ -1506,12 +1553,14 @@
1265
 				index->next ) index = index->next;
1266
 		}
1267
 		index->writing = 1;
1268
-		report( "writeByte:  index->writing = 1" );
1269
+		report( "writeByte:	index->writing = 1\n" );
1270
 	}
1271
 #endif
1272
+	
1273
+	memset(&msg[0], 0, sizeof(msg));
1274
 	sprintf( msg, "RXTXPort:writeByte %i\n", result );
1275
 	report( msg );
1276
-	LEAVE( "RXTXPort:writeByte" );
1277
+	report( "Leaving - RXTXPort:writeByte\n" );
1278
 	if(result >= 0)
1279
 	{
1280
 		report_time_end();
1281
@@ -1525,13 +1574,13 @@
1282
 /*----------------------------------------------------------
1283
 RXTXPort.writeArray
1284
 
1285
-   accept:      jbarray: bytes used for writing
1286
-                offset: offset in array to start writing
1287
-                count: Number of bytes to write
1288
-                jboolean interrupted (no events if true)
1289
-   perform:     write length bytes of jbarray
1290
-   return:      none
1291
-   exceptions:  IOException
1292
+	accept:		jbarray: bytes used for writing
1293
+	offset:		offset in array to start writing
1294
+	count:		Number of bytes to write
1295
+				jboolean interrupted (no events if true)
1296
+	perform:	write length bytes of jbarray
1297
+	return:		none
1298
+	exceptions:	IOException
1299
 ----------------------------------------------------------*/
1300
 JNIEXPORT void JNICALL RXTXPort(writeArray)( JNIEnv *env,
1301
 	jobject jobj, jbyteArray jbarray, jint offset, jint count,
1302
@@ -1562,9 +1611,10 @@
1303
 /* return; OH CRAP */
1304
 
1305
 	report_time_start();
1306
-	ENTER( "writeArray" );
1307
+	report( "Entering - writeArray\n" );
1308
 	/* warning Roy Rogers */
1309
 	/*
1310
+	memset(&message[0], 0, sizeof(message));
1311
 	sprintf( message, "::::RXTXPort:writeArray(%s);\n", (char *) body );
1312
 	report_verbose( message );
1313
 	*/
1314
@@ -1600,7 +1650,7 @@
1315
 				index->next ) index = index->next;
1316
 		}
1317
 		index->writing = 1;
1318
-		report( "writeArray:  index->writing = 1" );
1319
+		report( "writeArray:	index->writing = 1\n" );
1320
 	}
1321
 #endif /* TIOCSERGETLSR */
1322
 	/*
1323
@@ -1615,7 +1665,7 @@
1324
 
1325
 		Things just start spinning out of control after that.
1326
 	*/
1327
-	LEAVE( "RXTXPort:writeArray" );
1328
+	report( "Leaving - RXTXPort:writeArray\n" );
1329
 	report_time_end();
1330
 fail:
1331
 	if( result < 0 ) throw_java_exception( env, IO_EXCEPTION,
1332
@@ -1625,15 +1675,14 @@
1333
 /*----------------------------------------------------------
1334
 RXTXPort.nativeDrain
1335
 
1336
-   accept:      jboolean interrupted (no events if true)
1337
-   perform:     wait until all data is transmitted
1338
-   return:      none
1339
-   exceptions:  IOException
1340
-   comments:    java.io.OutputStream.flush() is equivalent to tcdrain,
1341
-                not tcflush, which throws away unsent bytes
1342
-
1343
-                count logic added to avoid infinite loops when EINTR is
1344
-                true...  Thread.yeild() was suggested.
1345
+	accept:		jboolean interrupted (no events if true)
1346
+	perform:	wait until all data is transmitted
1347
+	return:		none
1348
+	exceptions:	IOException
1349
+	comments:	java.io.OutputStream.flush() is equivalent to tcdrain,
1350
+				not tcflush, which throws away unsent bytes
1351
+				count logic added to avoid infinite loops when EINTR is
1352
+				true...  Thread.yeild() was suggested.
1353
 ----------------------------------------------------------*/
1354
 JNIEXPORT jboolean JNICALL RXTXPort(nativeDrain)( JNIEnv *env,
1355
 	jobject jobj, jboolean interrupted )
1356
@@ -1644,7 +1693,7 @@
1357
 
1358
 	char message[80];
1359
 
1360
-	ENTER( "SerialImp.c:drain()" );
1361
+	report( "Entering - SerialImp.c:drain()\n" );
1362
 	report_time_start( );
1363
 	do {
1364
 		report_verbose( "nativeDrain: trying tcdrain\n" );
1365
@@ -1652,13 +1701,15 @@
1366
 		count++;
1367
 	}  while (result && errno==EINTR && count <3);
1368
 
1369
+	memset(&message[0], 0, sizeof(message));
1370
 	sprintf( message, "RXTXPort:drain() returns: %i\n", result );
1371
 	report_verbose( message );
1372
+	
1373
 #if defined(__sun__)
1374
 	/* FIXME: No time to test on all OS's for production */
1375
 	return( JNI_TRUE );
1376
 #endif /* __sun__ */
1377
-	LEAVE( "RXTXPort:drain()" );
1378
+	report( "Leaving - RXTXPort:drain()\n" );
1379
 	if( result ) throw_java_exception( env, IO_EXCEPTION, "nativeDrain",
1380
 		strerror( errno ) );
1381
 	if( interrupted ) return( JNI_FALSE );
1382
@@ -1669,10 +1720,12 @@
1383
 		eis->output_buffer_empty_flag = 0;
1384
 	}
1385
 #endif /* !TIOCSERGETLSR !WIN32 */
1386
+
1387
 	if( eis && eis->eventflags[SPE_OUTPUT_BUFFER_EMPTY] )
1388
 	{
1389
-                struct event_info_struct myeis =
1390
+		struct event_info_struct myeis =
1391
 			build_threadsafe_eis( env, &jobj, eis );
1392
+			
1393
 		send_event( &myeis, SPE_OUTPUT_BUFFER_EMPTY, 1 );
1394
 	}
1395
 	report_time_end( );
1396
@@ -1682,29 +1735,29 @@
1397
 /*----------------------------------------------------------
1398
 RXTXPort.sendBreak
1399
 
1400
-   accept:     duration in milliseconds.
1401
-   perform:    send break for actual time.  not less than 0.25 seconds.
1402
-   exceptions: none
1403
-   comments:   not very precise
1404
+	accept:		duration in milliseconds.
1405
+	perform:	send break for actual time.  not less than 0.25 seconds.
1406
+	exceptions: none
1407
+	comments:	not very precise
1408
 ----------------------------------------------------------*/
1409
 JNIEXPORT void JNICALL RXTXPort(sendBreak)( JNIEnv *env,
1410
 	jobject jobj, jint duration )
1411
 {
1412
 	int fd = get_java_var( env, jobj,"fd","I" );
1413
 	report_time_start( );
1414
-	ENTER( "RXTXPort:sendBreak()" );
1415
+	report( "Entering - RXTXPort:sendBreak()\n" );
1416
 	tcsendbreak( fd, (int)( duration / 250 ) );
1417
 	report_time_end( );
1418
-	LEAVE( "RXTXPort:sendBreak()" );
1419
+	report( "Leaving - RXTXPort:sendBreak()\n" );
1420
 }
1421
 
1422
 /*----------------------------------------------------------
1423
 RXTXPort.NativegetReceiveTimeout
1424
 
1425
-   accept:     none
1426
-   perform:    get termios.c_cc[VTIME]
1427
-   return:     VTIME
1428
-   comments:   see  NativeEnableReceiveTimeoutThreshold
1429
+	accept:		none
1430
+	perform:	get termios.c_cc[VTIME]
1431
+	return:	VTIME
1432
+	comments:	see  NativeEnableReceiveTimeoutThreshold
1433
 ----------------------------------------------------------*/
1434
 JNIEXPORT jint JNICALL RXTXPort(NativegetReceiveTimeout)(
1435
 	JNIEnv *env,
1436
@@ -1714,12 +1767,12 @@
1437
 	int fd = get_java_var( env, jobj,"fd","I" );
1438
 	struct termios ttyset;
1439
 
1440
-	ENTER( "RXTXPort:nativegetRecieveTimeout()" );
1441
+	report( "Entering - RXTXPort:nativegetRecieveTimeout()\n" );
1442
 	if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
1443
-	LEAVE( "RXTXPort:nativegetRecieveTimeout()" );
1444
+	report( "Leaving - RXTXPort:nativegetRecieveTimeout()\n" );
1445
 	return(ttyset.c_cc[ VTIME ] * 100);
1446
 fail:
1447
-	LEAVE( "RXTXPort:nativegetRecieveTimeout()" );
1448
+	report( "Leaving - RXTXPort:nativegetRecieveTimeout()\n" );
1449
 	throw_java_exception( env, IO_EXCEPTION, "getReceiveTimeout",
1450
 		strerror( errno ) );
1451
 	return -1;
1452
@@ -1728,10 +1781,10 @@
1453
 /*----------------------------------------------------------
1454
 RXTXPort.NativeisReceiveTimeoutEnabled
1455
 
1456
-   accept:     none
1457
-   perform:    determine if VTIME is none 0
1458
-   return:     JNI_TRUE if VTIME > 0 else JNI_FALSE
1459
-   comments:   see  NativeEnableReceiveTimeoutThreshold
1460
+	accept:		none
1461
+	perform:	determine if VTIME is none 0
1462
+	return:		JNI_TRUE if VTIME > 0 else JNI_FALSE
1463
+	comments:	see  NativeEnableReceiveTimeoutThreshold
1464
 ----------------------------------------------------------*/
1465
 JNIEXPORT jboolean JNICALL RXTXPort(NativeisReceiveTimeoutEnabled)(
1466
 	JNIEnv *env,
1467
@@ -1740,12 +1793,12 @@
1468
 {
1469
 	int fd = get_java_var( env, jobj,"fd","I" );
1470
 	struct termios ttyset;
1471
-	ENTER( "RXTXPort:NativeisRecieveTimeoutEnabled()" );
1472
+	report( "Entering - RXTXPort:NativeisRecieveTimeoutEnabled()\n" );
1473
 	if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
1474
-	LEAVE( "RXTXPort:NativeisRecieveTimeoutEnabled()" );
1475
+	report( "Leaving - RXTXPort:NativeisRecieveTimeoutEnabled()\n" );
1476
 	return(ttyset.c_cc[ VTIME ] > 0 ? JNI_TRUE:JNI_FALSE);
1477
 fail:
1478
-	LEAVE( "RXTXPort:NativeisRecieveTimeoutEnabled()" );
1479
+	report( "Leaving - RXTXPort:NativeisRecieveTimeoutEnabled()\n" );
1480
 	throw_java_exception( env, IO_EXCEPTION, "isReceiveTimeoutEnabled",
1481
 		strerror( errno ) );
1482
 	return JNI_FALSE;
1483
@@ -1754,12 +1807,12 @@
1484
 /*----------------------------------------------------------
1485
 RXTXPort.isDSR
1486
 
1487
-   accept:      none
1488
-   perform:     check status of DSR
1489
-   return:      true if TIOCM_DSR is set
1490
-                false if TIOCM_DSR is not set
1491
-   exceptions:  none
1492
-   comments:    DSR stands for Data Set Ready
1493
+	accept:		none
1494
+	perform:	check status of DSR
1495
+	return:		true if TIOCM_DSR is set
1496
+				false if TIOCM_DSR is not set
1497
+	exceptions:	none
1498
+	comments:	DSR stands for Data Set Ready
1499
 ----------------------------------------------------------*/
1500
 JNIEXPORT jboolean JNICALL RXTXPort(isDSR)( JNIEnv *env,
1501
 	jobject jobj )
1502
@@ -1768,11 +1821,13 @@
1503
 	int fd = get_java_var( env, jobj,"fd","I" );
1504
 	char message[80];
1505
 
1506
-	ENTER( "RXTXPort:isDSR" );
1507
+	report( "Entering - RXTXPort:isDSR\n" );
1508
 	ioctl( fd, TIOCMGET, &result );
1509
+	
1510
+	memset(&message[0], 0, sizeof(message));
1511
 	sprintf( message, "RXTXPort:isDSR returns %i\n", result & TIOCM_DSR );
1512
 	report( message );
1513
-	LEAVE( "RXTXPort:isDSR" );
1514
+	report( "Leaving - RXTXPort:isDSR\n" );
1515
 	if( result & TIOCM_DSR ) return JNI_TRUE;
1516
 	else return JNI_FALSE;
1517
 }
1518
@@ -1780,15 +1835,15 @@
1519
 /*----------------------------------------------------------
1520
 RXTXPort.isCD
1521
 
1522
-   accept:      none
1523
-   perform:     check status of CD
1524
-   return:      true if TIOCM_CD is set
1525
-                false if TIOCM_CD is not set
1526
-   exceptions:  none
1527
-   comments:    CD stands for Carrier Detect
1528
-                The following comment has been made...
1529
-                "well, it works, there might ofcourse be a bug, but making DCD
1530
-                permanently on fixed it for me so I don't care"
1531
+	accept:		none
1532
+	perform:	check status of CD
1533
+	return:		true if TIOCM_CD is set
1534
+				false if TIOCM_CD is not set
1535
+	exceptions:	none
1536
+	comments:	CD stands for Carrier Detect
1537
+				The following comment has been made...
1538
+				"well, it works, there might ofcourse be a bug, but making DCD
1539
+				permanently on fixed it for me so I don't care"
1540
 
1541
 ----------------------------------------------------------*/
1542
 JNIEXPORT jboolean JNICALL RXTXPort(isCD)( JNIEnv *env,
1543
@@ -1798,10 +1853,12 @@
1544
 	int fd = get_java_var( env, jobj,"fd","I" );
1545
 	char message[80];
1546
 
1547
-	ENTER( "RXTXPort:isCD" );
1548
+	report( "Entering - RXTXPort:isCD\n" );
1549
 	ioctl( fd, TIOCMGET, &result );
1550
+	
1551
+	memset(&message[0], 0, sizeof(message));
1552
 	sprintf( message, "RXTXPort:isCD returns %i\n", result & TIOCM_CD );
1553
-	LEAVE( "RXTXPort:isCD" );
1554
+	report( "Leaving - RXTXPort:isCD\n" );
1555
 	if( result & TIOCM_CD ) return JNI_TRUE;
1556
 	else return JNI_FALSE;
1557
 }
1558
@@ -1809,12 +1866,12 @@
1559
 /*----------------------------------------------------------
1560
 RXTXPort.isCTS
1561
 
1562
-   accept:      none
1563
-   perform:     check status of CTS
1564
-   return:      true if TIOCM_CTS is set
1565
-                false if TIOCM_CTS is not set
1566
-   exceptions:  none
1567
-   comments:    CTS stands for Clear To Send.
1568
+	accept:		none
1569
+	perform:	check status of CTS
1570
+	return:		true if TIOCM_CTS is set
1571
+				false if TIOCM_CTS is not set
1572
+	exceptions:	none
1573
+	comments:	CTS stands for Clear To Send.
1574
 ----------------------------------------------------------*/
1575
 JNIEXPORT jboolean JNICALL RXTXPort(isCTS)( JNIEnv *env,
1576
 	jobject jobj )
1577
@@ -1823,11 +1880,13 @@
1578
 	int fd = get_java_var( env, jobj,"fd","I" );
1579
 	char message[80];
1580
 
1581
-	ENTER( "RXTXPort:isCTS" );
1582
+	report( "Entering - RXTXPort:isCTS\n" );
1583
 	ioctl( fd, TIOCMGET, &result );
1584
+	
1585
+	memset(&message[0], 0, sizeof(message));
1586
 	sprintf( message, "RXTXPort:isCTS returns %i\n", result & TIOCM_CTS );
1587
 	report( message );
1588
-	LEAVE( "RXTXPort:isCTS" );
1589
+	report( "Leaving - RXTXPort:isCTS\n" );
1590
 	if( result & TIOCM_CTS ) return JNI_TRUE;
1591
 	else return JNI_FALSE;
1592
 }
1593
@@ -1835,12 +1894,12 @@
1594
 /*----------------------------------------------------------
1595
 RXTXPort.isRI
1596
 
1597
-   accept:      none
1598
-   perform:     check status of RI
1599
-   return:      true if TIOCM_RI is set
1600
-                false if TIOCM_RI is not set
1601
-   exceptions:  none
1602
-   comments:    RI stands for Ring Indicator
1603
+	accept:		none
1604
+	perform:	check status of RI
1605
+	return:		true if TIOCM_RI is set
1606
+				false if TIOCM_RI is not set
1607
+	exceptions:	none
1608
+	comments:	RI stands for Ring Indicator
1609
 ----------------------------------------------------------*/
1610
 JNIEXPORT jboolean JNICALL RXTXPort(isRI)( JNIEnv *env,
1611
 	jobject jobj )
1612
@@ -1849,11 +1908,13 @@
1613
 	int fd = get_java_var( env, jobj,"fd","I" );
1614
 	char message[80];
1615
 
1616
-	ENTER( "RXTXPort:isRI" );
1617
+	report( "Entering - RXTXPort:isRI\n" );
1618
 	ioctl( fd, TIOCMGET, &result );
1619
+	
1620
+	memset(&message[0], 0, sizeof(message));
1621
 	sprintf( message, "RXTXPort:isRI returns %i\n", result & TIOCM_RI );
1622
 	report( message );
1623
-	LEAVE( "RXTXPort:isRI" );
1624
+	report( "Leaving - RXTXPort:isRI\n" );
1625
 	if( result & TIOCM_RI ) return JNI_TRUE;
1626
 	else return JNI_FALSE;
1627
 }
1628
@@ -1861,12 +1922,12 @@
1629
 /*----------------------------------------------------------
1630
 RXTXPort.isRTS
1631
 
1632
-   accept:      none
1633
-   perform:     check status of RTS
1634
-   return:      true if TIOCM_RTS is set
1635
-                false if TIOCM_RTS is not set
1636
-   exceptions:  none
1637
-   comments:    tcgetattr with c_cflag CRTS_IFLOW
1638
+	accept:		none
1639
+	perform:	check status of RTS
1640
+	return:		true if TIOCM_RTS is set
1641
+				false if TIOCM_RTS is not set
1642
+	exceptions:	none
1643
+	comments:	tcgetattr with c_cflag CRTS_IFLOW
1644
 ----------------------------------------------------------*/
1645
 JNIEXPORT jboolean JNICALL RXTXPort(isRTS)( JNIEnv *env,
1646
 	jobject jobj )
1647
@@ -1875,11 +1936,13 @@
1648
 	int fd = get_java_var( env, jobj,"fd","I" );
1649
 	char message[80];
1650
 
1651
-	ENTER( "RXTXPort:isRTS" );
1652
+	report( "Entering - RXTXPort:isRTS\n" );
1653
 	ioctl( fd, TIOCMGET, &result );
1654
+	
1655
+	memset(&message[0], 0, sizeof(message));
1656
 	sprintf( message, "RXTXPort:isRTS returns %i\n", result & TIOCM_RTS );
1657
 	report( message );
1658
-	LEAVE( "RXTXPort:isRTS" );
1659
+	report( "Leaving - RXTXPort:isRTS\n" );
1660
 	if( result & TIOCM_RTS ) return JNI_TRUE;
1661
 	else return JNI_FALSE;
1662
 }
1663
@@ -1887,13 +1950,13 @@
1664
 /*----------------------------------------------------------
1665
 RXTXPort.setRTS
1666
 
1667
-   accept:      state  flag to set/unset.
1668
-   perform:     depends on the state flag
1669
-                if true TIOCM_RTS is set
1670
-                if false TIOCM_RTS is unset
1671
-   return:      none
1672
-   exceptions:  none
1673
-   comments:    tcsetattr with c_cflag CRTS_IFLOW
1674
+	accept:		state  flag to set/unset.
1675
+	perform:	depends on the state flag
1676
+				if true TIOCM_RTS is set
1677
+				if false TIOCM_RTS is unset
1678
+	return:		none
1679
+	exceptions:	none
1680
+	comments:	tcsetattr with c_cflag CRTS_IFLOW
1681
 ----------------------------------------------------------*/
1682
 JNIEXPORT void JNICALL RXTXPort(setRTS)( JNIEnv *env,
1683
 	jobject jobj, jboolean state )
1684
@@ -1902,27 +1965,29 @@
1685
 	int fd = get_java_var( env, jobj,"fd","I" );
1686
 	char message[80];
1687
 
1688
-	ENTER( "RXTXPort:setRTS" );
1689
+	report( "Entering - RXTXPort:setRTS\n" );
1690
 	ioctl( fd, TIOCMGET, &result );
1691
 	if( state == JNI_TRUE ) result |= TIOCM_RTS;
1692
 	else result &= ~TIOCM_RTS;
1693
 	ioctl( fd, TIOCMSET, &result );
1694
+	
1695
+	memset(&message[0], 0, sizeof(message));
1696
 	sprintf( message, "setRTS( %i )\n", state );
1697
 	report( message );
1698
-	LEAVE( "RXTXPort:setRTS" );
1699
+	report( "Leaving - RXTXPort:setRTS\n" );
1700
 	return;
1701
 }
1702
 
1703
 /*----------------------------------------------------------
1704
 RXTXPort.setDSR
1705
 
1706
-   accept:      state  flag to set/unset.
1707
-   perform:     depends on the state flag
1708
-                if true TIOCM_DSR is set
1709
-                if false TIOCM_DSR is unset
1710
-   return:      none
1711
-   exceptions:  none
1712
-   comments:    tcsetattr with c_cflag CRTS_IFLOW
1713
+	accept:		state  flag to set/unset.
1714
+	perform:	depends on the state flag
1715
+				if true TIOCM_DSR is set
1716
+				if false TIOCM_DSR is unset
1717
+	return:		none
1718
+	exceptions:	none
1719
+	comments:	tcsetattr with c_cflag CRTS_IFLOW
1720
 ----------------------------------------------------------*/
1721
 JNIEXPORT void JNICALL RXTXPort(setDSR)( JNIEnv *env,
1722
 	jobject jobj, jboolean state )
1723
@@ -1931,28 +1996,31 @@
1724
 	int fd = get_java_var( env, jobj,"fd","I" );
1725
 	char message[80];
1726
 
1727
-	ENTER( "RXTXPort:setDSR()" );
1728
+	report( "Entering - RXTXPort:setDSR()\n" );
1729
 	ioctl( fd, TIOCMGET, &result );
1730
 
1731
+	memset(&message[0], 0, sizeof(message));
1732
 	sprintf( message, "setDSR( %i )\n", state );
1733
 	if( state == JNI_TRUE ) result |= TIOCM_DSR;
1734
 	else result &= ~TIOCM_DSR;
1735
 	ioctl( fd, TIOCMSET, &result );
1736
+	
1737
+	memset(&message[0], 0, sizeof(message));
1738
 	sprintf( message, "setDSR( %i )\n", state );
1739
 	report( message );
1740
-	LEAVE( "RXTXPort:setDSR()" );
1741
+	report( "Leaving - RXTXPort:setDSR()\n" );
1742
 	return;
1743
 }
1744
 
1745
 /*----------------------------------------------------------
1746
 RXTXPort.isDTR
1747
 
1748
-   accept:      none
1749
-   perform:     check status of DTR
1750
-   return:      true if TIOCM_DTR is set
1751
-                false if TIOCM_DTR is not set
1752
-   exceptions:  none
1753
-   comments:    DTR stands for Data Terminal Ready
1754
+	accept:		none
1755
+	perform:	check status of DTR
1756
+	return:		true if TIOCM_DTR is set
1757
+				false if TIOCM_DTR is not set
1758
+	exceptions:	none
1759
+	comments:	DTR stands for Data Terminal Ready
1760
 ----------------------------------------------------------*/
1761
 JNIEXPORT jboolean JNICALL RXTXPort(isDTR)( JNIEnv *env,
1762
 	jobject jobj )
1763
@@ -1961,11 +2029,13 @@
1764
 	int fd = get_java_var( env, jobj,"fd","I" );
1765
 	char message[80];
1766
 
1767
-	ENTER( "RXTXPort:isDTR" );
1768
+	report( "Entering - RXTXPort:isDTR\n" );
1769
 	ioctl( fd, TIOCMGET, &result );
1770
+	
1771
+	memset(&message[0], 0, sizeof(message));
1772
 	sprintf( message, "isDTR( ) returns %i\n", result& TIOCM_DTR );
1773
 	report( message );
1774
-	LEAVE( "RXTXPort:isDTR" );
1775
+	report( "Leaving - RXTXPort:isDTR\n" );
1776
 	if( result & TIOCM_DTR ) return JNI_TRUE;
1777
 	else return JNI_FALSE;
1778
 }
1779
@@ -1973,12 +2043,12 @@
1780
 /*----------------------------------------------------------
1781
 RXTXPort.setDTR
1782
 
1783
-   accept:      new DTR state
1784
-   perform:     if state is true, TIOCM_DTR is set
1785
-                if state is false, TIOCM_DTR is unset
1786
-   return:      none
1787
-   exceptions:  none
1788
-   comments:    DTR stands for Data Terminal Ready
1789
+	accept:		new DTR state
1790
+	perform:	if state is true, TIOCM_DTR is set
1791
+				if state is false, TIOCM_DTR is unset
1792
+	return:		none
1793
+	exceptions:	none
1794
+	comments:	DTR stands for Data Terminal Ready
1795
 ----------------------------------------------------------*/
1796
 JNIEXPORT void JNICALL RXTXPort(setDTR)( JNIEnv *env,
1797
 	jobject jobj, jboolean state )
1798
@@ -1987,32 +2057,35 @@
1799
 	int fd = get_java_var( env, jobj,"fd","I" );
1800
 	char message[80];
1801
 
1802
-	ENTER( "RXTXPort:setDTR" );
1803
+	report( "Entering - RXTXPort:setDTR\n" );
1804
 	ioctl( fd, TIOCMGET, &result );
1805
 	if( state == JNI_TRUE ) result |= TIOCM_DTR;
1806
 	else result &= ~TIOCM_DTR;
1807
 	ioctl( fd, TIOCMSET, &result );
1808
+	
1809
+	memset(&message[0], 0, sizeof(message));
1810
 	sprintf( message, "setDTR( %i )\n", state );
1811
 	report( message );
1812
-	LEAVE( "RXTXPort:setDTR" );
1813
+	report( "Leaving - RXTXPort:setDTR\n" );
1814
 	return;
1815
 }
1816
 /*----------------------------------------------------------
1817
 RXTXPort.static_add_filename
1818
 
1819
-   accept:      filename and fd to save
1820
-   perform:     add a struct holding the info to a linked list
1821
-   return:      none
1822
-   exceptions:  none
1823
-   comments:    the info is checked on open() if its in the list no
1824
-		changes are performed on the file on open()
1825
-
1826
-   comments:    see
1827
-			RXTXPort.nativeStaticSetDSR
1828
-			RXTXPort.nativeStaticSetDTR
1829
-			RXTXPort.nativeStaticSetRTS
1830
-			RXTXPort.nativeStaticSetSerialPortParams
1831
-		This is used so people can setDTR low before calling the
1832
+	accept:		filename and fd to save
1833
+	perform:	add a struct holding the info to a linked list
1834
+	return:		none
1835
+	exceptions:	none
1836
+	comments:	the info is checked on open() if its in the list no
1837
+				changes are performed on the file on open()
1838
+
1839
+	comments:	see
1840
+				RXTXPort.nativeStaticSetDSR
1841
+				RXTXPort.nativeStaticSetDTR
1842
+				RXTXPort.nativeStaticSetRTS
1843
+				RXTXPort.nativeStaticSetSerialPortParams
1844
+				
1845
+	This is used so people can setDTR low before calling the
1846
 -----------------------------------------------------------*/
1847
 
1848
 void static_add_filename( const char *filename, int fd)
1849
@@ -2055,14 +2128,14 @@
1850
 /*----------------------------------------------------------
1851
 RXTXPort.nativeSetBaudBase
1852
 
1853
-   accept:      The Baud Base for custom speeds
1854
-   perform:     set the Baud Base
1855
-   return:      0 on success
1856
-   exceptions:  Unsupported Comm Operation on systems not supporting
1857
-                TIOCGSERIAL
1858
-   comments:
1859
-		Set baud rate to 38400 before using this
1860
-		First introduced in rxtx-2.1-3
1861
+	accept:		The Baud Base for custom speeds
1862
+	perform:	set the Baud Base
1863
+	return:		0 on success
1864
+	exceptions:	Unsupported Comm Operation on systems not supporting
1865
+				TIOCGSERIAL
1866
+	comments:
1867
+				Set baud rate to 38400 before using this
1868
+				First introduced in rxtx-2.1-3
1869
 ----------------------------------------------------------*/
1870
 JNIEXPORT jboolean JNICALL RXTXPort(nativeSetBaudBase)(
1871
 	JNIEnv *env,
1872
@@ -2103,13 +2176,13 @@
1873
 /*----------------------------------------------------------
1874
 RXTXPort.nativeGetBaudBase
1875
 
1876
-   accept:      the Baud Base used for custom speeds
1877
-   perform:
1878
-   return:      Baud Base
1879
-   exceptions:  Unsupported Comm Operation on systems not supporting
1880
-                TIOCGSERIAL
1881
-   comments:
1882
-		First introduced in rxtx-2.1-3
1883
+	accept:		the Baud Base used for custom speeds
1884
+	perform:
1885
+	return:		Baud Base
1886
+	exceptions:	Unsupported Comm Operation on systems not supporting
1887
+				TIOCGSERIAL
1888
+	comments:
1889
+				First introduced in rxtx-2.1-3
1890
 ----------------------------------------------------------*/
1891
 JNIEXPORT jint JNICALL RXTXPort(nativeGetBaudBase)(
1892
 	JNIEnv *env,
1893
@@ -2141,14 +2214,14 @@
1894
 /*----------------------------------------------------------
1895
 RXTXPort.nativeSetDivisor
1896
 
1897
-   accept:      Divisor for custom speeds
1898
-   perform:     set the Divisor for custom speeds
1899
-   return:      0 on success
1900
-   exceptions:  Unsupported Comm Operation on systems not supporting
1901
-                TIOCGSERIAL
1902
-   comments:
1903
-		Set baud rate to 38400 before using this
1904
-		First introduced in rxtx-2.1-3
1905
+	accept:		Divisor for custom speeds
1906
+	perform:	set the Divisor for custom speeds
1907
+	return:		0 on success
1908
+	exceptions:	Unsupported Comm Operation on systems not supporting
1909
+				TIOCGSERIAL
1910
+	comments:
1911
+				Set baud rate to 38400 before using this
1912
+				First introduced in rxtx-2.1-3
1913
 ----------------------------------------------------------*/
1914
 JNIEXPORT jboolean JNICALL RXTXPort(nativeSetDivisor)(
1915
 	JNIEnv *env,
1916
@@ -2187,13 +2260,13 @@
1917
 /*----------------------------------------------------------
1918
 RXTXPort.nativeGetDivisor
1919
 
1920
-   accept:      none
1921
-   perform:     Find the Divisor used for custom speeds
1922
-   return:      Divisor negative value on error.
1923
-   exceptions:  Unsupported Comm Operation on systems not supporting
1924
-	        TIOCGSERIAL
1925
-   comments:
1926
-		First introduced in rxtx-2.1-3
1927
+	accept:		none
1928
+	perform:	Find the Divisor used for custom speeds
1929
+	return:		Divisor negative value on error.
1930
+	exceptions:	Unsupported Comm Operation on systems not supporting
1931
+				TIOCGSERIAL
1932
+	comments:
1933
+				First introduced in rxtx-2.1-3
1934
 ----------------------------------------------------------*/
1935
 JNIEXPORT jint JNICALL RXTXPort(nativeGetDivisor)(
1936
 	JNIEnv *env,
1937
@@ -2226,18 +2299,18 @@
1938
 /*----------------------------------------------------------
1939
 RXTXPort.nativeStaticSetDSR
1940
 
1941
-   accept:      new RTS state
1942
-   perform:     if flag is true, TIOCM_DSR is set
1943
-                if flag is false, TIOCM_DSR is unset
1944
-   return:      none
1945
-   exceptions:  none
1946
-   comments:    Set the DSR so it does not raise on the next open
1947
-		needed for some funky test boards?
1948
+	accept:		new RTS state
1949
+	perform:	if flag is true, TIOCM_DSR is set
1950
+				if flag is false, TIOCM_DSR is unset
1951
+	return:		none
1952
+	exceptions:	none
1953
+	comments:	Set the DSR so it does not raise on the next open
1954
+				needed for some funky test boards?
1955
 
1956
-		This is static so we can not call the open() setDSR()
1957
-		we dont have the jobject.
1958
+			This is static so we can not call the open() setDSR()
1959
+			we dont have the jobject.
1960
 
1961
-		First introduced in rxtx-1.5-9
1962
+			First introduced in rxtx-1.5-9
1963
 ----------------------------------------------------------*/
1964
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetDSR) (JNIEnv *env,
1965
 	jclass jclazz, jstring jstr, jboolean flag)
1966
@@ -2247,7 +2320,7 @@
1967
 	int result;
1968
 	const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 );
1969
 
1970
-	ENTER( "RXTXPort:nativeStaticSetDSR" );
1971
+	report( "Entering - RXTXPort:nativeStaticSetDSR\n" );
1972
 #ifndef WIN32
1973
 	pid = getpid();
1974
 #endif /* WIN32 */
1975
@@ -2281,29 +2354,29 @@
1976
 
1977
 	/* dont close the port.  Its not clear if the DSR would remain high */
1978
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
1979
-	LEAVE( "RXTXPort:nativeStaticSetDSR" );
1980
+	report( "Leaving - RXTXPort:nativeStaticSetDSR\n" );
1981
 	return( JNI_TRUE );
1982
 fail:
1983
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
1984
-	LEAVE( "RXTXPort:nativeStaticSetDSR" );
1985
+	report( "Leaving - RXTXPort:nativeStaticSetDSR\n" );
1986
 	return( JNI_FALSE );
1987
 }
1988
 
1989
 /*----------------------------------------------------------
1990
 RXTXPort.nativeStaticSetRTS
1991
 
1992
-   accept:      new RTS state
1993
-   perform:     if flag is true, TIOCM_RTS is set
1994
-                if flag is false, TIOCM_RTS is unset
1995
-   return:      none
1996
-   exceptions:  none
1997
-   comments:    Set the RTS so it does not raise on the next open
1998
-		needed for some funky test boards?
1999
-
2000
-		This is static so we can not call the open() setDTR()
2001
-		we dont have the jobject.
2002
-
2003
-		First introduced in rxtx-1.5-9
2004
+	accept:		new RTS state
2005
+	perform:	if flag is true, TIOCM_RTS is set
2006
+				if flag is false, TIOCM_RTS is unset
2007
+	return:		none
2008
+	exceptions:	none
2009
+	comments:	Set the RTS so it does not raise on the next open
2010
+				needed for some funky test boards?
2011
+
2012
+				This is static so we can not call the open() setDTR()
2013
+				we dont have the jobject.
2014
+				
2015
+				First introduced in rxtx-1.5-9
2016
 ----------------------------------------------------------*/
2017
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetRTS) (JNIEnv *env,
2018
 	jclass jclazz, jstring jstr, jboolean flag)
2019
@@ -2313,7 +2386,7 @@
2020
 	int result;
2021
 	const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 );
2022
 
2023
-	ENTER( "RXTXPort:nativeStaticSetRTS" );
2024
+	report( "Entering - RXTXPort:nativeStaticSetRTS\n" );
2025
 #ifndef WIN32
2026
 	pid = getpid();
2027
 #endif /* WIN32 */
2028
@@ -2347,29 +2420,29 @@
2029
 
2030
 	/* dont close the port.  Its not clear if the RTS would remain high */
2031
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2032
-	LEAVE( "RXTXPort:nativeStaticSetRTS" );
2033
+	report( "Leaving - RXTXPort:nativeStaticSetRTS\n" );
2034
 	return( JNI_TRUE );
2035
 fail:
2036
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2037
-	LEAVE( "RXTXPort:nativeStaticSetRTS" );
2038
+	report( "Leaving - RXTXPort:nativeStaticSetRTS\n" );
2039
 	return( JNI_FALSE );
2040
 }
2041
 
2042
 /*----------------------------------------------------------
2043
 RXTXPort.nativeStaticSetSerialPortParams
2044
 
2045
-   accept:      string for the filename, int baudrate, int databits,
2046
-		int stopbits, int parity
2047
-   perform:     set the serial port, set the params, save the fd in a linked
2048
+	accept:		string for the filename, int baudrate, int databits,
2049
+				int stopbits, int parity
2050
+	perform:	set the serial port, set the params, save the fd in a linked
2051
 		list.
2052
-   return:      none
2053
-   exceptions:  none
2054
-   comments:    Not set the speed on the next 'open'
2055
+	return:		none
2056
+	exceptions:	none
2057
+	comments:	Not set the speed on the next 'open'
2058
 
2059
-		This is static so we can not call the open() setDTR()
2060
-		we dont have the jobject.
2061
+				This is static so we can not call the open() setDTR()
2062
+				we dont have the jobject.
2063
 
2064
-		First introduced in rxtx-1.5-9
2065
+				First introduced in rxtx-1.5-9
2066
 ----------------------------------------------------------*/
2067
 JNIEXPORT void JNICALL RXTXPort(nativeStaticSetSerialPortParams) (JNIEnv *env,
2068
 	jclass jclazz, jstring jstr, jint baudrate, jint dataBits, jint stopBits, jint parity )
2069
@@ -2380,7 +2453,7 @@
2070
 	int cspeed = translate_speed( env, baudrate );
2071
 
2072
 
2073
-	ENTER( "RXTXPort:nativeStaticSetSerialPortParams" );
2074
+	report( "Entering - RXTXPort:nativeStaticSetSerialPortParams\n" );
2075
 #ifndef WIN32
2076
 	pid = getpid();
2077
 #endif /* WIN32 */
2078
@@ -2400,7 +2473,7 @@
2079
 	if ( fd < 0 )
2080
 	{
2081
 		(*env)->ReleaseStringUTFChars( env, jstr, filename );
2082
-		LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" );
2083
+		report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" );
2084
 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
2085
 			"nativeStaticSetSerialPortParams", strerror( errno ) );
2086
 		return;
2087
@@ -2410,14 +2483,14 @@
2088
 	{
2089
 		(*env)->ReleaseStringUTFChars( env, jstr, filename );
2090
 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
2091
-			"", "BaudRate could not be set to the specified value" );
2092
+			"", "BaudRate could not be set to the specified value\n" );
2093
 		return;
2094
 	}
2095
 
2096
 	if( set_port_params( env, fd, cspeed, dataBits, stopBits, parity ) )
2097
 	{
2098
 		(*env)->ReleaseStringUTFChars( env, jstr, filename );
2099
-		LEAVE( "RXTXPort:nativeStatic SetSerialPortParams" );
2100
+		report( "Leaving - RXTXPort:nativeStatic SetSerialPortParams\n" );
2101
 		throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
2102
 			"nativeStaticSetSerialPortParams", strerror( errno ) );
2103
 		return;
2104
@@ -2431,29 +2504,29 @@
2105
 	/* dont close the port. */
2106
 
2107
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2108
-	LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" );
2109
+	report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" );
2110
 	return;
2111
 fail:
2112
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2113
-	LEAVE( "RXTXPort:nativeStaticSetSerialPortParams" );
2114
+	report( "Leaving - RXTXPort:nativeStaticSetSerialPortParams\n" );
2115
 	return;
2116
 }
2117
 
2118
 /*----------------------------------------------------------
2119
 RXTXPort.nativeStaticSetDTR
2120
 
2121
-   accept:      new DTR state
2122
-   perform:     if flag is true, TIOCM_DTR is set
2123
-                if flag is false, TIOCM_DTR is unset
2124
-   return:      none
2125
-   exceptions:  none
2126
-   comments:    Set the DTR so it does not raise on the next open
2127
-		needed for some funky test boards?
2128
-
2129
-		This is static so we can not call the open() setDTR()
2130
-		we dont have the jobject.
2131
-
2132
-		First introduced in rxtx-1.5-9
2133
+	accept:		new DTR state
2134
+	perform:	if flag is true, TIOCM_DTR is set
2135
+				if flag is false, TIOCM_DTR is unset
2136
+	return:		none
2137
+	exceptions:	none
2138
+	comments:	Set the DTR so it does not raise on the next open
2139
+				needed for some funky test boards?
2140
+				
2141
+				This is static so we can not call the open() setDTR()
2142
+				we dont have the jobject.
2143
+				
2144
+				First introduced in rxtx-1.5-9
2145
 ----------------------------------------------------------*/
2146
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticSetDTR) (JNIEnv *env,
2147
 	jclass jclazz, jstring jstr, jboolean flag)
2148
@@ -2463,7 +2536,7 @@
2149
 	const char *filename = (*env)->GetStringUTFChars( env, jstr, 0 );
2150
 	int result;
2151
 
2152
-	ENTER( "RXTXPort:nativeStaticSetDTR" );
2153
+	report( "Entering - RXTXPort:nativeStaticSetDTR\n" );
2154
 #ifndef WIN32
2155
 	pid = getpid();
2156
 #endif /* WIN32 */
2157
@@ -2497,24 +2570,24 @@
2158
 	/* dont close the port.  Its not clear if the DTR would remain high */
2159
 
2160
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2161
-	LEAVE( "RXTXPort:nativeStaticSetDTR" );
2162
+	report( "Leaving - RXTXPort:nativeStaticSetDTR\n" );
2163
 	return( JNI_TRUE );
2164
 fail:
2165
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2166
-	LEAVE( "RXTXPort:nativeStaticSetDTR" );
2167
+	report( "Leaving - RXTXPort:nativeStaticSetDTR\n" );
2168
 	return( JNI_FALSE );
2169
 }
2170
 
2171
 /*----------------------------------------------------------
2172
 RXTXPort.nativeStaticIsRTS
2173
 
2174
-   accept:      filename
2175
-   perform:     check status of RTS of preopened ports (setting lines/params
2176
-		before calling the Java open()
2177
-   return:      true if TIOCM_RTS is set
2178
-                false if TIOCM_RTS is not set
2179
-   exceptions:  none
2180
-   comments:    RTS stands for Request to Send
2181
+	accept:		filename
2182
+	perform:	check status of RTS of preopened ports (setting lines/params
2183
+				before calling the Java open()
2184
+	return:		true if TIOCM_RTS is set
2185
+				false if TIOCM_RTS is not set
2186
+	exceptions:	none
2187
+	comments:	RTS stands for Request to Send
2188
 ----------------------------------------------------------*/
2189
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRTS)( JNIEnv *env,
2190
 	jobject jobj, jstring jstr )
2191
@@ -2524,29 +2597,31 @@
2192
 	int fd = find_preopened_ports( filename );
2193
 	char message[80];
2194
 
2195
-	ENTER( "RXTXPort:nativeStaticIsRTS" );
2196
+	report( "Entering - RXTXPort:nativeStaticIsRTS\n" );
2197
 	if( !fd )
2198
 	{
2199
 		/* Exception? FIXME */
2200
 		return JNI_FALSE;
2201
 	}
2202
 	ioctl( fd, TIOCMGET, &result );
2203
+	
2204
+	memset(&message[0], 0, sizeof(message));
2205
 	sprintf( message, "nativeStaticIsRTS( ) returns %i\n", result& TIOCM_RTS );
2206
 	report( message );
2207
-	LEAVE( "RXTXPort:nativeStaticIsRTS" );
2208
+	report( "Leaving - RXTXPort:nativeStaticIsRTS\n" );
2209
 	if( result & TIOCM_RTS ) return JNI_TRUE;
2210
 	else return JNI_FALSE;
2211
 }
2212
 /*----------------------------------------------------------
2213
 RXTXPort.nativeStaticIsDSR
2214
 
2215
-   accept:      filename
2216
-   perform:     check status of DSR of preopened ports (setting lines/params
2217
-		before calling the Java open()
2218
-   return:      true if TIOCM_DSR is set
2219
-                false if TIOCM_DSR is not set
2220
-   exceptions:  none
2221
-   comments:
2222
+	accept:		filename
2223
+	perform:	check status of DSR of preopened ports (setting lines/params
2224
+				before calling the Java open()
2225
+	return:		true if TIOCM_DSR is set
2226
+				false if TIOCM_DSR is not set
2227
+	exceptions:	none
2228
+	comments:
2229
 ----------------------------------------------------------*/
2230
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDSR)( JNIEnv *env,
2231
 	jobject jobj, jstring jstr )
2232
@@ -2556,29 +2631,31 @@
2233
 	int fd = find_preopened_ports( filename );
2234
 	char message[80];
2235
 
2236
-	ENTER( "RXTXPort:nativeStaticIsDSR" );
2237
+	report( "Entering - RXTXPort:nativeStaticIsDSR\n" );
2238
 	if( !fd )
2239
 	{
2240
 		/* Exception? FIXME */
2241
 		return JNI_FALSE;
2242
 	}
2243
 	ioctl( fd, TIOCMGET, &result );
2244
+	
2245
+	memset(&message[0], 0, sizeof(message));
2246
 	sprintf( message, "nativeStaticIsDSR( ) returns %i\n", result& TIOCM_DSR );
2247
 	report( message );
2248
-	LEAVE( "RXTXPort:nativeStaticIsDSR" );
2249
+	report( "Leaving - RXTXPort:nativeStaticIsDSR\n" );
2250
 	if( result & TIOCM_DSR ) return JNI_TRUE;
2251
 	else return JNI_FALSE;
2252
 }
2253
 /*----------------------------------------------------------
2254
 RXTXPort.nativeStaticIsDTR
2255
 
2256
-   accept:      filename
2257
-   perform:     check status of DTR of preopened ports (setting lines/params
2258
-		before calling the Java open()
2259
-   return:      true if TIOCM_DTR is set
2260
-                false if TIOCM_DTR is not set
2261
-   exceptions:  none
2262
-   comments:    DTR stands for Data Terminal Ready
2263
+	accept:		filename
2264
+	perform:	check status of DTR of preopened ports (setting lines/params
2265
+				before calling the Java open()
2266
+	return:		true if TIOCM_DTR is set
2267
+				false if TIOCM_DTR is not set
2268
+	exceptions:	none
2269
+	comments:	DTR stands for Data Terminal Ready
2270
 ----------------------------------------------------------*/
2271
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsDTR)( JNIEnv *env,
2272
 	jobject jobj, jstring jstr )
2273
@@ -2588,29 +2665,31 @@
2274
 	int fd = find_preopened_ports( filename );
2275
 	char message[80];
2276
 
2277
-	ENTER( "RXTXPort:nativeStaticIsDTR" );
2278
+	report( "Entering - RXTXPort:nativeStaticIsDTR\n" );
2279
 	if( !fd )
2280
 	{
2281
 		/* Exception? FIXME */
2282
 		return JNI_FALSE;
2283
 	}
2284
 	ioctl( fd, TIOCMGET, &result );
2285
+	
2286
+	memset(&message[0], 0, sizeof(message));
2287
 	sprintf( message, "nativeStaticIsDTR( ) returns %i\n", result& TIOCM_DTR );
2288
 	report( message );
2289
-	LEAVE( "RXTXPort:nativeStaticIsDTR" );
2290
+	report( "Leaving - RXTXPort:nativeStaticIsDTR\n" );
2291
 	if( result & TIOCM_DTR ) return JNI_TRUE;
2292
 	else return JNI_FALSE;
2293
 }
2294
 /*----------------------------------------------------------
2295
 RXTXPort.nativeStaticIsCD
2296
 
2297
-   accept:      filename
2298
-   perform:     check status of CD of preopened ports (setting lines/params
2299
-		before calling the Java open()
2300
-   return:      true if TIOCM_CD is set
2301
-                false if TIOCM_CD is not set
2302
-   exceptions:  none
2303
-   comments:    CD stands for carrier detect
2304
+	accept:		filename
2305
+	perform:	check status of CD of preopened ports (setting lines/params
2306
+				before calling the Java open()
2307
+	return:		true if TIOCM_CD is set
2308
+				false if TIOCM_CD is not set
2309
+	exceptions:	none
2310
+	comments:	CD stands for carrier detect
2311
 ----------------------------------------------------------*/
2312
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCD)( JNIEnv *env,
2313
 	jobject jobj, jstring jstr )
2314
@@ -2620,29 +2699,31 @@
2315
 	int fd = find_preopened_ports( filename );
2316
 	char message[80];
2317
 
2318
-	ENTER( "RXTXPort:nativeStaticIsCD" );
2319
+	report( "Entering - RXTXPort:nativeStaticIsCD\n" );
2320
 	if( !fd )
2321
 	{
2322
 		/* Exception? FIXME */
2323
 		return JNI_FALSE;
2324
 	}
2325
 	ioctl( fd, TIOCMGET, &result );
2326
+	
2327
+	memset(&message[0], 0, sizeof(message));
2328
 	sprintf( message, "nativeStaticIsCD( ) returns %i\n", result& TIOCM_CD );
2329
 	report( message );
2330
-	LEAVE( "RXTXPort:nativeStaticIsCD" );
2331
+	report( "Leaving - RXTXPort:nativeStaticIsCD\n" );
2332
 	if( result & TIOCM_CD ) return JNI_TRUE;
2333
 	else return JNI_FALSE;
2334
 }
2335
 /*----------------------------------------------------------
2336
 RXTXPort.nativeStaticIsCTS
2337
 
2338
-   accept:      filename
2339
-   perform:     check status of CTS of preopened ports (setting lines/params
2340
-		before calling the Java open()
2341
-   return:      true if TIOCM_CTS is set
2342
-                false if TIOCM_CTS is not set
2343
-   exceptions:  none
2344
-   comments:    CTS stands for Clear To Send
2345
+	accept:		filename
2346
+	perform:	check status of CTS of preopened ports (setting lines/params
2347
+				before calling the Java open()
2348
+	return:		true if TIOCM_CTS is set
2349
+				false if TIOCM_CTS is not set
2350
+	exceptions:	none
2351
+	comments:	CTS stands for Clear To Send
2352
 ----------------------------------------------------------*/
2353
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsCTS)( JNIEnv *env,
2354
 	jobject jobj, jstring jstr )
2355
@@ -2652,29 +2733,31 @@
2356
 	int fd = find_preopened_ports( filename );
2357
 	char message[80];
2358
 
2359
-	ENTER( "RXTXPort:nativeStaticIsCTS" );
2360
+	report( "Entering - RXTXPort:nativeStaticIsCTS\n" );
2361
 	if( !fd )
2362
 	{
2363
 		/* Exception? FIXME */
2364
 		return JNI_FALSE;
2365
 	}
2366
 	ioctl( fd, TIOCMGET, &result );
2367
+	
2368
+	memset(&message[0], 0, sizeof(message));
2369
 	sprintf( message, "nativeStaticIsCTS( ) returns %i\n", result& TIOCM_CTS );
2370
 	report( message );
2371
-	LEAVE( "RXTXPort:nativeStaticIsCTS" );
2372
+	report( "Leaving - RXTXPort:nativeStaticIsCTS\n" );
2373
 	if( result & TIOCM_CTS ) return JNI_TRUE;
2374
 	else return JNI_FALSE;
2375
 }
2376
 /*----------------------------------------------------------
2377
 RXTXPort.nativeStaticIsRI
2378
 
2379
-   accept:      filename
2380
-   perform:     check status of RI of preopened ports (setting lines/params
2381
-		before calling the Java open()
2382
-   return:      true if TIOCM_RI is set
2383
-                false if TIOCM_RI is not set
2384
-   exceptions:  none
2385
-   comments:    RI stands for carrier detect
2386
+	accept:		filename
2387
+	perform:	check status of RI of preopened ports (setting lines/params
2388
+				before calling the Java open()
2389
+	return:		true if TIOCM_RI is set
2390
+				false if TIOCM_RI is not set
2391
+	exceptions:	none
2392
+	comments:	RI stands for carrier detect
2393
 ----------------------------------------------------------*/
2394
 JNIEXPORT jboolean JNICALL RXTXPort(nativeStaticIsRI)( JNIEnv *env,
2395
 	jobject jobj, jstring jstr )
2396
@@ -2684,16 +2767,18 @@
2397
 	int fd = find_preopened_ports( filename );
2398
 	char message[80];
2399
 
2400
-	ENTER( "RXTXPort:nativeStaticIsRI" );
2401
+	report( "Entering - RXTXPort:nativeStaticIsRI\n" );
2402
 	if( !fd )
2403
 	{
2404
 		/* Exception? FIXME */
2405
 		return JNI_FALSE;
2406
 	}
2407
 	ioctl( fd, TIOCMGET, &result );
2408
+	
2409
+	memset(&message[0], 0, sizeof(message));
2410
 	sprintf( message, "nativeStaticRI( ) returns %i\n", result& TIOCM_RI );
2411
 	report( message );
2412
-	LEAVE( "RXTXPort:nativeStaticIsRI" );
2413
+	report( "Leaving - RXTXPort:nativeStaticIsRI\n" );
2414
 	if( result & TIOCM_RI ) return JNI_TRUE;
2415
 	else return JNI_FALSE;
2416
 }
2417
@@ -2701,11 +2786,11 @@
2418
 /*----------------------------------------------------------
2419
 RXTXPort.nativeStaticGetBaudRate
2420
 
2421
-   accept:      filename
2422
-   perform:     find the baud rate (not all buads are handled yet)
2423
-   return:      return the baud rate or -1 if not supported yet.
2424
-   exceptions:
2425
-   comments:    simple test for preopened ports
2426
+	accept:		filename
2427
+	perform:	find the baud rate (not all buads are handled yet)
2428
+	return:		return the baud rate or -1 if not supported yet.
2429
+	exceptions:
2430
+	comments:	simple test for preopened ports
2431
 ----------------------------------------------------------*/
2432
 JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetBaudRate)( JNIEnv *env, jobject jobj, jstring jstr )
2433
 {
2434
@@ -2715,7 +2800,7 @@
2435
 	int baudrate;
2436
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2437
 
2438
-	ENTER( "RXTXPort:nativeStaticGetBaudRate" );
2439
+	report( "Entering - RXTXPort:nativeStaticGetBaudRate\n" );
2440
 	if( !fd )
2441
 	{
2442
 		/* Exception? FIXME */
2443
@@ -2743,21 +2828,21 @@
2444
 
2445
 */
2446
 #if defined(CBAUD)/* dima */
2447
-    	baudrate = ttyset.c_cflag&CBAUD;
2448
+		baudrate = ttyset.c_cflag&CBAUD;
2449
 #else
2450
-    	if(cfgetispeed(&ttyset) != cfgetospeed(&ttyset)) return -1;
2451
-    	baudrate = cfgetispeed(&ttyset);
2452
+		if(cfgetispeed(&ttyset) != cfgetospeed(&ttyset)) return -1;
2453
+		baudrate = cfgetispeed(&ttyset);
2454
 #endif
2455
 	return( get_java_baudrate(baudrate) );
2456
 }
2457
 /*----------------------------------------------------------
2458
 RXTXPort.nativeStaticGetDataBits
2459
 
2460
-   accept:      filename
2461
-   perform:     find the data bits (not all buads are handled yet)
2462
-   return:      return the data bits
2463
-   exceptions:
2464
-   comments:    simple test for preopened ports
2465
+	accept:		filename
2466
+	perform:	find the data bits (not all buads are handled yet)
2467
+	return:		return the data bits
2468
+	exceptions:
2469
+	comments:	simple test for preopened ports
2470
 ----------------------------------------------------------*/
2471
 JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetDataBits)( JNIEnv *env, jobject jobj, jstring jstr )
2472
 {
2473
@@ -2766,7 +2851,7 @@
2474
 	struct termios ttyset;
2475
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2476
 
2477
-	ENTER( "RXTXPort:nativeStaticGetDataBits" );
2478
+	report( "Entering - RXTXPort:nativeStaticGetDataBits\n" );
2479
 	if( !fd )
2480
 	{
2481
 		/* Exception? FIXME */
2482
@@ -2778,21 +2863,21 @@
2483
 		return(-1);
2484
 	}
2485
 	switch( ttyset.c_cflag&CSIZE ) {
2486
-		case CS5:  return JDATABITS_5;
2487
-		case CS6:  return JDATABITS_6;
2488
-		case CS7:  return JDATABITS_7;
2489
-		case CS8:  return JDATABITS_8;
2490
-		default:  return(-1);
2491
+		case CS5:	return JDATABITS_5;
2492
+		case CS6:	return JDATABITS_6;
2493
+		case CS7:	return JDATABITS_7;
2494
+		case CS8:	return JDATABITS_8;
2495
+		default:	return(-1);
2496
 	}
2497
 }
2498
 /*----------------------------------------------------------
2499
 RXTXPort.nativeStaticGetParity
2500
 
2501
-   accept:      filename
2502
-   perform:     find the parity
2503
-   return:      return the parity
2504
-   exceptions:
2505
-   comments:    simple test for preopened ports
2506
+	accept:		filename
2507
+	perform:	find the parity
2508
+	return:		return the parity
2509
+	exceptions:
2510
+	comments:	simple test for preopened ports
2511
 ----------------------------------------------------------*/
2512
 JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetParity)( JNIEnv *env, jobject jobj, jstring jstr )
2513
 {
2514
@@ -2801,7 +2886,7 @@
2515
 	struct termios ttyset;
2516
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2517
 
2518
-	ENTER( "RXTXPort:nativeStaticGetParity" );
2519
+	report( "Entering - RXTXPort:nativeStaticGetParity\n" );
2520
 	if( !fd )
2521
 	{
2522
 		/* Exception? FIXME */
2523
@@ -2824,17 +2909,17 @@
2524
 		case PARENB | PARODD | CMSPAR: return JPARITY_MARK;
2525
 		case PARENB | CMSPAR: return JPARITY_SPACE;
2526
 #endif /* CMSPAR */
2527
-		default:  return(-1);
2528
+		default:	return(-1);
2529
 	}
2530
 }
2531
 /*----------------------------------------------------------
2532
 RXTXPort.nativeStaticGetStopBits
2533
 
2534
-   accept:      filename
2535
-   perform:     find the stop bits
2536
-   return:      return the stop bits
2537
-   exceptions:
2538
-   comments:    simple test for preopened ports
2539
+	accept:		filename
2540
+	perform:	find the stop bits
2541
+	return:		return the stop bits
2542
+	exceptions:
2543
+	comments:	simple test for preopened ports
2544
 ----------------------------------------------------------*/
2545
 JNIEXPORT jint JNICALL RXTXPort(nativeStaticGetStopBits)( JNIEnv *env, jobject jobj, jstring jstr )
2546
 {
2547
@@ -2843,7 +2928,7 @@
2548
 	struct termios ttyset;
2549
 	(*env)->ReleaseStringUTFChars( env, jstr, filename );
2550
 
2551
-	ENTER( "RXTXPort:nativeStaticGetStopBits" );
2552
+	report( "Entering - RXTXPort:nativeStaticGetStopBits\n" );
2553
 	if( !fd )
2554
 	{
2555
 		/* Exception? FIXME */
2556
@@ -2872,46 +2957,46 @@
2557
 /*----------------------------------------------------------
2558
 RXTXPort.nativeGetParityErrorChar
2559
 
2560
-   accept:      -
2561
-   perform:     check the ParityErrorChar
2562
-   return:      The ParityErrorChar as an jbyte.
2563
-   exceptions:  UnsupportedCommOperationException if not implemented
2564
-   comments:    It appears the Parity char is usually \0.  The windows
2565
-		API allows for this to be changed.  I cant find may
2566
-		examples of this being done.  Maybe for a reason.
2567
-
2568
-		Use a direct call to the termios file until we find a
2569
-		solution.
2570
+	accept:	-
2571
+	perform:	check the ParityErrorChar
2572
+	return:		The ParityErrorChar as an jbyte.
2573
+	exceptions:	UnsupportedCommOperationException if not implemented
2574
+	comments:	It appears the Parity char is usually \0.  The windows
2575
+				API allows for this to be changed.  I cant find may
2576
+				examples of this being done.  Maybe for a reason.
2577
+				
2578
+				Use a direct call to the termios file until we find a
2579
+				solution.
2580
 ----------------------------------------------------------*/
2581
 JNIEXPORT jbyte JNICALL RXTXPort(nativeGetParityErrorChar)( JNIEnv *env,
2582
 	jobject jobj )
2583
 {
2584
 	unsigned int result = 0;
2585
 
2586
-	ENTER( "nativeGetParityErrorChar" );
2587
+	report( "Entering - nativeGetParityErrorChar\n" );
2588
 #ifdef WIN32
2589
 	result = ( jbyte ) termiosGetParityErrorChar(
2590
 			get_java_var(env, jobj, "fd", "I" ) );
2591
 #else
2592
 	/*
2593
-	   arg!  I cant find a way to change it from \0 in Linux.  I think
2594
-		   the frame and parity error characters are hardcoded.
2595
+		arg!  I cant find a way to change it from \0 in Linux.  I think
2596
+			the frame and parity error characters are hardcoded.
2597
 	*/
2598
 		result = ( jint ) '\0';
2599
 
2600
 #endif /* WIN32 */
2601
-	LEAVE( "nativeGetParityErrorChar" );
2602
+	report( "Leaving - nativeGetParityErrorChar\n" );
2603
 	return( ( jbyte ) result );
2604
 }
2605
 
2606
 /*----------------------------------------------------------
2607
 RXTXPort.nativeGetEndOfInputChar
2608
 
2609
-   accept:      -
2610
-   perform:     check the EndOf InputChar
2611
-   return:      the EndOfInputChar as an jbyte.  -1 on error
2612
-   exceptions:  UnsupportedCommOperationException if not implemented
2613
-   comments:
2614
+	accept:		-
2615
+	perform:	check the EndOf InputChar
2616
+	return:		the EndOfInputChar as an jbyte.  -1 on error
2617
+	exceptions:	UnsupportedCommOperationException if not implemented
2618
+	comments:
2619
 ----------------------------------------------------------*/
2620
 JNIEXPORT jbyte JNICALL RXTXPort(nativeGetEndOfInputChar)( JNIEnv *env,
2621
 	jobject jobj )
2622
@@ -2919,12 +3004,12 @@
2623
 	int fd = get_java_var( env, jobj,"fd","I" );
2624
 	struct termios ttyset;
2625
 
2626
-	ENTER( "nativeGetEndOfInputChar" );
2627
+	report( "Entering - nativeGetEndOfInputChar\n" );
2628
 	if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
2629
-	LEAVE( "nativeGetEndOfInputChar" );
2630
+	report( "Leaving - nativeGetEndOfInputChar" );
2631
 	return( (jbyte) ttyset.c_cc[VEOF] );
2632
 fail:
2633
-	LEAVE( "nativeGetEndOfInputChar" );
2634
+	report( "Leaving - nativeGetEndOfInputChar\n" );
2635
 	report( "nativeGetEndOfInputChar failed\n" );
2636
 	return( ( jbyte ) -1 );
2637
 }
2638
@@ -2932,16 +3017,16 @@
2639
 /*----------------------------------------------------------
2640
 RXTXPort.nativeSetParityErrorChar
2641
 
2642
-   accept:      the ParityArrorCharacter as an int.
2643
-   perform:     Set the ParityErrorChar
2644
-   return:      JNI_TRUE on success
2645
-   exceptions:  UnsupportedCommOperationException if not implemented
2646
-   comments:    It appears the Parity char is usually \0.  The windows
2647
-		API allows for this to be changed.  I cant find may
2648
-		examples of this being done.  Maybe for a reason.
2649
+	accept:		the ParityArrorCharacter as an int.
2650
+	perform:	Set the ParityErrorChar
2651
+	return:		JNI_TRUE on success
2652
+	exceptions:	UnsupportedCommOperationException if not implemented
2653
+	comments:	It appears the Parity char is usually \0.  The windows
2654
+				API allows for this to be changed.  I cant find may
2655
+				examples of this being done.  Maybe for a reason.
2656
 
2657
-		Use a direct call to the termios file until we find a
2658
-		solution.
2659
+				Use a direct call to the termios file until we find a
2660
+				solution.
2661
 ----------------------------------------------------------*/
2662
 JNIEXPORT jboolean JNICALL RXTXPort(nativeSetParityErrorChar)( JNIEnv *env,
2663
 	jobject jobj, jbyte value )
2664
@@ -2949,21 +3034,21 @@
2665
 
2666
 #ifdef WIN32
2667
 		int fd = get_java_var( env, jobj,"fd","I" );
2668
-		ENTER( "nativeSetParityErrorChar" );
2669
+		report( "Entering - nativeSetParityErrorChar\n" );
2670
 		termiosSetParityError( fd, ( char ) value );
2671
-		LEAVE( "nativeSetParityErrorChar" );
2672
+		report( "Leaving - nativeSetParityErrorChar\n" );
2673
 		return( JNI_TRUE );
2674
 #else
2675
-		ENTER( "nativeSetParityErrorChar" );
2676
+		report( "Entering - nativeSetParityErrorChar\n" );
2677
 	/*
2678
-	   arg!  I cant find a way to change it from \0 in Linux.  I think
2679
-	   the frame and parity error characters are hardcoded.
2680
+		arg!  I cant find a way to change it from \0 in Linux.  I think
2681
+		the frame and parity error characters are hardcoded.
2682
 	*/
2683
 
2684
 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
2685
 		"Not implemented... yet",
2686
 		strerror( errno ) );
2687
-	LEAVE( "nativeSetParityErrorChar" );
2688
+	report( "Leaving - nativeSetParityErrorChar\n" );
2689
 	return( JNI_FALSE );
2690
 #endif /* WIN32 */
2691
 }
2692
@@ -2971,17 +3056,17 @@
2693
 /*----------------------------------------------------------
2694
 RXTXPort.nativeSetEndOfInputChar
2695
 
2696
-   accept:      The EndOfInputChar as an int
2697
-   perform:     set the EndOfInputChar
2698
-   return:      JNI_TRUE on success
2699
-   exceptions:  UnsupportedCommOperationException if not implemented
2700
-   comments:    This may cause troubles on Windows.
2701
-		Lets give it a shot and see what happens.
2702
+	accept:		The EndOfInputChar as an int
2703
+	perform:	set the EndOfInputChar
2704
+	return:		JNI_TRUE on success
2705
+	exceptions:	UnsupportedCommOperationException if not implemented
2706
+	comments:	This may cause troubles on Windows.
2707
+				Lets give it a shot and see what happens.
2708
 
2709
-		See termios.c for the windows bits.
2710
+				See termios.c for the windows bits.
2711
 
2712
-		EofChar = val;
2713
-		fBinary = false;  winapi docs say always use true. ?
2714
+				EofChar = val;
2715
+				fBinary = false;  winapi docs say always use true. ?
2716
 ----------------------------------------------------------*/
2717
 JNIEXPORT jboolean JNICALL RXTXPort(nativeSetEndOfInputChar)( JNIEnv *env,
2718
 	jobject jobj, jbyte value )
2719
@@ -2989,17 +3074,17 @@
2720
 	int fd = get_java_var( env, jobj,"fd","I" );
2721
 	struct termios ttyset;
2722
 
2723
-	ENTER( "nativeSetEndOfInputChar" );
2724
+	report( "Entering - nativeSetEndOfInputChar\n" );
2725
 	if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
2726
 	ttyset.c_cc[VEOF] = ( char ) value;
2727
 	if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail;
2728
-	LEAVE( "nativeSetEndOfInputChar" );
2729
+	report( "Leaving - nativeSetEndOfInputChar\n" );
2730
 	return( JNI_TRUE );
2731
 fail:
2732
 	throw_java_exception( env, IO_EXCEPTION, "nativeSetEndOfInputChar",
2733
 		strerror( errno ) );
2734
 	report( "nativeSetEndOfInputChar failed\n" );
2735
-	LEAVE( "nativeSetEndOfInputChar" );
2736
+	report( "Leaving - nativeSetEndOfInputChar\n" );
2737
 	return( JNI_FALSE );
2738
 }
2739
 
2740
@@ -3025,28 +3110,31 @@
2741
 /*----------------------------------------------------------
2742
 read_byte_array
2743
 
2744
-   accept:      int                fd   file descriptor to read from
2745
-                unsigned char *buffer   buffer to read data into
2746
-                int            length   number of bytes to read
2747
-		int           timeout   milliseconds to wait before returning
2748
-   perform:     read bytes from the port into a buffer
2749
-   return:      status of read
2750
-                -1 fail (IOException)
2751
-                 0 timeout
2752
-                >0 number of bytes read
2753
-   comments:    According to the Communications API spec, a receive threshold
2754
-                of 1 is the same as having the threshold disabled.
2755
-
2756
-		The nuts and bolts are documented in
2757
-		NativeEnableReceiveTimeoutThreshold()
2758
-----------------------------------------------------------*/
2759
-
2760
-int read_byte_array( JNIEnv *env,
2761
-                     jobject *jobj,
2762
-                     int fd,
2763
-                     unsigned char *buffer,
2764
-                     int length,
2765
-                     int timeout )
2766
+	accept:		int 			fd		file descriptor to read from
2767
+				unsigned char 	*buffer	buffer to read data into
2768
+				int				length	number of bytes to read
2769
+				int				timeout	milliseconds to wait
2770
+	perform:	read bytes from the port into a buffer
2771
+	return:		status of read
2772
+				-1 fail (IOException)
2773
+				0 timeout
2774
+				>0 number of bytes read
2775
+	comments:	According to the Communications API spec, a receive
2776
+				threshold of 1 is the same as having the threshold
2777
+				disabled.
2778
+
2779
+				The nuts and bolts are documented in
2780
+				NativeEnableReceiveTimeoutThreshold()
2781
+----------------------------------------------------------*/
2782
+
2783
+int read_byte_array( 
2784
+	JNIEnv *env,
2785
+	jobject *jobj,
2786
+	int fd,
2787
+	unsigned char *buffer,
2788
+	int length,
2789
+	int timeout
2790
+)
2791
 {
2792
 	int ret, left, bytes = 0;
2793
 	long timeLeft, now = 0, start = 0;
2794
@@ -3062,7 +3150,8 @@
2795
 	flag = eis->eventflags[SPE_DATA_AVAILABLE];
2796
 	eis->eventflags[SPE_DATA_AVAILABLE] = 0;
2797
 /*
2798
-	ENTER( "read_byte_array" );
2799
+	report( "Entering - read_byte_array\n" );
2800
+	memset(&message[0], 0, sizeof(message));
2801
 	sprintf(msg, "read_byte_array requests %i\n", length);
2802
 	report( msg );
2803
 */
2804
@@ -3102,7 +3191,7 @@
2805
 #endif /* WIN32 */
2806
 		if (ret == -1){
2807
 			report( "read_byte_array: select returned -1\n" );
2808
-			LEAVE( "read_byte_array" );
2809
+			report( "Leaving - read_byte_array\n" );
2810
 			eis->eventflags[SPE_DATA_AVAILABLE] = flag;
2811
 			return -1;
2812
 		}
2813
@@ -3111,7 +3200,7 @@
2814
 			if ((ret = READ( fd, buffer + bytes, left )) < 0 ){
2815
 				if (errno != EINTR && errno != EAGAIN){
2816
 					report( "read_byte_array: read returned -1\n" );
2817
-					LEAVE( "read_byte_array" );
2818
+					report( "Leaving - read_byte_array\n" );
2819
 					eis->eventflags[SPE_DATA_AVAILABLE] = flag;
2820
 					return -1;
2821
 				}
2822
@@ -3146,9 +3235,10 @@
2823
 			"No data available" );
2824
 	}
2825
 
2826
+	memset(&message[0], 0, sizeof(message));
2827
 	sprintf(msg, "read_byte_array returns %i\n", bytes);
2828
 	report( msg );
2829
-	LEAVE( "read_byte_array" );
2830
+	report( "Leaving - read_byte_array\n" );
2831
 	report_time_end();
2832
 */
2833
 	eis->eventflags[SPE_DATA_AVAILABLE] = flag;
2834
@@ -3168,7 +3258,8 @@
2835
 	char msg[80];
2836
 
2837
 	report_time_start();
2838
-	ENTER( "read_byte_array" );
2839
+	report( "Entering - read_byte_array\n" );
2840
+	memset(&message[0], 0, sizeof(message));
2841
 	sprintf(msg, "read_byte_array requests %i\n", length);
2842
 	report( msg );
2843
 	left = length;
2844
@@ -3186,15 +3277,16 @@
2845
 			if (errno == EINTR)
2846
 				goto RETRY;
2847
 			report( "read_byte_array: read returned -1\n" );
2848
-			LEAVE( "read_byte_array" );
2849
+			report( "Leaving - read_byte_array\n" );
2850
 			return -1;
2851
 		}
2852
 		bytes += ret;
2853
 		left -= ret;
2854
 	}
2855
+	memset(&message[0], 0, sizeof(message));
2856
 	sprintf(msg, "read_byte_array returns %i\n", bytes);
2857
 	report( msg );
2858
-	LEAVE( "read_byte_array" );
2859
+	report( "Leaving - read_byte_array\n" );
2860
 	report_time_end();
2861
 	return bytes;
2862
 }
2863
@@ -3217,7 +3309,7 @@
2864
 	struct timeval *psleep=&sleep;
2865
 #endif /* WIN32 */
2866
 
2867
-	ENTER( "read_byte_array" );
2868
+	report( "Entering - read_byte_array\n" );
2869
 	left = length;
2870
 	FD_ZERO( &rfds );
2871
 	FD_SET( fd, &rfds );
2872
@@ -3228,10 +3320,10 @@
2873
 	}
2874
 	while( bytes < length )
2875
 	{
2876
-         /* FIXME: In Linux, select updates the timeout automatically, so
2877
-            other OSes will need to update it manually if they want to have
2878
-            the same behavior.  For those OSes, timeouts will occur after no
2879
-            data AT ALL is received for the timeout duration.  No big deal. */
2880
+		/* FIXME: In Linux, select updates the timeout automatically, so
2881
+		other OSes will need to update it manually if they want to have
2882
+		the same behavior.  For those OSes, timeouts will occur after no
2883
+		data AT ALL is received for the timeout duration.  No big deal. */
2884
 #ifndef WIN32
2885
 		do {
2886
 			if( timeout == 0 ) psleep = NULL;
2887
@@ -3239,9 +3331,9 @@
2888
 		}  while (ret < 0 && errno==EINTR);
2889
 #else
2890
 		/*
2891
-		    the select() needs some work before the above will
2892
-		    work on win32.  The select code cannot be accessed
2893
-		    from both the Monitor Thread and the Reading Thread.
2894
+			the select() needs some work before the above will
2895
+			work on win32.  The select code cannot be accessed
2896
+			from both the Monitor Thread and the Reading Thread.
2897
 
2898
 		*/
2899
 		ret = RXTXPort(nativeavailable)( env, *jobj );
2900
@@ -3249,44 +3341,44 @@
2901
 		if( ret == 0 )
2902
 		{
2903
 			report( "read_byte_array: select returned 0\n" );
2904
-			LEAVE( "read_byte_array" );
2905
+			report( "Leaving - read_byte_array\n" );
2906
 			break;
2907
 		}
2908
 		if( ret < 0 )
2909
 		{
2910
 			report( "read_byte_array: select returned -1\n" );
2911
-			LEAVE( "read_byte_array" );
2912
+			report( "Leaving - read_byte_array\n" );
2913
 			return -1;
2914
 		}
2915
 		ret = READ( fd, buffer + bytes, left );
2916
 		if( ret == 0 )
2917
 		{
2918
 			report( "read_byte_array: read returned 0 bytes\n" );
2919
-			LEAVE( "read_byte_array" );
2920
+			report( "Leaving - read_byte_array\n" );
2921
 			break;
2922
 		}
2923
 		else if( ret < 0 )
2924
 		{
2925
 			report( "read_byte_array: read returned -1\n" );
2926
-			LEAVE( "read_byte_array" );
2927
+			report( "Leaving - read_byte_array\n" );
2928
 			return -1;
2929
 		}
2930
 		bytes += ret;
2931
 		left -= ret;
2932
 	}
2933
-	LEAVE( "read_byte_array" );
2934
+	report( "Leaving - read_byte_array\n" );
2935
 	return bytes;
2936
 }
2937
 #endif /* asdf */
2938
 
2939
 /*----------------------------------------------------------
2940
 NativeEnableReceiveTimeoutThreshold
2941
-   accept:      int  threshold, int vtime,int buffer
2942
-   perform:     Set c_cc->VMIN to threshold and c_cc=>VTIME to vtime
2943
-   return:      void
2944
-   exceptions:  IOException
2945
-   comments:    This is actually all handled in read with select in
2946
-                canonical input mode.
2947
+	accept:		int  threshold, int vtime,int buffer
2948
+	perform:	Set c_cc->VMIN to threshold and c_cc=>VTIME to vtime
2949
+	return:		void
2950
+	exceptions:	IOException
2951
+	comments:	This is actually all handled in read with select in
2952
+				canonical input mode.
2953
 ----------------------------------------------------------*/
2954
 JNIEXPORT void JNICALL RXTXPort(NativeEnableReceiveTimeoutThreshold)(
2955
 	JNIEnv *env, jobject jobj, jint vtime, jint threshold, jint buffer)
2956
@@ -3305,16 +3397,16 @@
2957
 		timeout = vtime;
2958
 	}
2959
 
2960
-	ENTER( "RXTXPort:NativeEnableRecieveTimeoutThreshold" );
2961
+	report( "Entering - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" );
2962
 	if( tcgetattr( fd, &ttyset ) < 0 ) goto fail;
2963
 	ttyset.c_cc[ VMIN ] = threshold;
2964
 	ttyset.c_cc[ VTIME ] = timeout/100;
2965
 	if( tcsetattr( fd, TCSANOW, &ttyset ) < 0 ) goto fail;
2966
 
2967
-	LEAVE( "RXTXPort:NativeEnableRecieveTimeoutThreshold" );
2968
+	report( "Leaving - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" );
2969
 	return;
2970
 fail:
2971
-	LEAVE( "RXTXPort:NativeEnableRecieveTimeoutThreshold" );
2972
+	report( "Leaving - RXTXPort:NativeEnableRecieveTimeoutThreshold\n" );
2973
 	throw_java_exception( env, IO_EXCEPTION, "TimeoutThreshold",
2974
 		strerror( errno ) );
2975
 	return;
2976
@@ -3323,16 +3415,16 @@
2977
 /*----------------------------------------------------------
2978
 RXTXPort.readByte
2979
 
2980
-   accept:      none
2981
-   perform:     Read a single byte from the port.  Block unless an exeption
2982
-	        is thrown, or end of stream.
2983
-   return:      The byte read
2984
-   exceptions:  IOException
2985
-   comments:
2986
+	accept:		none
2987
+	perform:	Read a single byte from the port.  Block unless an exeption
2988
+				is thrown, or end of stream.
2989
+	return:		The byte read
2990
+	exceptions:	IOException
2991
+	comments:
2992
 
2993
-On Fri, 30 Aug 2002, Bill Smith wrote:
2994
+	On Fri, 30 Aug 2002, Bill Smith wrote:
2995
 
2996
-I agree, the documentation isn't the best. No surprises there.
2997
+	I agree, the documentation isn't the best. No surprises there.
2998
 
2999
 I did do a test using the sun/win32 comm driver with read() and retrieve
3000
 timeout enabled. It blocked until the timeout expired, then returned a -1.
3001
@@ -3350,32 +3442,32 @@
3002
 > I have a couple of questions/comments.
3003
 >
3004
 > 1) I noticed in the thread last night and in the code changes this morning that you
3005
->    now have readByte() (which is called from the input stream read(), to block
3006
->    forever. I pulled the following info from the javax.comm doc for the CommPort class in
3007
->    getInputStream().
3008
+>	now have readByte() (which is called from the input stream read(), to block
3009
+>	forever. I pulled the following info from the javax.comm doc for the CommPort class in
3010
+>	getInputStream().
3011
 >
3012
->    The way I interpret that is that read() just like read(byte[]), and read(byte[], int, int),
3013
->    show only block indefinitely if timeout is disabled. The sun implementation for win32 (as
3014
->    well as the one we have for vxworks) returns a -1 when it times out.
3015
+>	The way I interpret that is that read() just like read(byte[]), and read(byte[], int, int),
3016
+>	show only block indefinitely if timeout is disabled. The sun implementation for win32 (as
3017
+>	well as the one we have for vxworks) returns a -1 when it times out.
3018
 >
3019
 
3020
 Doing what Sun does is going to the least hassle.  The documentation was a
3021
 little unclear to me.  I assume this is the CommPort.getInputStream
3022
 comment that you mention
3023
 
3024
-        The read behaviour of the input stream returned by getInputStream
3025
-        depends on combination of the threshold and timeout values. The
3026
-        possible behaviours are described in the table below: ...
3027
+	 The read behaviour of the input stream returned by getInputStream
3028
+	 depends on combination of the threshold and timeout values. The
3029
+	 possible behaviours are described in the table below: ...
3030
 
3031
 But InputStream is where read(byte) is documented
3032
 http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read()
3033
 
3034
-        Reads the next byte of data from the input stream. The value byte
3035
-        is returned as an int in the range 0 to 255. If no byte is
3036
-        available because the end of the stream has been reached, the value
3037
-        -1 is returned. This method blocks until input data is
3038
-        available, the end of the stream is detected, or an exception is
3039
-        thrown
3040
+	 Reads the next byte of data from the input stream. The value byte
3041
+	 is returned as an int in the range 0 to 255. If no byte is
3042
+	 available because the end of the stream has been reached, the value
3043
+	 -1 is returned. This method blocks until input data is
3044
+	 available, the end of the stream is detected, or an exception is
3045
+	 thrown
3046
 
3047
 If you are sure commapi is doing a timeout and returning -1, I can change
3048
 it back and document the issue.
3049
@@ -3383,20 +3475,20 @@
3050
 Because I often grep my own mailbox for details, I'm going to add
3051
 these two comments also:
3052
 
3053
-        public int read(byte[] b)
3054
+	 public int read(byte[] b)
3055
 )
3056
 http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read(byte[])
3057
 
3058
-        Reads some number of bytes from the input stream and stores them
3059
-        into the buffer array b. The number of bytes actually read is
3060
-        returned as an integer. This method blocks until input data is
3061
-        available, end of file is detected, or an exception is thrown.
3062
-
3063
-        If b is null, a NullPointerException is thrown. If the length of b
3064
-        is zero, then no bytes are read and 0 is returned; otherwise,
3065
-        there is an attempt to read at least one byte. If no byte is
3066
-        available because the stream is at end of file, the value -1 is
3067
-        returned; otherwise, at least one byte is read and stored into b.
3068
+	 Reads some number of bytes from the input stream and stores them
3069
+	 into the buffer array b. The number of bytes actually read is
3070
+	 returned as an integer. This method blocks until input data is
3071
+	 available, end of file is detected, or an exception is thrown.
3072
+
3073
+	 If b is null, a NullPointerException is thrown. If the length of b
3074
+	 is zero, then no bytes are read and 0 is returned; otherwise,
3075
+	 there is an attempt to read at least one byte. If no byte is
3076
+	 available because the stream is at end of file, the value -1 is
3077
+	 returned; otherwise, at least one byte is read and stored into b.
3078
 
3079
 So read(byte[] b) is documented as blocking for the first byte.
3080
 
3081
@@ -3404,10 +3496,10 @@
3082
 http://java.sun.com/j2se/1.3/docs/api/java/io/InputStream.html#read(byte[],
3083
 int, int)
3084
 
3085
-        Reads up to len bytes of data from the input stream into an array of
3086
-        bytes. An attempt is made to read as many as len bytes, but a
3087
-        smaller number may be read, possibly zero. The number of bytes
3088
-        actually read is returned as an integer.
3089
+	 Reads up to len bytes of data from the input stream into an array of
3090
+	 bytes. An attempt is made to read as many as len bytes, but a
3091
+	 smaller number may be read, possibly zero. The number of bytes
3092
+	 actually read is returned as an integer.
3093
 
3094
 Which makes sense with the timeout documentation.
3095
 
3096
@@ -3434,18 +3526,18 @@
3097
 > described in the table below:
3098
 >
3099
 >
3100
->    Threshold             Timeout        Read Buffer    Read Behaviour
3101
-> State     Value       State     Value       Size
3102
+>	Threshold		Timeout	 Read Buffer	Read Behaviour
3103
+> State	Value	State	Value	Size
3104
 >
3105
 -----------------------------------------------------------------------------------
3106
-> disabled    -         disabled    -       n bytes      block until any data is available
3107
+> disabled	-		disabled	-	n bytes	block until any data is available
3108
 >
3109
-> enabled   m bytes     disabled    -       n bytes      block until min(m,n) bytes are available
3110
+> enabled	m bytes	disabled	-	n bytes	block until min(m,n) bytes are available
3111
 >
3112
-> disabled    -         enabled   x ms      n bytes      block for x ms or
3113
+> disabled	-		enabled	x ms	n bytes	block for x ms or
3114
 until any data is available
3115
 >
3116
-> enabled   m bytes     enabled   x ms      n bytes      block for x ms or
3117
+> enabled	m bytes	enabled	x ms	n bytes	block for x ms or
3118
 until min(m,n) bytes are available
3119
 >
3120
 > Returns: InputStream object that can be used to read from the port
3121
@@ -3464,18 +3556,19 @@
3122
 	/* char msg[80]; */
3123
 
3124
 /*
3125
-	ENTER( "RXTXPort:readByte" );
3126
+	report( "Entering - RXTXPort:readByte" );
3127
 	report_time_start( );
3128
 */
3129
 	bytes = read_byte_array( env, &jobj, fd, buffer, 1, timeout );
3130
 	if( bytes < 0 ) {
3131
-		LEAVE( "RXTXPort:readByte" );
3132
+		report( "Leaving - RXTXPort:readByte\n" );
3133
 		throw_java_exception( env, IO_EXCEPTION, "readByte",
3134
 			strerror( errno ) );
3135
 		return -1;
3136
 	}
3137
 /*
3138
-	LEAVE( "RXTXPort:readByte" );
3139
+	report( "Leaving - RXTXPort:readByte\n" );
3140
+	memset(&message[0], 0, sizeof(message));
3141
 	sprintf( msg, "readByte return(%i)\n", bytes ? buffer[ 0 ] : -1 );
3142
 	report( msg );
3143
 	report_time_end( );
3144
@@ -3486,14 +3579,14 @@
3145
 /*----------------------------------------------------------
3146
 RXTXPort.readArray
3147
 
3148
-   accept:       offset (offset to start storing data in the jbarray) and
3149
-                 Length (bytes to read)
3150
-   perform:      read bytes from the port into a byte array
3151
-   return:       bytes read on success
3152
-                 0 on read timeout
3153
-   exceptions:   IOException
3154
-   comments:     throws ArrayIndexOutOfBoundsException if asked to
3155
-                 read more than SSIZE_MAX bytes
3156
+	accept:		offset (offset to start storing data in the jbarray) and
3157
+		*		Length (bytes to read)
3158
+	perform:	read bytes from the port into a byte array
3159
+	return:		bytes read on success
3160
+		*		0 on read timeout
3161
+	exceptions:	IOException
3162
+	comments:	throws ArrayIndexOutOfBoundsException if asked to
3163
+		*		read more than SSIZE_MAX bytes
3164
 ----------------------------------------------------------*/
3165
 JNIEXPORT jint JNICALL RXTXPort(readArray)( JNIEnv *env,
3166
 	jobject jobj, jbyteArray jbarray, jint offset, jint length )
3167
@@ -3505,12 +3598,12 @@
3168
 	int timeout = get_java_var( env, jobj, "timeout", "I" );
3169
 
3170
 /*
3171
-	ENTER( "readArray" );
3172
+	report( "Entering - readArray\n" );
3173
 	report_time_start( );
3174
 */
3175
 	if( (size_t) length > SSIZE_MAX || (size_t) length < 0 ) {
3176
-		report( "RXTXPort:readArray length > SSIZE_MAX" );
3177
-		LEAVE( "RXTXPort:readArray" );
3178
+		report( "RXTXPort:readArray length > SSIZE_MAX\n" );
3179
+		report( "Leaving - RXTXPort:readArray\n" );
3180
 		throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS,
3181
 			"readArray", "Invalid length" );
3182
 		return -1;
3183
@@ -3519,17 +3612,18 @@
3184
 	bytes = read_byte_array( env, &jobj, fd, (unsigned char *)(body+offset), length, timeout );/* dima */
3185
 	(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 );
3186
 	if( bytes < 0 ) {
3187
-		report( "RXTXPort:readArray bytes < 0" );
3188
-		LEAVE( "RXTXPort:readArray" );
3189
+		report( "RXTXPort:readArray bytes < 0\n" );
3190
+		report( "Leaving - RXTXPort:readArray\n" );
3191
 		throw_java_exception( env, IO_EXCEPTION, "readArray",
3192
 			strerror( errno ) );
3193
 		return -1;
3194
 	}
3195
 /*
3196
+	memset(&message[0], 0, sizeof(message));
3197
 	sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes);
3198
 	report( msg );
3199
 	report_time_end( );
3200
-	LEAVE( "RXTXPort:readArray" );
3201
+	report( "Leaving - RXTXPort:readArray\n" );
3202
 */
3203
 	return (bytes);
3204
 }
3205
@@ -3537,11 +3631,11 @@
3206
 /*----------------------------------------------------------
3207
 RXTXPort.nativeClearCommInput
3208
 
3209
-   accept:       none
3210
-   perform:      try to clear the input.
3211
-   return:       true on success, false on error
3212
-   exceptions:   none
3213
-   comments:     This is an extension to commapi.
3214
+	accept:		none
3215
+	perform:	try to clear the input.
3216
+	return:		true on success, false on error
3217
+	exceptions:	none
3218
+	comments:	This is an extension to commapi.
3219
 ----------------------------------------------------------*/
3220
 JNIEXPORT jboolean JNICALL RXTXPort(nativeClearCommInput)( JNIEnv *env,
3221
 	jobject jobj )
3222
@@ -3554,18 +3648,18 @@
3223
 /*----------------------------------------------------------
3224
 RXTXPort.readTerminatedArray
3225
 
3226
-   accept:       offset (offset to start storing data in the jbarray) and
3227
-                 Length (bytes to read).  Terminator - 2 bytes that we
3228
-		 dont read past
3229
-   perform:      read bytes from the port into a byte array
3230
-   return:       bytes read on success
3231
-                 0 on read timeout
3232
-   exceptions:   IOException
3233
-   comments:     throws ArrayIndexOutOfBoundsException if asked to
3234
-                 read more than SSIZE_MAX bytes
3235
-		 timeout is not properly handled
3236
+	accept:		offset (offset to start storing data in the jbarray) and
3237
+				Length (bytes to read).  Terminator - 2 bytes that we
3238
+				dont read past
3239
+	perform:	read bytes from the port into a byte array
3240
+	return:		bytes read on success
3241
+				0 on read timeout
3242
+	exceptions:	IOException
3243
+	comments:	throws ArrayIndexOutOfBoundsException if asked to
3244
+				read more than SSIZE_MAX bytes
3245
+				timeout is not properly handled
3246
 
3247
-		 This is an extension to commapi.
3248
+				This is an extension to commapi.
3249
 ----------------------------------------------------------*/
3250
 JNIEXPORT jint JNICALL RXTXPort(readTerminatedArray)( JNIEnv *env,
3251
 	jobject jobj, jbyteArray jbarray, jint offset, jint length,
3252
@@ -3578,12 +3672,12 @@
3253
 	int timeout = get_java_var( env, jobj, "timeout", "I" );
3254
 
3255
 /*
3256
-	ENTER( "readArray" );
3257
+	report( "Entering - readArray\n" );
3258
 	report_time_start( );
3259
 */
3260
 	if( (size_t) length > SSIZE_MAX || (size_t) length < 0 ) {
3261
-		report( "RXTXPort:readArray length > SSIZE_MAX" );
3262
-		LEAVE( "RXTXPort:readArray" );
3263
+		report( "RXTXPort:readArray length > SSIZE_MAX\n" );
3264
+		report( "Leaving - RXTXPort:readArray\n" );
3265
 		throw_java_exception( env, ARRAY_INDEX_OUT_OF_BOUNDS,
3266
 			"readArray", "Invalid length" );
3267
 		return -1;
3268
@@ -3595,8 +3689,8 @@
3269
 		bytes = read_byte_array( env, &jobj, fd, (unsigned char *)(body+offset + total ), 1 , timeout );/* dima */
3270
 		total += bytes;
3271
 		if( bytes < 0 ) {
3272
-			report( "RXTXPort:readArray bytes < 0" );
3273
-			LEAVE( "RXTXPort:readArray" );
3274
+			report( "RXTXPort:readArray bytes < 0\n" );
3275
+			report( "Leaving - RXTXPort:readArray\n" );
3276
 			throw_java_exception( env, IO_EXCEPTION, "readArray",
3277
 				strerror( errno ) );
3278
 			return -1;
3279
@@ -3612,10 +3706,11 @@
3280
 	} while ( bytes > 0 && total < length );
3281
 	(*env)->ReleaseByteArrayElements( env, jbarray, body, 0 );
3282
 /*
3283
+	memset(&message[0], 0, sizeof(message));
3284
 	sprintf( msg, "RXTXPort:readArray: %i %i\n", (int) length, bytes);
3285
 	report( msg );
3286
 	report_time_end( );
3287
-	LEAVE( "RXTXPort:readArray" );
3288
+	report( "Leaving - RXTXPort:readArray\n" );
3289
 */
3290
 	return (bytes);
3291
 }
3292
@@ -3623,11 +3718,11 @@
3293
 /*----------------------------------------------------------
3294
 RXTXPort.nativeavailable
3295
 
3296
-   accept:      none
3297
-   perform:     find out the number of bytes available for reading
3298
-   return:      available bytes
3299
-                -1 on error
3300
-   exceptions:  none
3301
+	accept:		none
3302
+	perform:	find out the number of bytes available for reading
3303
+	return:		available bytes
3304
+				-1 on error
3305
+	exceptions:	none
3306
 ----------------------------------------------------------*/
3307
 JNIEXPORT jint JNICALL RXTXPort(nativeavailable)( JNIEnv *env,
3308
 	jobject jobj )
3309
@@ -3638,13 +3733,13 @@
3310
 	char message[80];
3311
 
3312
 
3313
-	ENTER( "RXTXPort:nativeavailable" );
3314
+	report( "Entering - RXTXPort:nativeavailable\n" );
3315
 
3316
-    On SCO OpenServer FIONREAD always fails for serial devices,
3317
-    so try ioctl FIORDCHK instead; will only tell us whether
3318
-    bytes are available, not how many, but better than nothing.
3319
+	On SCO OpenServer FIONREAD always fails for serial devices,
3320
+	so try ioctl FIORDCHK instead; will only tell us whether
3321
+	bytes are available, not how many, but better than nothing.
3322
 
3323
-    This turns out to be true on Solaris also.  taj.
3324
+	This turns out to be true on Solaris also.  taj.
3325
 */
3326
 #ifdef FIORDCHK  /* __unixware__ __sun__ probably others */
3327
 	result = ioctl(fd, FIORDCHK, 0);
3328
@@ -3658,22 +3753,24 @@
3329
 		goto fail;
3330
 	}
3331
 /*
3332
-	sprintf(message, "    nativeavailable: FIORDCHK result %d, \
3333
+	memset(&message[0], 0, sizeof(message));
3334
+	sprintf(message, "	nativeavailable: FIORDCHK result %d, \
3335
 		errno %d\n", result , result == -1 ? errno : 0);
3336
 	report_verbose( message );
3337
 	if( result )
3338
 	{
3339
-		sprintf(message, "    nativeavailable: FIORDCHK result %d, \
3340
+		memset(&message[0], 0, sizeof(message));
3341
+		sprintf(message, "	nativeavailable: FIORDCHK result %d, \
3342
 				errno %d\n", result , result == -1 ? errno : 0);
3343
 		report( message );
3344
 	}
3345
-	LEAVE( "RXTXPort:nativeavailable" );
3346
+	report( "Leaving - RXTXPort:nativeavailable\n" );
3347
 */
3348
 	return (jint)result;
3349
 fail:
3350
-	report("RXTXPort:nativeavailable:  ioctl() failed\n");
3351
+	report("RXTXPort:nativeavailable:	ioctl() failed\n");
3352
 /*
3353
-	LEAVE( "RXTXPort:nativeavailable" );
3354
+	report( "Leaving - RXTXPort:nativeavailable\n" );
3355
 */
3356
 	throw_java_exception( env, IO_EXCEPTION, "nativeavailable",
3357
 		strerror( errno ) );
3358
@@ -3683,17 +3780,17 @@
3359
 /*----------------------------------------------------------
3360
 RXTXPort.setflowcontrol
3361
 
3362
-   accept:      flowmode
3363
-	FLOWCONTROL_NONE        none
3364
-	FLOWCONTROL_RTSCTS_IN   hardware flow control
3365
-	FLOWCONTROL_RTSCTS_OUT         ""
3366
-	FLOWCONTROL_XONXOFF_IN  input software flow control
3367
-	FLOWCONTROL_XONXOFF_OUT output software flow control
3368
-   perform:     set flow control to flowmode
3369
-   return:      none
3370
-   exceptions:  UnsupportedCommOperationException
3371
-   comments:  there is no differentiation between input and output hardware
3372
-              flow control
3373
+	accept:		flowmode
3374
+				FLOWCONTROL_NONE	 none
3375
+				FLOWCONTROL_RTSCTS_IN	hardware flow control
3376
+				FLOWCONTROL_RTSCTS_OUT		""
3377
+				FLOWCONTROL_XONXOFF_IN  input software flow control
3378
+				FLOWCONTROL_XONXOFF_OUT output software flow control
3379
+	perform:	set flow control to flowmode
3380
+	return:		none
3381
+	exceptions:	UnsupportedCommOperationException
3382
+	comments:	there is no differentiation between input and output hardware
3383
+				flow control
3384
 ----------------------------------------------------------*/
3385
 JNIEXPORT void JNICALL RXTXPort(setflowcontrol)( JNIEnv *env,
3386
 	jobject jobj, jint flowmode )
3387
@@ -3701,7 +3798,7 @@
3388
 	struct termios ttyset;
3389
 	int fd = get_java_var( env, jobj,"fd","I" );
3390
 
3391
-	ENTER( "RXTXPort:setflowcontrol" );
3392
+	report( "Entering - RXTXPort:setflowcontrol\n" );
3393
 	if( tcgetattr( fd, &ttyset ) ) goto fail;
3394
 
3395
 	if ( flowmode & ( FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT ) )
3396
@@ -3726,10 +3823,10 @@
3397
 	else ttyset.c_iflag &= ~IXON;
3398
 /* TRENT */
3399
 	if( tcsetattr( fd, TCSANOW, &ttyset ) ) goto fail;
3400
-	LEAVE( "RXTXPort:setflowcontrol" );
3401
+	report( "Leaving - RXTXPort:setflowcontrol\n" );
3402
 	return;
3403
 fail:
3404
-	LEAVE( "RXTXPort:setflowcontrol" );
3405
+	report( "Leaving - RXTXPort:setflowcontrol\n" );
3406
 	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION, "",
3407
 		"flow control type not supported" );
3408
 	return;
3409
@@ -3738,30 +3835,32 @@
3410
 /*----------------------------------------------------------
3411
 unlock_monitor_thread
3412
 
3413
-   accept:      event_info_struct
3414
-   perform:     unlock the monitor thread so event notification can start.
3415
-   return:      none
3416
-   exceptions:  none
3417
-   comments:    Events can be missed otherwise.
3418
+	accept:		event_info_struct
3419
+	perform:	unlock the monitor thread so event notification can start.
3420
+	return:		none
3421
+	exceptions:	none
3422
+	comments:	Events can be missed otherwise.
3423
 ----------------------------------------------------------*/
3424
 
3425
 void unlock_monitor_thread( struct event_info_struct *eis )
3426
 {
3427
+	report("Entering - unlock_monitor_thread\n");
3428
 	JNIEnv *env = eis->env;
3429
 	jobject jobj = *(eis->jobj);
3430
 
3431
 	jfieldID jfid = (*env)->GetFieldID( env, (*env)->GetObjectClass( env, jobj ), "MonitorThreadLock", "Z" );
3432
 	(*env)->SetBooleanField( env, jobj, jfid, (jboolean) 0 );
3433
+	report("Leaving - unlock_monitor_thread\n");
3434
 }
3435
 
3436
 /*----------------------------------------------------------
3437
 check_line_status_register
3438
 
3439
-   accept:      event_info_struct
3440
-   perform:     check for changes on the LSR
3441
-   return:      0 on success
3442
-   exceptions:  none
3443
-   comments:    not supported on all devices/drivers.
3444
+	accept:		event_info_struct
3445
+	perform:	check for changes on the LSR
3446
+	return:		0 on success
3447
+	exceptions:	none
3448
+	comments:	not supported on all devices/drivers.
3449
 ----------------------------------------------------------*/
3450
 int check_line_status_register( struct event_info_struct *eis )
3451
 {
3452
@@ -3771,8 +3870,8 @@
3453
 	if( ! eis->eventflags[SPE_OUTPUT_BUFFER_EMPTY] )
3454
 	{
3455
 		/* This occurs constantly so remove for now
3456
-		 * report( "check_line_status_registe OUPUT_BUFFER_EMPTY not set\n" );
3457
-		 */
3458
+		* report( "check_line_status_registe OUPUT_BUFFER_EMPTY not set\n" );
3459
+		*/
3460
 		return 0;
3461
 	}
3462
 	if ( fstat( eis->fd, &fstatbuf ) )
3463
@@ -3811,16 +3910,17 @@
3464
 /*----------------------------------------------------------
3465
 has_line_status_register_access
3466
 
3467
-   accept:      fd of interest
3468
-   perform:     check for access to the LSR
3469
-   return:      0 if not available
3470
-   exceptions:  none
3471
-   comments:    not supported on all devices/drivers.
3472
-		JK00: work around for multiport cards without TIOCSERGETLSR
3473
-		Cyclades is one of those :-(
3474
+	accept:		fd of interest
3475
+	perform:	check for access to the LSR
3476
+	return:		0 if not available
3477
+	exceptions:	none
3478
+	comments:	not supported on all devices/drivers.
3479
+	JK00: 		work around for multiport cards without TIOCSERGETLSR
3480
+				Cyclades is one of those :-(
3481
 ----------------------------------------------------------*/
3482
 int has_line_status_register_access( int fd )
3483
 {
3484
+	report("Entering - has_line_status_register_access\n");
3485
 #if defined(TIOCSERGETLSR)
3486
 	int change;
3487
 
3488
@@ -3835,17 +3935,17 @@
3489
 /*----------------------------------------------------------
3490
 check_cgi_count
3491
 
3492
-   accept:      fd of interest
3493
-   perform:     check for access to TIOCGICOUNT
3494
-   return:      0 if not available
3495
-   exceptions:  none
3496
-   comments:    not supported on all devices/drivers.
3497
-	 *	wait for RNG, DSR, CD or CTS  but not DataAvailable
3498
-	 *      The drawback here is it never times out so if someone
3499
-	 *      reads there will be no chance to try again.
3500
-	 *      This may make sense if the program does not want to
3501
-	 *      be notified of data available or errors.
3502
-	 *	ret=ioctl(fd,TIOCMIWAIT);
3503
+	accept:		fd of interest
3504
+	perform:	check for access to TIOCGICOUNT
3505
+	return:		0 if not available
3506
+	exceptions:	none
3507
+	comments:	not supported on all devices/drivers.
3508
+				wait for RNG, DSR, CD or CTS  but not DataAvailable
3509
+				The drawback here is it never times out so if someone
3510
+				reads there will be no chance to try again.
3511
+				This may make sense if the program does not want to
3512
+				be notified of data available or errors.
3513
+				ret=ioctl(fd,TIOCMIWAIT);
3514
 ----------------------------------------------------------*/
3515
 void check_cgi_count( struct event_info_struct *eis )
3516
 {
3517
@@ -3885,11 +3985,11 @@
3518
 /*----------------------------------------------------------
3519
 port_has_changed_fionread
3520
 
3521
-   accept:      fd of interest
3522
-   perform:     check if FIONREAD has changed
3523
-   return:      0 if no data available
3524
-   exceptions:  none
3525
-   comments:
3526
+	accept:		fd of interest
3527
+	perform:	check if FIONREAD has changed
3528
+	return:		0 if no data available
3529
+	exceptions:	none
3530
+	comments:
3531
 ----------------------------------------------------------*/
3532
 int port_has_changed_fionread( struct event_info_struct *eis )
3533
 {
3534
@@ -3897,17 +3997,19 @@
3535
 	char message[80];
3536
 
3537
 	rc = ioctl( eis->fd, FIONREAD, &change );
3538
+	memset(&message[0], 0, sizeof(message));
3539
 	sprintf( message, "port_has_changed_fionread: change is %i ret is %i\n", change, eis->ret );
3540
 #if defined(__unixware__) || defined(__sun__)
3541
 	/*
3542
-	   On SCO OpenServer FIONREAD always fails for serial devices,
3543
-	   so rely upon select() result to know whether data available.
3544
+		On SCO OpenServer FIONREAD always fails for serial devices,
3545
+		so rely upon select() result to know whether data available.
3546
 
3547
-	   This is true for Solaris, also.  taj.
3548
+		This is true for Solaris, also.  taj.
3549
 	*/
3550
 	if( (rc != -1 && change) || (rc == -1 && eis->ret > 0) )
3551
 		return( 1 );
3552
 #else
3553
+	memset(&message[0], 0, sizeof(message));
3554
 	sprintf( message, "port_has_changed_fionread: change is %i\n", change );
3555
 	report_verbose( message );
3556
 	if( change )
3557
@@ -3919,11 +4021,11 @@
3558
 /*----------------------------------------------------------
3559
 check_tiocmget_changes
3560
 
3561
-   accept:      event_info_struct
3562
-   perform:     use TIOCMGET to report events
3563
-   return:      none
3564
-   exceptions:  none
3565
-   comments:    not supported on all devices/drivers.
3566
+	accept:		event_info_struct
3567
+	perform:	use TIOCMGET to report events
3568
+	return:		none
3569
+	exceptions:	none
3570
+	comments:	not supported on all devices/drivers.
3571
 ----------------------------------------------------------*/
3572
 void check_tiocmget_changes( struct event_info_struct * eis )
3573
 {
3574
@@ -3966,11 +4068,11 @@
3575
 /*----------------------------------------------------------
3576
 system_wait
3577
 
3578
-   accept:
3579
-   perform:
3580
-   return:
3581
-   exceptions:  none
3582
-   comments:
3583
+	accept:
3584
+	perform:
3585
+	return:
3586
+	exceptions:	none
3587
+	comments:
3588
 ----------------------------------------------------------*/
3589
 void system_wait()
3590
 {
3591
@@ -3987,9 +4089,9 @@
3592
 #else
3593
 #ifdef TRENT_IS_HERE_DEBUGGING_THREADS
3594
 	/* On NT4 The following was observed in a intense test:
3595
-		50000   95%   179 sec
3596
-		200000  95%   193 sec
3597
-		1000000 95%   203 sec	some callback failures sometimes.
3598
+		50000	95%	179 sec
3599
+		200000  95%	193 sec
3600
+		1000000 95%	203 sec	some callback failures sometimes.
3601
 		2000000 0-95% 		callback failures.
3602
 	*/
3603
 #endif /* TRENT_IS_HERE_DEBUGGING_THREADS */
3604
@@ -3999,28 +4101,32 @@
3605
 /*----------------------------------------------------------
3606
 driver_has_tiocgicount
3607
 
3608
-   accept:      fd of interest
3609
-   perform:     check for access to TIOCGICOUNT
3610
-   return:      0 if not available
3611
-   exceptions:  none
3612
-   comments:    not supported on all devices/drivers.
3613
-		Some multiport serial cards do not implement TIOCGICOUNT ...
3614
-		So use the 'dumb' mode to enable using them after all! JK00
3615
+	accept:		fd of interest
3616
+	perform:	check for access to TIOCGICOUNT
3617
+	return:		0 if not available
3618
+	exceptions:	none
3619
+	comments:	not supported on all devices/drivers.
3620
+				Some multiport serial cards do not implement TIOCGICOUNT
3621
+				So use the 'dumb' mode to enable using them after all!
3622
+				JK00
3623
 ----------------------------------------------------------*/
3624
 int driver_has_tiocgicount( struct event_info_struct * eis )
3625
 {
3626
+	report("Entering - driver_has_tiocgicount\n");
3627
 #if defined(TIOCGICOUNT)
3628
-
3629
+	report("TIOCGICOUNT is defined\n");
3630
 	/* Some multiport serial cards do not implement TIOCGICOUNT ... */
3631
 	/* So use the 'dumb' mode to enable using them after all! JK00 */
3632
 
3633
 	if( ioctl( eis->fd, TIOCGICOUNT, &eis->osis ) < 0 ) {
3634
-		report_verbose( " driver_has_tiocgicount:  Port does not support TIOCGICOUNT events\n" );
3635
+		report_verbose( " driver_has_tiocgicount:	Port does not support TIOCGICOUNT events\n" );
3636
 		return(0);
3637
 	}
3638
 	else
3639
+		report("driver_has_tiocgicount: TIOCGICOUNT is implemented\n");
3640
 		return(1);
3641
 #endif /*  TIOCGICOUNT */
3642
+	report("Leaving - driver_has_tiocgicount\n");
3643
 	return(0);
3644
 
3645
 }
3646
@@ -4028,11 +4134,11 @@
3647
 /*----------------------------------------------------------
3648
 report_serial_events
3649
 
3650
-   accept:      event_info_struct
3651
-   perform:     send events if they occured
3652
-   return:      0 if not available
3653
-   exceptions:  none
3654
-   comments:    not supported on all devices/drivers.
3655
+	accept:		event_info_struct
3656
+	perform:	send events if they occured
3657
+	return:		0 if not available
3658
+	exceptions:	none
3659
+	comments:	not supported on all devices/drivers.
3660
 ----------------------------------------------------------*/
3661
 void report_serial_events( struct event_info_struct *eis )
3662
 {
3663
@@ -4053,7 +4159,7 @@
3664
 		{
3665
 			report_verbose("report_serial_events: ignoring DATA_AVAILABLE\n");
3666
 /*
3667
-			report(".");
3668
+			report(".\n");
3669
 */
3670
 			usleep(20000);
3671
 #if !defined(__sun__)
3672
@@ -4078,14 +4184,15 @@
3673
 /*----------------------------------------------------------
3674
 initialise_event_info_struct
3675
 
3676
-   accept:      event_info_struct for this thread.
3677
-   perform:     initialise or reset the event_info_struct
3678
-   return:      1 on success
3679
-   exceptions:  none
3680
-   comments:
3681
+	accept:		event_info_struct for this thread.
3682
+	perform:	initialise or reset the event_info_struct
3683
+	return:		1 on success
3684
+	exceptions:	none
3685
+	comments:
3686
 ----------------------------------------------------------*/
3687
 int initialise_event_info_struct( struct event_info_struct *eis )
3688
 {
3689
+	report("Entering - initialise_event_info_struct\n");
3690
 	int i;
3691
 	jobject jobj = *eis->jobj;
3692
 	JNIEnv *env = eis->env;
3693
@@ -4141,21 +4248,23 @@
3694
 	eis->tv_sleep.tv_sec = 0;
3695
 	eis->tv_sleep.tv_usec = 1000;
3696
 	eis->initialised = 1;
3697
+	report("Leaving - initialise_event_info_struct\n");
3698
 	return( 1 );
3699
 fail:
3700
 	report_error("initialise_event_info_struct: initialise failed!\n");
3701
 	finalize_event_info_struct( eis );
3702
+	report("Leaving - initialise_event_info_struct\n");
3703
 	return( 0 );
3704
 }
3705
 
3706
 /*----------------------------------------------------------
3707
 finalize_event_info_struct
3708
 
3709
-   accept:      event_info_struct for this thread.
3710
-   perform:     free resources
3711
-   return:      none
3712
-   exceptions:  none
3713
-   comments:
3714
+	accept:		event_info_struct for this thread.
3715
+	perform:	free resources
3716
+	return:		none
3717
+	exceptions:	none
3718
+	comments:
3719
 ----------------------------------------------------------*/
3720
 void finalize_event_info_struct( struct event_info_struct *eis )
3721
 {
3722
@@ -4181,14 +4290,15 @@
3723
 /*----------------------------------------------------------
3724
 RXTXPort.eventLoop
3725
 
3726
-   accept:      none
3727
-   perform:     periodically check for SerialPortEvents
3728
-   return:      none
3729
-   exceptions:  none
3730
-   comments:	please keep this function clean.
3731
+	accept:		none
3732
+	perform:	periodically check for SerialPortEvents
3733
+	return:		none
3734
+	exceptions:	none
3735
+	comments:	please keep this function clean.
3736
 ----------------------------------------------------------*/
3737
 JNIEXPORT void JNICALL RXTXPort(eventLoop)( JNIEnv *env, jobject jobj )
3738
 {
3739
+	report( "Entering - RXTXPort_eventLoop\n" );
3740
 #ifdef WIN32
3741
 	int i = 0;
3742
 #endif /* WIN32 */
3743
@@ -4198,74 +4308,92 @@
3744
 	eis.jobj = &jobj;
3745
 	eis.initialised = 0;
3746
 
3747
-	ENTER( "eventLoop\n" );
3748
+	
3749
 	if ( !initialise_event_info_struct( &eis ) ) goto end;
3750
 	if ( !init_threads( &eis ) ) goto end;
3751
+	
3752
+	report( "RXTXPort_eventLoop - Unlocking Monitor Thread\n" );
3753
 	unlock_monitor_thread( &eis );
3754
+	
3755
 	do{
3756
 		report_time_eventLoop( );
3757
 		do {
3758
 			/* nothing goes between this call and select */
3759
 			if( eis.closing )
3760
 			{
3761
-				report("eventLoop: got interrupt\n");
3762
+				report( "RXTXPort_eventLoop - Got Interupted\n" );
3763
 				finalize_threads( &eis );
3764
 				finalize_event_info_struct( &eis );
3765
-				LEAVE("eventLoop");
3766
+				report("Leaving - RXTXPort_eventLoop\n");
3767
 				return;
3768
 			}
3769
-#ifndef WIN32
3770
-			/* report( "." ); */
3771
-			do {
3772
-				eis.ret = SELECT( eis.fd + 1, &eis.rfds, NULL, NULL,
3773
-					&eis.tv_sleep );
3774
-			} while (eis.ret < 0 && errno==EINTR);
3775
-#else
3776
-			/*
3777
-			    termios.c:serial_select is instable for some
3778
-			    reason
3779
-
3780
-			    polling is not blowing up.
3781
-			*/
3782
-/*
3783
-			usleep(5000);
3784
-*/
3785
-			eis.ret=1;
3786
-			while( i++ < 5 )
3787
-			{
3788
-				if(eis.eventflags[SPE_DATA_AVAILABLE] )
3789
+			
3790
+			#ifndef WIN32
3791
+				
3792
+				/**
3793
+				*	report( "." );
3794
+				**/
3795
+				
3796
+				do {
3797
+					eis.ret = SELECT( eis.fd + 1, &eis.rfds, NULL, NULL,
3798
+						&eis.tv_sleep );
3799
+				} while (eis.ret < 0 && errno==EINTR);
3800
+				
3801
+			#else
3802
+				
3803
+				/**
3804
+				*	termios.c:serial_select is instable for some
3805
+				*	reason
3806
+				*
3807
+				*	polling is not blowing up.
3808
+				**/
3809
+				
3810
+				/**
3811
+				*	usleep(5000);
3812
+				**/
3813
+				
3814
+				eis.ret=1;
3815
+				while( i++ < 5 )
3816
 				{
3817
-					if( port_has_changed_fionread( &eis ) )
3818
+					if(eis.eventflags[SPE_DATA_AVAILABLE] )
3819
 					{
3820
-						send_event( &eis, SPE_DATA_AVAILABLE, 1 );
3821
+						if( port_has_changed_fionread( &eis ) )
3822
+						{
3823
+							send_event( &eis, SPE_DATA_AVAILABLE, 1 );
3824
+						}
3825
 					}
3826
+					usleep(1000);
3827
 				}
3828
-				usleep(1000);
3829
-			}
3830
-			i = 0;
3831
-#endif /* WIN32 */
3832
+				i = 0;
3833
+				
3834
+			#endif /* WIN32 */
3835
 		}  while ( eis.ret < 0 && errno == EINTR );
3836
+		
3837
+		
3838
+		
3839
 		if( eis.ret >= 0 )
3840
 		{
3841
 			report_serial_events( &eis );
3842
 		}
3843
+		
3844
 		initialise_event_info_struct( &eis );
3845
+		
3846
 	} while( 1 );
3847
 end:
3848
-	LEAVE( "eventLoop:  Bailing!\n" );
3849
+	report( "Leaving - eventLoop:	Bailing!\n" );
3850
 }
3851
 
3852
 /*----------------------------------------------------------
3853
 RXTXVersion.nativeGetVersion
3854
 
3855
-   accept:      none
3856
-   perform:     return the current version
3857
-   return:      version
3858
-   exceptions:  none
3859
-   comments:    This is used to avoid mixing versions of the .jar and
3860
-		native library.
3861
-		First introduced in rxtx-1.5-9
3862
-                Moved from RXTXCommDriver to RXTXVersion in rxtx-2.1-7
3863
+	accept:		none
3864
+	perform:	return the current version
3865
+	return:		version
3866
+	exceptions:	none
3867
+	comments:	This is used to avoid mixing versions of the .jar and
3868
+				native library.
3869
+				First introduced in rxtx-1.5-9
3870
+				Moved from RXTXCommDriver to RXTXVersion in rxtx-2.1-7
3871
 
3872
 ----------------------------------------------------------*/
3873
 JNIEXPORT jstring JNICALL RXTXVersion(nativeGetVersion) (JNIEnv *env,
3874
@@ -4277,13 +4405,13 @@
3875
 /*----------------------------------------------------------
3876
 RXTXCommDriver.testRead
3877
 
3878
-   accept:      tty_name The device to be tested
3879
-   perform:     test if the device can be read from
3880
-   return:      JNI_TRUE if the device can be read from
3881
-   exceptions:  none
3882
-   comments:    From Wayne Roberts wroberts1@home.com
3883
-   		check tcget/setattr returns.
3884
-		support for non serial ports Trent
3885
+	accept:		tty_name The device to be tested
3886
+	perform:	test if the device can be read from
3887
+	return:		JNI_TRUE if the device can be read from
3888
+	exceptions:	none
3889
+	comments:	From Wayne Roberts wroberts1@home.com
3890
+				check tcget/setattr returns.
3891
+				support for non serial ports Trent
3892
 ----------------------------------------------------------*/
3893
 
3894
 JNIEXPORT jboolean  JNICALL RXTXCommDriver(testRead)(
3895
@@ -4293,68 +4421,117 @@
3896
 	jint port_type
3897
 )
3898
 {
3899
+	
3900
+	const char *name = (*env)->GetStringUTFChars(env, tty_name, 0);
3901
+	
3902
+	char sm[256];
3903
+	memset(&sm[0], 0, sizeof(sm));
3904
+	sprintf( sm, "Entering - RXTXPort:testRead(%s, %i)\n", name, port_type );
3905
+	report( sm );
3906
+
3907
 	struct termios ttyset;
3908
 	char c;
3909
-#ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION
3910
-	char message[80];
3911
-#endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */
3912
+	char message[256];
3913
 	int fd;
3914
-	const char *name = (*env)->GetStringUTFChars(env, tty_name, 0);
3915
+	
3916
 	int ret = JNI_TRUE;
3917
 	int pid = -1;
3918
-	/* We opened the file in this thread, use this pid to unlock */
3919
-#ifndef WIN32
3920
-	pid = getpid();
3921
-#else
3922
-	char full_windows_name[80];
3923
-#endif /* WIN32 */
3924
-
3925
-	ENTER( "RXTXPort:testRead" );
3926
-#ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION
3927
-	/* vmware lies about which ports are there causing irq conflicts */
3928
-	/* this is for testing only */
3929
-	if( !strcmp( name, "COM1" ) || !strcmp( name, "COM2") )
3930
-	{
3931
-		printf("%s is good\n",name);
3932
-		sprintf( message, "testRead: %s is good!\n", name );
3933
-		report( message );
3934
+	
3935
+	/* We open the file in this thread, use this pid to unlock */
3936
+	#ifndef WIN32
3937
+		pid = getpid();
3938
+	#else
3939
+		char full_windows_name[80];
3940
+	#endif /* WIN32 */
3941
+		
3942
+	#ifdef TRENT_IS_HERE_DEBUGGING_ENUMERATION
3943
+		char message[80];
3944
+		/* vmware lies about which ports are there causing irq conflicts */
3945
+		/* this is for testing only */
3946
+		if( !strcmp( name, "COM1" ) || !strcmp( name, "COM2") )
3947
+		{
3948
+			printf("%s is good\n",name);
3949
+			memset(&message[0], 0, sizeof(message));
3950
+			sprintf( message, "testRead: %s is good!\n", name );
3951
+			report( message );
3952
+			(*env)->ReleaseStringUTFChars( env, tty_name, name );
3953
+			return( JNI_TRUE );
3954
+		}
3955
 		(*env)->ReleaseStringUTFChars( env, tty_name, name );
3956
-		return( JNI_TRUE );
3957
-	}
3958
-	(*env)->ReleaseStringUTFChars( env, tty_name, name );
3959
-	return( JNI_FALSE );
3960
-#endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */
3961
-#ifdef WIN32
3962
-	strcpy( full_windows_name, DEVICEDIR );
3963
-	strcat( full_windows_name, name );
3964
-	ret = serial_test((char *) full_windows_name );
3965
-	(*env)->ReleaseStringUTFChars( env, tty_name, name );
3966
-	return(ret);
3967
-#endif /* WIN32 */
3968
+		return( JNI_FALSE );
3969
+	#endif /* TRENT_IS_HERE_DEBUGGING_ENUMERATION */
3970
+	
3971
+	#ifdef WIN32
3972
+		strcpy( full_windows_name, DEVICEDIR );
3973
+		strcat( full_windows_name, name );
3974
+		ret = serial_test((char *) full_windows_name );
3975
+		(*env)->ReleaseStringUTFChars( env, tty_name, name );
3976
+		return(ret);
3977
+	#endif /* WIN32 */
3978
 
3979
-	/*
3980
-		LOCK is one of three functions defined in SerialImp.h
3981
+	/**
3982
+	*	LOCK is one of three functions defined in SerialImp.h
3983
+	*		uucp_lock		Solaris
3984
+	*		fhs_lock		Linux
3985
+	*		system_does_not_lock	Win32
3986
+	**/
3987
 
3988
-			uucp_lock		Solaris
3989
-			fhs_lock		Linux
3990
-			system_does_not_lock	Win32
3991
-	*/
3992
-
3993
-	if ( LOCK( name, pid ) )
3994
+	
3995
+	if ( port_type == PORT_SERIAL )
3996
 	{
3997
-		(*env)->ReleaseStringUTFChars(env, tty_name, name);
3998
-		LEAVE( "RXTXPort:testRead no lock" );
3999
-		return JNI_FALSE;
4000
-	}
4001
+		int lockstate;
4002
+		report( "testRead() checking for lock\n" );
4003
+		lockstate = LOCK(name, pid);
4004
+		report( "testRead() - lock check complete\n" );
4005
+		
4006
 
4007
-	/*
4008
-           CLOCAL eliminates open blocking on modem status lines
4009
-           -- changed to O_NONBLOCK
4010
-	*/
4011
-	do {
4012
+		if ( lockstate == 1 )
4013
+		{
4014
+			(*env)->ReleaseStringUTFChars(env, tty_name, name);
4015
+			report( "Leaving - RXTXPort:testRead no lock\n" );
4016
+			return JNI_FALSE;
4017
+		}
4018
+		else
4019
+		{	
4020
+			memset(&message[0], 0, sizeof(message));
4021
+			sprintf( message, "testRead() - going to open the file (%i)\n", (int) O_RDWR);
4022
+			report( message );
4023
+		}
4024
+	}
4025
+	/**
4026
+	*	CLOCAL eliminates open blocking on modem status lines
4027
+	*	-- changed to O_NONBLOCK
4028
+	**/
4029
+
4030
+	/**
4031
+	*	FIXME - On FreeBSD the open command on /dev/lpt0 hangs for
4032
+	*	about 5 - 30 seconds in FreeBSD v10.1-p9 on i386.
4033
+	* 	No idea how to resolve yet.  Returns errno == EBUSY.
4034
+	**/	
4035
+	
4036
+	do 
4037
+	{
4038
 		fd=OPEN ( name, O_RDWR | O_NOCTTY | O_NONBLOCK );
4039
 	}  while ( fd < 0 && errno==EINTR );
4040
 
4041
+	/**
4042
+	*	Just because a port is busy, doesn't mean that we can't use it,
4043
+	*	but shows it is available for future use...
4044
+	*	Note: This skips all the permission tests, as it is in use.
4045
+	*	
4046
+	* 	FIXME: Get perms on FreeBSD from STAT command returned results.
4047
+	* 	
4048
+	*	so:
4049
+	**/
4050
+	if ( errno == EBUSY )
4051
+	{
4052
+		goto END;
4053
+	}
4054
+	
4055
+	memset(&message[0], 0, sizeof(message));
4056
+	sprintf( message, "testRead() - open returned(errno = %i, fd = %i)\n", (int) errno, (int) fd);
4057
+	report( message );
4058
+	
4059
 	if( fd < 0 )
4060
 	{
4061
 		report_verbose( "testRead() open failed\n" );
4062
@@ -4366,12 +4543,14 @@
4063
 	{
4064
 		int saved_flags;
4065
 		struct termios saved_termios;
4066
-
4067
+		
4068
+		report_verbose( "testRead() - tcgetattr\n" );
4069
+		
4070
 		if (tcgetattr(fd, &ttyset) < 0) {
4071
 			ret = JNI_FALSE;
4072
 			goto END;
4073
 		}
4074
-
4075
+		
4076
 		/* save, restore later */
4077
 		if ( ( saved_flags = fcntl(fd, F_GETFL ) ) < 0 )
4078
 		{
4079
@@ -4379,7 +4558,7 @@
4080
 			ret = JNI_FALSE;
4081
 			goto END;
4082
 		}
4083
-
4084
+		
4085
 		memcpy( &saved_termios, &ttyset, sizeof( struct termios ) );
4086
 
4087
 		if ( fcntl( fd, F_SETFL, O_NONBLOCK ) < 0 )
4088
@@ -4400,97 +4579,97 @@
4089
 			goto END;
4090
 		}
4091
 
4092
-/*
4093
-
4094
-              The following may mess up if both EAGAIN and EWOULDBLOCK
4095
-              are defined but only EWOULDBLOCK is used
4096
-
4097
-              Linux:
4098
-
4099
-              man 2 open
4100
-              O_NONBLOCK or O_NDELAY
4101
-              When  possible,  the file is opened in non-blocking
4102
-              mode. Neither the open nor  any  subsequent  opera�
4103
-              tions on the file descriptor which is returned will
4104
-              cause the calling process to wait.   For  the  han�
4105
-              dling  of  FIFOs  (named  pipes), see also fifo(4).
4106
-              This mode need not have any effect on  files  other
4107
-              than FIFOs.
4108
-
4109
-	      man 2 read
4110
-              EAGAIN
4111
-              Non-blocking I/O has been selected using O_NONBLOCK
4112
-              and no data was immediately available for  reading.
4113
-
4114
-
4115
-              /usr/include/asm/error.h:
4116
-              #define EAGAIN          11      / Try again /
4117
-              #define EWOULDBLOCK     EAGAIN  / Operation would block /
4118
-
4119
-              looks like the kernel is using EAGAIN
4120
-
4121
-              -- should be OK
4122
-
4123
-              Solaris:
4124
-
4125
-              man 2 open
4126
-              EAGAIN    The path  argument  names  the  slave  side  of  a
4127
-              pseudo-terminal device that is locked.
4128
-
4129
-              man 2 read
4130
-              If O_NONBLOCK is set, read() returns -1 and sets errno
4131
-              to EAGAIN.
4132
-
4133
-              -- should be OK.
4134
-
4135
-              HP-UX
4136
-
4137
-              both are defined but EAGAIN is used.
4138
-
4139
-              -- should be OK.
4140
-
4141
-              Win32
4142
-
4143
-              neither errno is currently set.  Comment added to termios.c
4144
-              serial_open().
4145
-
4146
-              -- should be OK
4147
-
4148
-Steven's book.  Advanced programming in the Unix Environment pg 364
4149
-
4150
-"A common use for nonblocking I/O is for dealing with a terminal device
4151
-for a network connection and these devices are normally used by one process
4152
-at a time.  This means that the change in the BSD semantics normally does 't
4153
-effect us.  The different error return, EWOULDBLOCK, instead of POSIX.1
4154
-EAGAIN, continues to be a portability difference that we must deal with."
4155
-
4156
-*/
4157
-
4158
+		/**
4159
+		*	The following may mess up if both EAGAIN and EWOULDBLOCK
4160
+		*	are defined but only EWOULDBLOCK is used
4161
+		*	
4162
+		*	Linux:
4163
+		*	
4164
+		*	man 2 open
4165
+		*	O_NONBLOCK or O_NDELAY
4166
+		*	When  possible,  the file is opened in non-blocking
4167
+		*	mode. Neither the open nor  any  subsequent  opera�
4168
+		*	tions on the file descriptor which is returned will
4169
+		*	cause the calling process to wait.	For  the  han�
4170
+		*	dling  of  FIFOs  (named  pipes), see also fifo(4).
4171
+		*	This mode need not have any effect on  files  other
4172
+		*	than FIFOs.
4173
+
4174
+		*	man 2 read
4175
+		*	EAGAIN
4176
+		*	Non-blocking I/O has been selected using O_NONBLOCK
4177
+		*	and no data was immediately available for  reading.
4178
+		*	/usr/include/asm/error.h:
4179
+		*	#define EAGAIN		11	/ Try again /
4180
+		*	#define EWOULDBLOCK	EAGAIN  / Operation would block /
4181
+		*	looks like the kernel is using EAGAIN
4182
+		*	-- should be OK
4183
+
4184
+		*	Solaris:
4185
+		*	man 2 open
4186
+		*	EAGAIN	The path  argument  names  the  slave  side  of  a
4187
+		*	pseudo-terminal device that is locked.
4188
+		*	man 2 read
4189
+		*	If O_NONBLOCK is set, read() returns -1 and sets errno
4190
+		*	to EAGAIN.
4191
+		*	-- should be OK.
4192
+
4193
+		*	HP-UX
4194
+		*	both are defined but EAGAIN is used.
4195
+		*	-- should be OK.
4196
+
4197
+		*	Win32
4198
+		*	neither errno is currently set.  Comment added to termios.c
4199
+		*	serial_open().
4200
+		*	-- should be OK
4201
+
4202
+		*	Steven's book.  Advanced programming in the Unix Environment pg 364
4203
+
4204
+		*	"A common use for nonblocking I/O is for dealing with a terminal device
4205
+		*	for a network connection and these devices are normally used by one process
4206
+		*	at a time.  This means that the change in the BSD semantics normally does 't
4207
+		*	effect us.  The different error return, EWOULDBLOCK, instead of POSIX.1
4208
+		*	EAGAIN, continues to be a portability difference that we must deal with."
4209
+		**/
4210
+		report_verbose( "testRead() - Reading...\n" );
4211
+		
4212
 		if ( READ( fd, &c, 1 ) < 0 )
4213
 		{
4214
-#ifdef EAGAIN
4215
-			if ( errno != EAGAIN ) {
4216
-				report( "testRead() read failed\n" );
4217
-				ret = JNI_FALSE;
4218
-			}
4219
-#else
4220
-#ifdef EWOULDBLOCK
4221
-			if ( errno != EWOULDBLOCK )
4222
-			{
4223
-				report( "testRead() read failed\n" );
4224
-				ret = JNI_FALSE;
4225
-			}
4226
-#else
4227
-			ret = JNI_FALSE;
4228
-#endif /* EWOULDBLOCK */
4229
-#endif /* EAGAIN */
4230
+			#ifdef EAGAIN
4231
+				if ( errno != EAGAIN ) {
4232
+					report( "testRead() read failed\n" );
4233
+					ret = JNI_FALSE;
4234
+				}
4235
+			#else
4236
+				#ifdef EWOULDBLOCK
4237
+					if ( errno != EWOULDBLOCK )
4238
+					{
4239
+						report( "testRead() read failed\n" );
4240
+						ret = JNI_FALSE;
4241
+					}
4242
+				#else
4243
+					ret = JNI_FALSE;
4244
+				#endif /* EWOULDBLOCK */
4245
+			#endif /* EAGAIN */
4246
 		}
4247
-
4248
+		report_verbose( "testRead() - Read Complete\n" );
4249
+		
4250
 		/* dont walk over unlocked open devices */
4251
 		tcsetattr( fd, TCSANOW, &saved_termios );
4252
 		fcntl( fd, F_SETFL, saved_flags );
4253
 	}
4254
-
4255
+	else if ( port_type == PORT_PARALLEL )
4256
+	{
4257
+		/**
4258
+		*	Parrellel ports are also sent here for testing.
4259
+		*	We should be doing some sort of check...
4260
+		*	FIXME - To implement.
4261
+		**/
4262
+		report( "testRead() This is a parrelle port, skipping\n" );
4263
+	}
4264
+	
4265
+	
4266
+	
4267
 	/*
4268
 		UNLOCK is one of three functions defined in SerialImp.h
4269
 
4270
@@ -4500,185 +4679,249 @@
4271
 	*/
4272
 
4273
 END:
4274
-	UNLOCK(name, pid );
4275
-	(*env)->ReleaseStringUTFChars( env, tty_name, name );
4276
-	CLOSE( fd );
4277
-	LEAVE( "RXTXPort:testRead" );
4278
+	report_verbose( "testRead() - at end\n" );
4279
+	if ( port_type == PORT_SERIAL )
4280
+	{
4281
+		report_verbose( "testRead() - unlocking\n" );
4282
+		UNLOCK(name, pid );
4283
+		report_verbose( "testRead()  - Releasing String Chars\n" );
4284
+		(*env)->ReleaseStringUTFChars( env, tty_name, name );
4285
+		report_verbose( "testRead() - Closing...\n" );
4286
+		CLOSE( fd );
4287
+	}
4288
+	else
4289
+	{
4290
+		report_verbose( "testRead()  - Releasing String Chars\n" );
4291
+		(*env)->ReleaseStringUTFChars( env, tty_name, name );
4292
+	}
4293
+	report( "Leaving - RXTXPort:testRead\n" );
4294
 	return ret;
4295
 }
4296
 
4297
 #if defined(__APPLE__)
4298
-/*----------------------------------------------------------
4299
- createSerialIterator()
4300
-   accept:
4301
-   perform:
4302
-   return:
4303
-   exceptions:
4304
-   comments:
4305
+	
4306
+	/*----------------------------------------------------------
4307
+	createSerialIterator()
4308
+	accept:
4309
+	perform:
4310
+	return:
4311
+	exceptions:
4312
+	comments:
4313
 		Code courtesy of Eric Welch at Keyspan, except for the bugs
4314
 		which are courtesy of Joseph Goldstone (joseph@lp.com)
4315
-----------------------------------------------------------*/
4316
-
4317
-kern_return_t
4318
-createSerialIterator(io_iterator_t *serialIterator)
4319
-{
4320
-    kern_return_t    kernResult;
4321
-    mach_port_t        masterPort;
4322
-    CFMutableDictionaryRef    classesToMatch;
4323
-    if ((kernResult=IOMasterPort( (int) NULL, &masterPort ) ) != KERN_SUCCESS)
4324
-    {
4325
-	printf( "IOMasterPort returned %d\n", kernResult);
4326
-	return kernResult;
4327
-    }
4328
-    if ((classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue)) == NULL)
4329
-    {
4330
-	printf( "IOServiceMatching returned NULL\n" );
4331
-	return kernResult;
4332
-    }
4333
-    CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
4334
-    kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, serialIterator);
4335
-    if (kernResult != KERN_SUCCESS)
4336
-    {
4337
-	printf( "IOServiceGetMatchingServices returned %d\n", kernResult);
4338
-    }
4339
-    return kernResult;
4340
-}
4341
+	----------------------------------------------------------*/
4342
+	
4343
+	kern_return_t
4344
+	createSerialIterator(io_iterator_t *serialIterator)
4345
+	{
4346
+		kern_return_t			kernResult;
4347
+		mach_port_t				masterPort;
4348
+		CFMutableDictionaryRef	classesToMatch;
4349
+		
4350
+		if ((kernResult=IOMasterPort( (int) NULL, &masterPort ) ) != KERN_SUCCESS)
4351
+		{
4352
+			printf( "IOMasterPort returned %d\n", kernResult);
4353
+			return kernResult;
4354
+		}
4355
+		if ((classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue)) == NULL)
4356
+		{
4357
+			printf( "IOServiceMatching returned NULL\n" );
4358
+			return kernResult;
4359
+		}
4360
+		
4361
+		CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
4362
+		
4363
+		kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, serialIterator);
4364
+		
4365
+		if (kernResult != KERN_SUCCESS)
4366
+		{
4367
+			printf( "IOServiceGetMatchingServices returned %d\n", kernResult);
4368
+		}
4369
+		
4370
+		return kernResult;
4371
+	}
4372
 
4373
-/*----------------------------------------------------------
4374
- getRegistryString()
4375
-
4376
-   accept:
4377
-   perform:
4378
-   return:
4379
-   exceptions:
4380
-   comments:
4381
+	/*----------------------------------------------------------
4382
+	getRegistryString()
4383
+	
4384
+	accept:
4385
+	perform:
4386
+	return:
4387
+	exceptions:
4388
+	comments:
4389
 		Code courtesy of Eric Welch at Keyspan, except for the bugs
4390
 		which are courtesy of Joseph Goldstone (joseph@lp.com)
4391
-----------------------------------------------------------*/
4392
-char *
4393
-getRegistryString(io_object_t sObj, char *propName)
4394
-{
4395
-    static char resultStr[256];
4396
-    CFTypeRef   nameCFstring;
4397
-    resultStr[0] = 0;
4398
-    nameCFstring = IORegistryEntryCreateCFProperty(sObj,
4399
-            CFStringCreateWithCString(kCFAllocatorDefault, propName, kCFStringEncodingASCII),
4400
-                                                   kCFAllocatorDefault, 0);
4401
-    if (nameCFstring)
4402
-    {
4403
-        CFStringGetCString(nameCFstring, resultStr, sizeof(resultStr), kCFStringEncodingASCII);
4404
-        CFRelease(nameCFstring);
4405
-    }
4406
-    return resultStr;
4407
-}
4408
+	----------------------------------------------------------*/
4409
+	char *
4410
+	getRegistryString(io_object_t sObj, char *propName)
4411
+	{
4412
+		static char resultStr[256];
4413
+		CFTypeRef	nameCFstring;
4414
+		resultStr[0] = 0;
4415
+		nameCFstring = IORegistryEntryCreateCFProperty(
4416
+			sObj,
4417
+		CFStringCreateWithCString
4418
+				(
4419
+					kCFAllocatorDefault,
4420
+					propName,
4421
+					kCFStringEncodingASCII
4422
+				),
4423
+		kCFAllocatorDefault, 
4424
+		0
4425
+		);
4426
+		if (nameCFstring)
4427
+		{
4428
+			CFStringGetCString(nameCFstring, resultStr, sizeof(resultStr), kCFStringEncodingASCII);
4429
+			CFRelease(nameCFstring);
4430
+		}
4431
+		return resultStr;
4432
+	}
4433
+	
4434
+	/*----------------------------------------------------------
4435
+	registerKnownSerialPorts()
4436
+	accept:
4437
+	perform:
4438
+	return:
4439
+	exceptions:
4440
+	comments:
4441
+	----------------------------------------------------------*/
4442
+	int
4443
+	registerKnownSerialPorts(JNIEnv *env, jobject jobj, jint portType) /* dima */
4444
+	{
4445
+		io_iterator_t	theSerialIterator;
4446
+		io_object_t	theObject;
4447
+		int		*	numPorts = 0;/* dima it should initiated */
4448
+	
4449
+		if 	(
4450
+				( createSerialIterator( &theSerialIterator ) != KERN_SUCCESS) ||
4451
+				( ! IOIteratorIsValid( theSerialIterator))
4452
+			)
4453
+		{
4454
+			/*  This also happens when no drivers are installed */
4455
+			report( "createSerialIterator failed\n" );
4456
+			return(0);
4457
+		} 
4458
+		else
4459
+		{
4460
+			jclass cls;
4461
+			jmethodID mid;
4462
+			cls = (*env)->FindClass(env,"gnu/io/CommPortIdentifier" );
4463
+			if (cls == 0)
4464
+			{ 
4465
+				report( "can't find class of gnu/io/CommPortIdentifier\n" );
4466
+				return numPorts;
4467
+			}
4468
+			mid = (*env)->GetStaticMethodID(
4469
+				env, 
4470
+				cls, 
4471
+				"addPortName",
4472
+				"(Ljava/lang/String;ILgnu/io/CommDriver;)V"
4473
+			);
4474
 
4475
-/*----------------------------------------------------------
4476
- registerKnownSerialPorts()
4477
-   accept:
4478
-   perform:
4479
-   return:
4480
-   exceptions:
4481
-   comments:
4482
-----------------------------------------------------------*/
4483
-int
4484
-registerKnownSerialPorts(JNIEnv *env, jobject jobj, jint portType) /* dima */
4485
-{
4486
-    io_iterator_t    theSerialIterator;
4487
-    io_object_t      theObject;
4488
-    int              numPorts = 0;/* dima it should initiated */
4489
-
4490
-    if (( createSerialIterator( &theSerialIterator ) != KERN_SUCCESS) ||
4491
-        ( ! IOIteratorIsValid( theSerialIterator)))
4492
-    {
4493
-	/*  This also happens when no drivers are installed */
4494
-        report( "createSerialIterator failed\n" );
4495
-	return(0);
4496
-    } else {
4497
-	jclass cls; /* dima */
4498
-	jmethodID mid; /* dima */
4499
-        cls = (*env)->FindClass(env,"gnu/io/CommPortIdentifier" ); /* dima */
4500
-        if (cls == 0) { /* dima */
4501
-            report( "can't find class of gnu/io/CommPortIdentifier\n" ); /* dima */
4502
-            return numPorts; /* dima */
4503
-        } /* dima */
4504
-        mid = (*env)->GetStaticMethodID(env, cls, "addPortName", "(Ljava/lang/String;ILgnu/io/CommDriver;)V" ); /* dima */
4505
-
4506
-        if (mid == 0) {
4507
-            printf( "getMethodID of CommDriver.addPortName failed\n" );
4508
-        } else {
4509
-            while (theObject = IOIteratorNext(theSerialIterator))
4510
-            {
4511
- /* begin dima */
4512
-            	jstring	tempJstring;
4513
-				tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIODialinDeviceKey));
4514
-                (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */
4515
- 				(*env)->DeleteLocalRef(env,tempJstring);
4516
-                numPorts++;
4517
-
4518
- 				tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIOCalloutDeviceKey));
4519
-               (*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */
4520
- 				(*env)->DeleteLocalRef(env,tempJstring);
4521
-                numPorts++;
4522
-/* end dima */
4523
-            }
4524
-        }
4525
-    }
4526
-    return numPorts;
4527
-}
4528
+			if (mid == 0) 
4529
+			{
4530
+				printf( "getMethodID of CommDriver.addPortName failed\n" );
4531
+			} 
4532
+			else 
4533
+			{
4534
+				while (theObject = IOIteratorNext(theSerialIterator))
4535
+				{
4536
+					/* begin dima */
4537
+					jstring	tempJstring;
4538
+					tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIODialinDeviceKey));
4539
+					(*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */
4540
+					(*env)->DeleteLocalRef(env,tempJstring);
4541
+					numPorts++;
4542
+					
4543
+					tempJstring = (*env)->NewStringUTF(env,getRegistryString(theObject, kIOCalloutDeviceKey));
4544
+					(*env)->CallStaticVoidMethod(env, cls, mid,tempJstring,portType,jobj);/* dima */
4545
+					(*env)->DeleteLocalRef(env,tempJstring);
4546
+					numPorts++;
4547
+					/* end dima */
4548
+				}
4549
+			}
4550
+		}
4551
+		return numPorts;
4552
+	}
4553
 #endif /* __APPLE__ */
4554
 
4555
 /*----------------------------------------------------------
4556
  registerKnownPorts
4557
 
4558
-   accept:      the type of port
4559
-   perform:     register any ports of the desired type a priori known to this OS
4560
-   return:      JNI_TRUE if any such ports were registered otherwise JNI_FALSE
4561
-   exceptions:  none
4562
-   comments:
4563
+	accept:		the type of port
4564
+	perform:	register any ports of the desired type a priori known
4565
+	 			to this OS
4566
+	return:		JNI_TRUE if any such ports were registered otherwise
4567
+				JNI_FALSE
4568
+	exceptions:	none
4569
+	comments:
4570
 ----------------------------------------------------------*/
4571
-JNIEXPORT jboolean JNICALL RXTXCommDriver(registerKnownPorts)(JNIEnv *env,
4572
-    jobject jobj, jint portType)
4573
+JNIEXPORT jboolean JNICALL RXTXCommDriver(registerKnownPorts)(
4574
+	JNIEnv *env,
4575
+	jobject jobj, 
4576
+	jint portType
4577
+)
4578
 {
4579
-	enum {PORT_TYPE_SERIAL = 1,
4580
+	report("Entering - RXTXCommDriver_registerKnownPorts\n");
4581
+	
4582
+	char strbuf[256];
4583
+	
4584
+	enum 
4585
+	{
4586
+		PORT_TYPE_SERIAL = 1,
4587
 		PORT_TYPE_PARALLEL,
4588
 		PORT_TYPE_I2C,
4589
 		PORT_TYPE_RS485,
4590
-		PORT_TYPE_RAW};
4591
+		PORT_TYPE_RAW
4592
+	};
4593
+		
4594
 	jboolean result = JNI_FALSE;
4595
 	char message[80];
4596
 
4597
-	switch(portType) {
4598
+	switch(portType)
4599
+	{
4600
 		case PORT_TYPE_SERIAL:
4601
-#if defined(__APPLE__)
4602
-			if (registerKnownSerialPorts(env, jobj,
4603
-				PORT_TYPE_SERIAL) > 0) {/* dima */
4604
-				result = JNI_TRUE;
4605
-			}
4606
-#endif
4607
-           		 break;
4608
-		case PORT_TYPE_PARALLEL: break;
4609
-		case PORT_TYPE_I2C:      break;
4610
-		case PORT_TYPE_RS485:    break;
4611
-		case PORT_TYPE_RAW:      break;
4612
+			#if defined(__APPLE__)
4613
+				if (registerKnownSerialPorts(env, jobj, PORT_TYPE_SERIAL) > 0)
4614
+				{
4615
+					/* dima */
4616
+					result = JNI_TRUE;
4617
+				}
4618
+			#endif
4619
+			break;
4620
+			
4621
+		case PORT_TYPE_PARALLEL: 
4622
+			break;
4623
+			
4624
+		case PORT_TYPE_I2C:	
4625
+			break;
4626
+			
4627
+		case PORT_TYPE_RS485:	
4628
+			break;
4629
+			
4630
+		case PORT_TYPE_RAW:	
4631
+			break;
4632
+			
4633
 		default:
4634
-			sprintf( message, "unknown portType %d handed to \
4635
-				native RXTXCommDriver.registerKnownPorts() \
4636
-				 method.\n",
4637
-				(int) portType
4638
-			);
4639
+			memset(&message[0], 0, sizeof(message));
4640
+			sprintf( message, "RXTXCommDriver_registerKnownPorts Unknown portType %d handed to native RXTXCommDriver.registerKnownPorts() method.\n", (int) portType);
4641
 			report( message );
4642
 	}
4643
+	memset(&strbuf[0], 0, sizeof(strbuf));
4644
+	sprintf(strbuf, "Leaving - RXTXCommDriver_registerKnownPorts(%i)\n", result);
4645
+	report(strbuf);
4646
+	
4647
 	return result;
4648
 }
4649
 
4650
 /*----------------------------------------------------------
4651
  isPortPrefixValid
4652
 
4653
-   accept:      a port prefix
4654
-   perform:     see if the port prefix matches a port that is valid on this OS.
4655
-   return:      JNI_TRUE if it exists otherwise JNI_FALSE
4656
-   exceptions:  none
4657
-   comments:
4658
+	accept:		a port prefix
4659
+	perform:	see if the port prefix matches a port that is valid on this OS.
4660
+	return:		JNI_TRUE if it exists otherwise JNI_FALSE
4661
+	exceptions:	none
4662
+	comments:
4663
 ----------------------------------------------------------*/
4664
 JNIEXPORT jboolean  JNICALL RXTXCommDriver(isPortPrefixValid)(JNIEnv *env,
4665
 	jobject jobj, jstring tty_name)
4666
@@ -4686,87 +4929,106 @@
4667
 	jboolean result;
4668
 	static struct stat mystat;
4669
 	char teststring[256];
4670
+	char strbuf[256];
4671
 	int fd,i;
4672
 	const char *name = (*env)->GetStringUTFChars(env, tty_name, 0);
4673
 
4674
-	ENTER( "RXTXCommDriver:isPortPrefixValid" );
4675
-	for(i=0;i<64;i++){
4676
-#if defined(__sun__)
4677
-		/* Solaris uses /dev/cua/a instead of /dev/cua0 */
4678
-		if( i > 25 ) break;
4679
-		sprintf(teststring,"%s%s%c",DEVICEDIR, name, i + 97 );
4680
-		fprintf(stderr, "testing: %s\n", teststring);
4681
-#else
4682
-#if defined(_GNU_SOURCE)
4683
-		snprintf(teststring, 256, "%s%s%i",DEVICEDIR,name, i);
4684
-#else
4685
-		sprintf(teststring,"%s%s%i",DEVICEDIR,name, i);
4686
-#endif /* _GNU_SOURCE */
4687
-		stat(teststring,&mystat);
4688
-#endif /* __sun__ */
4689
-/* XXX the following hoses freebsd when it tries to open the port later on */
4690
-#ifndef __FreeBSD__
4691
-		if(S_ISCHR(mystat.st_mode)){
4692
-			fd=OPEN(teststring,O_RDONLY|O_NONBLOCK);
4693
-			if (fd>0){
4694
-				CLOSE(fd);
4695
-				result=JNI_TRUE;
4696
-				break;
4697
+	report( "Entering - RXTXCommDriver:isPortPrefixValid\n" );
4698
+	for(i=0;i<64;i++)
4699
+	{
4700
+		#if defined(__sun__)
4701
+			/* Solaris uses /dev/cua/a instead of /dev/cua0 */
4702
+			if( i > 25 ) break;
4703
+			sprintf(teststring,"%s%s%c\n",DEVICEDIR, name, i + 97 );
4704
+			fprintf(stderr, "testing: %s\n", teststring);
4705
+		#else
4706
+			#if defined(_GNU_SOURCE)
4707
+				snprintf(teststring, 256, "%s%s%i\n",DEVICEDIR,name, i);
4708
+			#else
4709
+				sprintf(teststring,"%s%s%i\n",DEVICEDIR,name, i);
4710
+			#endif /* _GNU_SOURCE */
4711
+			stat(teststring,&mystat);
4712
+		#endif /* __sun__ */
4713
+
4714
+		/* XXX the following hoses freebsd when it tries to open the port later on */
4715
+		#ifndef __FreeBSD__
4716
+			if(S_ISCHR(mystat.st_mode))
4717
+			{
4718
+				fd=OPEN(teststring,O_RDONLY|O_NONBLOCK);
4719
+				if (fd>0)
4720
+				{
4721
+					CLOSE(fd);
4722
+					result=JNI_TRUE;
4723
+					break;
4724
+				}
4725
+				else
4726
+				{
4727
+					result=JNI_FALSE;
4728
+				}
4729
 			}
4730
 			else
4731
+			{
4732
 				result=JNI_FALSE;
4733
-		}
4734
-		else
4735
-			result=JNI_FALSE;
4736
-#else
4737
-		result=JNI_TRUE;
4738
-#endif  /* __FreeBSD __ */
4739
+			}
4740
+		#else
4741
+			result=JNI_TRUE;
4742
+		#endif  /* __FreeBSD __ */
4743
 	}
4744
-#if defined(_GNU_SOURCE)
4745
-	snprintf(teststring, 256, "%s%s",DEVICEDIR,name);
4746
-#else
4747
-	sprintf(teststring,"%s%s",DEVICEDIR,name);
4748
-#endif /* _GNU_SOURCE */
4749
+	
4750
+	#if defined(_GNU_SOURCE)
4751
+		snprintf(teststring, 256, "%s%s",DEVICEDIR,name);
4752
+	#else
4753
+		sprintf(teststring,"%s%s",DEVICEDIR,name);
4754
+	#endif /* _GNU_SOURCE */
4755
+	
4756
 	stat(teststring,&mystat);
4757
-	if(S_ISCHR(mystat.st_mode)){
4758
+	
4759
+	if(S_ISCHR(mystat.st_mode))
4760
+	{
4761
 		fd=OPEN(teststring,O_RDONLY|O_NONBLOCK);
4762
-		if (fd>0){
4763
+		if (fd>0)
4764
+		{
4765
 			CLOSE(fd);
4766
 			result=JNI_TRUE;
4767
 		}
4768
 	}
4769
+	
4770
 	(*env)->ReleaseStringUTFChars(env, tty_name, name);
4771
-	LEAVE( "RXTXCommDriver:isPortPrefixValid" );
4772
+	
4773
+	memset(&strbuf[0], 0, sizeof(strbuf));
4774
+	sprintf(strbuf, "Leaving - RXTXCommDriver:isPortPrefixValid(%i)\n", result);
4775
+	report(strbuf);
4776
+	
4777
 	return(result);
4778
 }
4779
 
4780
 /*----------------------------------------------------------
4781
  getDeviceDirectory
4782
 
4783
-   accept:
4784
-   perform:
4785
-   return:      the directory containing the device files
4786
-   exceptions:
4787
-   comments:    use this to avoid hard coded "/dev/"
4788
-   		values are in SerialImp.h
4789
+	accept:
4790
+	perform:
4791
+	return:		the directory containing the device files
4792
+	exceptions:
4793
+	comments:	use this to avoid hard coded "/dev/"
4794
+				values are in SerialImp.h
4795
 ----------------------------------------------------------*/
4796
 
4797
 JNIEXPORT jstring  JNICALL RXTXCommDriver(getDeviceDirectory)(JNIEnv *env,
4798
 	jobject jobj)
4799
 {
4800
-	ENTER( "RXTXCommDriver:getDeviceDirectory" );
4801
+	report( "Entering - RXTXCommDriver:getDeviceDirectory\n" );
4802
 	return (*env)->NewStringUTF(env, DEVICEDIR);
4803
-	LEAVE( "RXTXCommDriver:getDeviceDirectory" );
4804
+	report( "Leaving - RXTXCommDriver:getDeviceDirectory\n" );
4805
 }
4806
 
4807
 /*----------------------------------------------------------
4808
  setInputBufferSize
4809
 
4810
-   accept:
4811
-   perform:
4812
-   return:      none
4813
-   exceptions:  none
4814
-   comments:    see fopen/fclose/fwrite/fread man pages.
4815
+	accept:
4816
+	perform:
4817
+	return:		none
4818
+	exceptions:	none
4819
+	comments:	see fopen/fclose/fwrite/fread man pages.
4820
 ----------------------------------------------------------*/
4821
 JNIEXPORT void JNICALL RXTXPort(setInputBufferSize)(JNIEnv *env,
4822
 	jobject jobj,  jint size )
4823
@@ -4777,11 +5039,11 @@
4824
 /*----------------------------------------------------------
4825
  getIputBufferSize
4826
 
4827
-   accept:
4828
-   perform:
4829
-   return:      none
4830
-   exceptions:  none
4831
-   comments:    see fopen/fclose/fwrite/fread man pages.
4832
+	accept:
4833
+	perform:
4834
+	return:		none
4835
+	exceptions:	none
4836
+	comments:	see fopen/fclose/fwrite/fread man pages.
4837
 ----------------------------------------------------------*/
4838
 JNIEXPORT jint JNICALL RXTXPort(getInputBufferSize)(JNIEnv *env,
4839
 	jobject jobj)
4840
@@ -4793,11 +5055,11 @@
4841
 /*----------------------------------------------------------
4842
  setOutputBufferSize
4843
 
4844
-   accept:
4845
-   perform:
4846
-   return:      none
4847
-   exceptions:  none
4848
-   comments:    see fopen/fclose/fwrite/fread man pages.
4849
+	accept:
4850
+	perform:
4851
+	return:		none
4852
+	exceptions:	none
4853
+	comments:	see fopen/fclose/fwrite/fread man pages.
4854
 ----------------------------------------------------------*/
4855
 JNIEXPORT void JNICALL RXTXPort(setOutputBufferSize)(JNIEnv *env,
4856
 	jobject jobj, jint size )
4857
@@ -4808,11 +5070,11 @@
4858
 /*----------------------------------------------------------
4859
  getOutputBufferSize
4860
 
4861
-   accept:
4862
-   perform:
4863
-   return:      none
4864
-   exceptions:  none
4865
-   comments:    see fopen/fclose/fwrite/fread man pages.
4866
+	accept:
4867
+	perform:
4868
+	return:		none
4869
+	exceptions:	none
4870
+	comments:	see fopen/fclose/fwrite/fread man pages.
4871
 ----------------------------------------------------------*/
4872
 JNIEXPORT jint JNICALL RXTXPort(getOutputBufferSize)(JNIEnv *env,
4873
 	jobject jobj)
4874
@@ -4824,23 +5086,33 @@
4875
 /*----------------------------------------------------------
4876
  interruptEventLoop
4877
 
4878
-   accept:      nothing
4879
-   perform:     increment eventloop_interrupted
4880
-   return:      nothing
4881
-   exceptions:  none
4882
-   comments:    all eventloops in this PID will check if their thread
4883
-		is interrupted.  When all the interrupted threads exit
4884
-		they will decrement the var leaving it 0.
4885
-		the remaining threads will continue.
4886
+	accept:		nothing
4887
+	perform:	increment eventloop_interrupted
4888
+	return:		nothing
4889
+	exceptions:	none
4890
+	comments:	all eventloops in this PID will check if their thread
4891
+				is interrupted.  When all the interrupted threads exit
4892
+				they will decrement the var leaving it 0.
4893
+				the remaining threads will continue.
4894
 ----------------------------------------------------------*/
4895
-JNIEXPORT void JNICALL RXTXPort(interruptEventLoop)(JNIEnv *env,
4896
-	jobject jobj)
4897
+JNIEXPORT void JNICALL RXTXPort(interruptEventLoop)(
4898
+	JNIEnv *env,
4899
+	jobject jobj
4900
+)
4901
 {
4902
+	report("Entering - RXTXPort_interruptEventLoop\n");
4903
+	
4904
 	struct event_info_struct *index = master_index;
4905
+	
4906
 	int fd = get_java_var( env, jobj, "fd", "I" );
4907
+	
4908
 	int searching = 1;
4909
-
4910
-
4911
+	int waiting = 1;
4912
+	int loop_count = 0;
4913
+	char buff[ 60 ] = "";
4914
+	
4915
+	report("RXTXPort_interruptEventLoop - Searching...\n");
4916
+	
4917
 	while( searching )
4918
 	{
4919
 		index = master_index;
4920
@@ -4852,63 +5124,161 @@
4921
 		}
4922
 		else
4923
 			report("x");
4924
+			
4925
 		if( searching )
4926
 		{
4927
 			report("@");
4928
 			usleep(1000);
4929
 		}
4930
 	}
4931
+	report("RXTXPort_interruptEventLoop - Searched\n");
4932
+	
4933
+	/**
4934
+	* We now set a flag for the drain_loop thread to jump to it's end.
4935
+	**/
4936
+	
4937
 	index->eventloop_interrupted = 1;
4938
-	/*
4939
-	Many OS's need a thread running to determine if output buffer is
4940
-	empty.  For Linux and Win32 it is not needed.  So closing is used to
4941
-	shut down the thread in the write order on OS's that don't have
4942
-	kernel support for output buffer empty.
4943
-
4944
-	In rxtx TIOCSERGETLSR is defined for win32 and Linux
4945
-	*/
4946
-#ifdef TIOCSERGETLSR
4947
-	index->closing=1;
4948
-#endif /* TIOCSERGETLSR */
4949
-#ifdef WIN32
4950
-	termios_interrupt_event_loop( index->fd, 1 );
4951
-#endif /* WIN32 */
4952
-#if !defined(TIOCSERGETLSR) && !defined(WIN32)
4953
-	/* make sure that the drainloop unblocks from tcdrain */
4954
-	pthread_kill(index->drain_tid, SIGABRT);
4955
-	/* TODO use wait/join/SIGCHLD/?? instead of sleep? */
4956
-	usleep(50 * 1000);
4957
-	/*
4958
-	Under normal conditions, SIGABRT will unblock tcdrain. However
4959
-	a non-responding USB device combined with an unclean driver
4960
-	may still block. This is very ugly because it may block the call
4961
-	to close indefinetly.
4962
-	*/
4963
-	if (index->closing != 1) {
4964
-		/* good bye tcdrain, and thanks for all the fish */
4965
-		report("interruptEventLoop: canceling blocked drain thread\n");
4966
-		pthread_cancel(index->drain_tid);
4967
-		index->closing = 1;
4968
-	}
4969
-#endif
4970
-	report("interruptEventLoop: interrupted\n");
4971
+	
4972
+	report("RXTXPort_interruptEventLoop - Interrupted\n");
4973
+	
4974
+	/**
4975
+	*	Many OS's need a thread running to determine if output buffer is
4976
+	*	empty.  For Linux and Win32 it is not needed.  So closing is
4977
+	*	used to shut down the thread in the write order on OS's that
4978
+	*	don't have kernel support for output buffer empty.
4979
+	*	
4980
+	*	In rxtx TIOCSERGETLSR:
4981
+	*		is defined for win32 and Linux
4982
+	* 		is not defined for FreeBSD 10.1-p9 i386
4983
+	*		Other OSs not tested; not available...
4984
+	*	
4985
+	*	(
4986
+	*		From looking at the RXTX source code tarball, TIOCSERGETLSR
4987
+	*		is only manually defined if on WinCE, unless set / supported
4988
+	*		by OS dependant c precompiler...
4989
+	*	)
4990
+	**/
4991
+	
4992
+	#ifdef TIOCSERGETLSR
4993
+		report("RXTXPort_interruptEventLoop - TIOCSERGETLSR defined\n");
4994
+		index->closing=1;
4995
+	#endif /* TIOCSERGETLSR */
4996
+	
4997
+	#ifdef WIN32
4998
+		report("RXTXPort_interruptEventLoop - WIN32 defined\n");
4999
+		termios_interrupt_event_loop( index->fd, 1 );
5000
+	#endif /* WIN32 */
5001
+	
5002
+	#if !defined(TIOCSERGETLSR) && !defined(WIN32)
5003
+	
5004
+		report("RXTXPort_interruptEventLoop - TIOCSERGETLSR and WIN32 not defined\n");
5005
+		/* make sure that the drainloop unblocks from tcdrain */
5006
+	
5007
+		/**
5008
+		*	JCE: This was supposed to kill off drain_loop...
5009
+		* 	CORE DUMP seen with original code on i386 FreeBSD v10.1-p9.
5010
+		*	
5011
+		* 	As eventloop_interrupted is set to 1 above, the attempted
5012
+		*	forced closure of the thread is now not needed: the thread
5013
+		*	kills its self off politely when it sees the flag.
5014
+		*	
5015
+		*	Going to wait 1/20th + 1 of the maximum sleep time
5016
+		*	(SUN = 5000, ANOs=1000000) and see if it has cancelled.
5017
+		* 	After 20 iterations we have waited for the entire sleep,
5018
+		*	at which point we just get on with it and will be caught by
5019
+		*	the good bye tcdrain code block at the end of this function.
5020
+		**/
5021
+		
5022
+		memset(&buff[0], 0, sizeof(buff));
5023
+		sprintf( buff, "RXTXPort_interruptEventLoop - Closing State is %i\n", index->closing );
5024
+		report (buff);
5025
+		
5026
+		report("RXTXPort_interruptEventLoop - Going to wait for thread to say it is closing\n");
5027
+		
5028
+		loop_count = 0;		
5029
+		while( waiting )
5030
+		{
5031
+			report("RXTXPort_interruptEventLoop - Waiting\n");
5032
+			usleep(5001);
5033
+			loop_count = loop_count + 1;
5034
+			if ((index->closing) == 1) waiting = 0;
5035
+			if (loop_count > 20) waiting = 0;
5036
+		}
5037
+		
5038
+		memset(&buff[0], 0, sizeof(buff));
5039
+		sprintf( buff, "RXTXPort_interruptEventLoop - Closing State is now %i\n", index->closing );
5040
+		report (buff);
5041
+		
5042
+		/**
5043
+		*	The command below was being sent to the relevant thread,
5044
+		*	however under POSIX spec this abort signal applies to the
5045
+		* 	whole process, NOT the thread.
5046
+		*	
5047
+		*	However, if RXTX is being call by something else in Java,
5048
+		*	this causes the parent enumaertor and the entire JRE to
5049
+		*	SIGABRT, resulting in a Java Core Dump (as requested)!
5050
+		*	
5051
+		*	Not sure what this call was supposed to achive; Have
5052
+		*	included new wait loop above to ensure that we wait for the
5053
+		*	thread to pick up that we have asked for it to exit:
5054
+		* 
5055
+		*		index->eventloop_interrupted = 1;
5056
+		*	
5057
+		*	No way for checking if an OS is POSIX compliant with
5058
+		*	pthread_kill, when TIOCSERGETLSR is not defined?
5059
+		**/ 	
5060
+		
5061
+		/**	
5062
+		*	pthread_kill(index->drain_tid, SIGABRT);	
5063
+		**/
5064
+		
5065
+		report("***RXTXPort_interruptEventLoop - Thread Killed\n");
5066
+		
5067
+		/* TODO use wait/join/SIGCHLD/?? instead of sleep? */
5068
+	
5069
+		report("RXTXPort_interruptEventLoop - Sleeping now...\n");
5070
+		usleep(50 * 1000);
5071
+		
5072
+		report("RXTXPort_interruptEventLoop - Waking up...\n");
5073
+		
5074
+		/**
5075
+		*	Under normal conditions, SIGABRT will unblock tcdrain. However
5076
+		*	a non-responding USB device combined with an unclean driver
5077
+		*	may still block. This is very ugly because it may block the call
5078
+		*	to close indefinetly.
5079
+		* 
5080
+		*	UPDATE to above statement:
5081
+		*		SIGABRT does not have the expected results in a
5082
+		*		POSIX environment.
5083
+		**/
5084
+	
5085
+		if (index->closing != 1) {
5086
+			/* good bye tcdrain, and thanks for all the fish */
5087
+			report("interruptEventLoop: canceling blocked drain thread\n");
5088
+			pthread_cancel(index->drain_tid);
5089
+			index->closing = 1;
5090
+		}
5091
+		
5092
+	#endif
5093
+	
5094
+	report("Leaving - interruptEventLoop\n");
5095
 }
5096
 
5097
 /*----------------------------------------------------------
5098
  is_interrupted
5099
 
5100
-   accept:      event_info_struct
5101
-   perform:     see if the port is being closed.
5102
-   return:      a positive value if the port is being closed.
5103
-   exceptions:  none
5104
-   comments:
5105
+	accept:		event_info_struct
5106
+	perform:	see if the port is being closed.
5107
+	return:		a positive value if the port is being closed.
5108
+	exceptions:	none
5109
+	comments:
5110
 ----------------------------------------------------------*/
5111
 jboolean is_interrupted( struct event_info_struct *eis )
5112
 {
5113
 	int result;
5114
 	JNIEnv *env = eis->env;
5115
 
5116
-	ENTER( "is_interrupted" );
5117
+	report( "Entering - is_interrupted\n" );
5118
 	(*env)->ExceptionClear(env);
5119
 	result = (*env)->CallBooleanMethod( env, *eis->jobj,
5120
 			eis->checkMonitorThread );
5121
@@ -4919,18 +5289,18 @@
5122
 		(*env)->ExceptionClear(env);
5123
 	}
5124
 #endif /* DEBUG */
5125
-	LEAVE( "RXTXCommDriver:is_interrupted" );
5126
+	report( "Leaving - RXTXCommDriver:is_interrupted\n" );
5127
 	return(result);
5128
 }
5129
 
5130
 /*----------------------------------------------------------
5131
  nativeSetEventFlag
5132
 
5133
-   accept:      fd for finding the struct, event to flag, flag.
5134
-   perform:     toggle the flag
5135
-   return:      none
5136
-   exceptions:  none
5137
-   comments:	all the logic used to be done in Java but its too noisy
5138
+	accept:	fd for finding the struct, event to flag, flag.
5139
+	perform:	toggle the flag
5140
+	return:		none
5141
+	exceptions:	none
5142
+	comments:	all the logic used to be done in Java but its too noisy
5143
 ----------------------------------------------------------*/
5144
 JNIEXPORT void JNICALL RXTXPort(nativeSetEventFlag)( JNIEnv *env,
5145
 							jobject jobj,
5146
@@ -4964,11 +5334,11 @@
5147
 /*----------------------------------------------------------
5148
  send_event
5149
 
5150
-   accept:      event_info_structure, event type and true/false
5151
-   perform:     if state is > 0 send a JNI_TRUE event otherwise send JNI_FALSE
5152
-   return:      a positive value if the port is being closed.
5153
-   exceptions:  none
5154
-   comments:
5155
+	accept:		event_info_structure, event type and true/false
5156
+	perform:	if state is > 0 send a JNI_TRUE event otherwise send JNI_FALSE
5157
+	return:		a positive value if the port is being closed.
5158
+	exceptions:	none
5159
+	comments:
5160
 ----------------------------------------------------------*/
5161
 int send_event( struct event_info_struct *eis, jint type, int flag )
5162
 {
5163
@@ -4977,7 +5347,7 @@
5164
 	if( eis ) env = eis->env;
5165
 	else return(-1);
5166
 
5167
-	ENTER( "send_event" );
5168
+	report( "Entering - send_event\n" );
5169
 	if( !eis || eis->eventloop_interrupted > 1 )
5170
 	{
5171
 		report("event loop interrupted\n");
5172
@@ -5002,18 +5372,18 @@
5173
 	}
5174
 #endif /* asdf */
5175
 	/* report("e"); */
5176
-	LEAVE( "send_event" );
5177
+	report( "Leaving - send_event\n" );
5178
 	return(result);
5179
 }
5180
 
5181
 /*----------------------------------------------------------
5182
 get_java_var
5183
 
5184
-   accept:      env (keyhole to java)
5185
-                jobj (java RXTXPort object)
5186
-   return:      the fd field from the java object
5187
-   exceptions:  none
5188
-   comments:
5189
+	accept:		env (keyhole to java)
5190
+			 	jobj (java RXTXPort object)
5191
+	return:		the fd field from the java object
5192
+	exceptions:	none
5193
+	comments:
5194
 ----------------------------------------------------------*/
5195
 size_t get_java_var( JNIEnv *env, jobject jobj, char *id, char *type ) {
5196
   return (size_t) get_java_var_long( env, jobj, id, type );
5197
@@ -5026,26 +5396,26 @@
5198
 	jfieldID jfd = (*env)->GetFieldID( env, jclazz, id, type );
5199
 
5200
 /*
5201
-	ENTER( "get_java_var" );
5202
+	report( "Entering - get_java_var\n" );
5203
 */
5204
 	if( !jfd ) {
5205
 		(*env)->ExceptionDescribe( env );
5206
 		(*env)->ExceptionClear( env );
5207
 		(*env)->DeleteLocalRef( env, jclazz );
5208
-		LEAVE( "get_java_var" );
5209
+		report( "Leaving - get_java_var\n" );
5210
 		return result;
5211
 	}
5212
 	if ( !strcmp( type, "J" ) ) {
5213
-	  result = (long)( (*env)->GetLongField( env, jobj, jfd ) );
5214
+	 result = (long)( (*env)->GetLongField( env, jobj, jfd ) );
5215
 	} else {
5216
-	  result = (size_t) ( (*env)->GetIntField( env, jobj, jfd ) );
5217
+	 result = (size_t) ( (*env)->GetIntField( env, jobj, jfd ) );
5218
 	}
5219
 /* ct7 & gel * Added DeleteLocalRef */
5220
 	(*env)->DeleteLocalRef( env, jclazz );
5221
 	if(!strncmp( "fd",id,2) && result == 0)
5222
 		report_error( "get_java_var: invalid file descriptor\n" );
5223
 /*
5224
-	LEAVE( "get_java_var" );
5225
+	report( "Leaving - get_java_var\n" );
5226
 */
5227
 	return result;
5228
 }
5229
@@ -5053,110 +5423,132 @@
5230
 /*----------------------------------------------------------
5231
 throw_java_exception
5232
 
5233
-   accept:      env (keyhole to java)
5234
-                *exc (exception class name)
5235
-                *foo (function name)
5236
-                *msg (error message)
5237
-   perform:     Throw a new java exception
5238
-   return:      none
5239
-   exceptions:  haha!
5240
-   comments:
5241
+	accept:		env (keyhole to java)
5242
+				*exc (exception class name)
5243
+				*foo (function name)
5244
+				*msg (error message)
5245
+	perform:	Throw a new java exception
5246
+	return:		none
5247
+	exceptions:	haha!
5248
+	comments:
5249
 ----------------------------------------------------------*/
5250
 void throw_java_exception( JNIEnv *env, char *exc, char *foo, char *msg )
5251
 {
5252
 	char buf[ 60 ];
5253
 	jclass clazz = (*env)->FindClass( env, exc );
5254
-	ENTER( "throw_java_exception" );
5255
+	report( "Entering - throw_java_exception\n" );
5256
 	if( !clazz ) {
5257
 		(*env)->ExceptionDescribe( env );
5258
 		(*env)->ExceptionClear( env );
5259
-		LEAVE( "throw_java_exception" );
5260
+		report( "Leaving - throw_java_exception\n" );
5261
 		return;
5262
 	}
5263
+	memset(&buf[0], 0, sizeof(buf));
5264
 #if defined(_GNU_SOURCE)
5265
-	snprintf( buf, 60, "%s in %s", msg, foo );
5266
+	snprintf( buf, 60, "%s in %s\n", msg, foo );
5267
 #else
5268
-	sprintf( buf,"%s in %s", msg, foo );
5269
+	sprintf( buf,"%s in %s\n", msg, foo );
5270
 #endif /* _GNU_SOURCE */
5271
 	(*env)->ThrowNew( env, clazz, buf );
5272
 /* ct7 * Added DeleteLocalRef */
5273
 	(*env)->DeleteLocalRef( env, clazz );
5274
-	LEAVE( "throw_java_exception" );
5275
+	report( "Leaving - throw_java_exception\n" );
5276
 }
5277
 
5278
 /*----------------------------------------------------------
5279
  report_warning
5280
 
5281
-   accept:      string to send to report as an message
5282
-   perform:     send the string to stderr or however it needs to be reported.
5283
-   return:      none
5284
-   exceptions:  none
5285
-   comments:
5286
+	accept:		string to send to report as an message
5287
+	perform:	send the string to stderr or however it needs to be reported.
5288
+	return:		none
5289
+	exceptions:	none
5290
+	comments:
5291
 ----------------------------------------------------------*/
5292
 void report_warning(char *msg)
5293
 {
5294
-#ifndef DEBUG_MW
5295
-	fprintf(stderr, msg);
5296
-#else
5297
-	mexWarnMsgTxt( (const char *) msg );
5298
-#endif /* DEBUG_MW */
5299
+	
5300
+	#if defined(DEBUG_STDOUT)
5301
+		report(msg);
5302
+	#endif
5303
+	
5304
+	#ifdef DEBUG
5305
+		fprintf(stderr, "%s", msg);
5306
+	#endif
5307
+	
5308
 }
5309
 
5310
 /*----------------------------------------------------------
5311
  report_verbose
5312
 
5313
-   accept:      string to send to report as an verbose message
5314
-   perform:     send the string to stderr or however it needs to be reported.
5315
-   return:      none
5316
-   exceptions:  none
5317
-   comments:
5318
+	accept:		string to send to report as an verbose message
5319
+	perform:	send the string to stderr or however it needs to be reported.
5320
+	return:		none
5321
+	exceptions:	none
5322
+	comments:
5323
 ----------------------------------------------------------*/
5324
 void report_verbose(char *msg)
5325
 {
5326
-#ifdef DEBUG_VERBOSE
5327
-#ifdef DEBUG_MW
5328
-	mexErrMsgTxt( msg );
5329
-#else
5330
-	fprintf(stderr, msg);
5331
-#endif /* DEBUG_MW */
5332
-#endif /* DEBUG_VERBOSE */
5333
+	
5334
+	#if defined(DEBUG_STDOUT)
5335
+		report(msg);
5336
+	#endif
5337
+	
5338
+	#ifdef DEBUG
5339
+		fprintf(stderr, "%s", msg);
5340
+	#endif
5341
+	
5342
 }
5343
 /*----------------------------------------------------------
5344
  report_error
5345
 
5346
-   accept:      string to send to report as an error
5347
-   perform:     send the string to stderr or however it needs to be reported.
5348
-   return:      none
5349
-   exceptions:  none
5350
-   comments:
5351
+	accept:	string to send to report as an error
5352
+	perform:	send the string to stderr or however it needs to be reported.
5353
+	return:		none
5354
+	exceptions:	none
5355
+	comments:
5356
 ----------------------------------------------------------*/
5357
 void report_error(char *msg)
5358
 {
5359
-#ifndef DEBUG_MW
5360
-	fprintf(stderr, msg);
5361
-#else
5362
-	mexWarnMsgTxt( msg );
5363
-#endif /* DEBUG_MW */
5364
+	
5365
+	#if defined(DEBUG_STDOUT)
5366
+		report(msg);
5367
+	#endif
5368
+	
5369
+	#ifdef DEBUG
5370
+		fprintf(stderr, "%s", msg);
5371
+	#endif
5372
+	
5373
 }
5374
 
5375
 /*----------------------------------------------------------
5376
  report
5377
 
5378
-   accept:      string to send to stderr
5379
-   perform:     if DEBUG is defined send the string to stderr.
5380
-   return:      none
5381
-   exceptions:  none
5382
-   comments:
5383
+	accept:	string to send to stderr
5384
+	perform:	if DEBUG is defined send the string to stderr.
5385
+	return:		none
5386
+	exceptions:	none
5387
+	comments:
5388
 ----------------------------------------------------------*/
5389
 void report(char *msg)
5390
 {
5391
-#ifdef DEBUG
5392
-#	ifndef DEBUG_MW
5393
-		fprintf(stderr, msg);
5394
-#	else
5395
-		mexPrintf( msg );
5396
-#	endif /* DEBUG_MW */
5397
-#endif /* DEBUG */
5398
+	#if defined(DEBUG_STDOUT)
5399
+		
5400
+		char message[1024] = "";
5401
+		char fmsg[1024] = "";
5402
+		
5403
+		memset(&fmsg[0], 0, sizeof(fmsg));
5404
+		strcat ( fmsg, "SerialImp.c: " );
5405
+		strcat ( fmsg, msg );
5406
+		
5407
+		memset(&message[0], 0, sizeof(message));
5408
+		sprintf( message, "%s", fmsg);
5409
+		fprintf(stdout, "%s", message);
5410
+		
5411
+	#endif
5412
+	
5413
+	#ifdef DEBUG
5414
+		fprintf(stderr, "%s", msg);
5415
+	#endif /* DEBUG */
5416
 }
5417
 
5418
 #ifndef WIN32
5419
@@ -5164,12 +5556,12 @@
5420
 /*----------------------------------------------------------
5421
  lfs_lock
5422
 
5423
-   accept:      The name of the device to try to lock
5424
-   perform:     Create a lock file if there is not one already using a
5425
-                lock file server.
5426
-   return:      1 on failure 0 on success
5427
-   exceptions:  none
5428
-   comments:
5429
+	accept:		The name of the device to try to lock
5430
+	perform:	Create a lock file if there is not one already using a
5431
+				lock file server.
5432
+	return:		1 on failure 0 on success
5433
+	exceptions:	none
5434
+	comments:
5435
 
5436
 ----------------------------------------------------------*/
5437
 int lfs_lock( const char *filename, int pid )
5438
@@ -5189,7 +5581,7 @@
5439
 	if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 )
5440
 		return 1;
5441
 	ret=recv( s, buffer, size, 0 );
5442
-	sprintf( buffer, "lock %s %i\n", filename, pid );
5443
+	sprintf( buffer, "lock %s %i", filename, pid );
5444
 	/* printf( "%s", buffer ); */
5445
 	send( s, buffer, strlen(buffer), 0 );
5446
 	ret=recv( s, buffer, size, 0 );
5447
@@ -5208,12 +5600,12 @@
5448
 /*----------------------------------------------------------
5449
  lfs_unlock
5450
 
5451
-   accept:      The name of the device to try to unlock
5452
-   perform:     Remove a lock file if there is one using a
5453
-                lock file server.
5454
-   return:      1 on failure 0 on success
5455
-   exceptions:  none
5456
-   comments:
5457
+	accept:		The name of the device to try to unlock
5458
+	perform:	Remove a lock file if there is one using a
5459
+				lock file server.
5460
+	return:		1 on failure 0 on success
5461
+	exceptions:	none
5462
+	comments:
5463
 
5464
 ----------------------------------------------------------*/
5465
 int lfs_unlock( const char *filename, int pid )
5466
@@ -5232,7 +5624,7 @@
5467
 
5468
 	if ( !connect( s, ( struct sockaddr * ) &addr, sizeof( addr ) ) == 0 )
5469
 		return 1;
5470
-	sprintf( buffer, "unlock %s %i\n", filename, pid );
5471
+	sprintf( buffer, "unlock %s %i", filename, pid );
5472
 	/* printf( "%s", buffer ); */
5473
 	send( s, buffer, strlen(buffer), 0 );
5474
 	ret = recv( s, buffer, size, 0 );
5475
@@ -5251,14 +5643,14 @@
5476
 /*----------------------------------------------------------
5477
  lib_lock_dev_unlock
5478
 
5479
-   accept:      The name of the device to try to unlock
5480
-   perform:     Remove a lock file if there is one using a
5481
-                lock file server.
5482
-   return:      1 on failure 0 on success
5483
-   exceptions:  none
5484
-   comments:    This is for use with liblockdev which comes with Linux
5485
-		distros.  I suspect it will be problematic with embeded
5486
-		Linux.   taj
5487
+	accept:		The name of the device to try to unlock
5488
+	perform:	Remove a lock file if there is one using a
5489
+				lock file server.
5490
+	return:		1 on failure 0 on success
5491
+	exceptions:	none
5492
+	comments:	This is for use with liblockdev which comes with Linux
5493
+				distros. I suspect it will be problematic with embeded
5494
+				Linux.	taj
5495
 
5496
 ----------------------------------------------------------*/
5497
 #ifdef LIBLOCKDEV
5498
@@ -5276,17 +5668,17 @@
5499
 /*----------------------------------------------------------
5500
  lib_lock_dev_lock
5501
 
5502
-   accept:      The name of the device to try to lock
5503
-                termios struct
5504
-   perform:     Create a lock file if there is not one already.
5505
-   return:      1 on failure 0 on success
5506
-   exceptions:  none
5507
-   comments:    This is for use with liblockdev which comes with Linux
5508
-		distros.  I suspect it will be problematic with embeded
5509
-		Linux.   taj
5510
+	accept:		The name of the device to try to lock
5511
+				termios struct
5512
+	perform:	Create a lock file if there is not one already.
5513
+	return:		1 on failure 0 on success
5514
+	exceptions:	none
5515
+	comments:	This is for use with liblockdev which comes with Linux
5516
+				distros.  I suspect it will be problematic with embeded
5517
+				Linux.	taj
5518
 
5519
-		One could load the library here rather than link it and
5520
-		always try to use this.
5521
+				One could load the library here rather than link it and
5522
+				always try to use this.
5523
 
5524
 ----------------------------------------------------------*/
5525
 #ifdef LIBLOCKDEV
5526
@@ -5301,6 +5693,7 @@
5527
 	}
5528
 	if ( dev_lock( filename ) )
5529
 	{
5530
+		memset(&message[0], 0, sizeof(message));
5531
 		sprintf( message,
5532
 			"RXTX fhs_lock() Error: creating lock file for: %s: %s\n",
5533
 			filename, strerror(errno) );
5534
@@ -5314,27 +5707,24 @@
5535
 /*----------------------------------------------------------
5536
  fhs_lock
5537
 
5538
-   accept:      The name of the device to try to lock
5539
-                termios struct
5540
-   perform:     Create a lock file if there is not one already.
5541
-   return:      1 on failure 0 on success
5542
-   exceptions:  none
5543
-   comments:    This is for linux and freebsd only currently.  I see SVR4 does
5544
-                this differently and there are other proposed changes to the
5545
-		Filesystem Hierachy Standard
5546
-
5547
-		more reading:
5548
-
5549
+	accept:		The name of the device to try to lock
5550
+				termios struct
5551
+	perform:	Create a lock file if there is not one already.
5552
+	return:		1 on failure 0 on success
5553
+	exceptions:	none
5554
+	comments:	This is for linux and freebsd only currently.  I see SVR4 does
5555
+				this differently and there are other proposed changes to the
5556
+				Filesystem Hierachy Standard
5557
 ----------------------------------------------------------*/
5558
 int fhs_lock( const char *filename, int pid )
5559
 {
5560
 	/*
5561
-	 * There is a zoo of lockdir possibilities
5562
-	 * Its possible to check for stale processes with most of them.
5563
-	 * for now we will just check for the lockfile on most
5564
-	 * Problem lockfiles will be dealt with.  Some may not even be in use.
5565
-	 *
5566
-	 */
5567
+	* There is a zoo of lockdir possibilities
5568
+	* Its possible to check for stale processes with most of them.
5569
+	* for now we will just check for the lockfile on most
5570
+	* Problem lockfiles will be dealt with.  Some may not even be in use.
5571
+	*
5572
+	*/
5573
 	int fd,j;
5574
 	char lockinfo[12], message[80];
5575
 	char file[80], *p;
5576
@@ -5342,7 +5732,7 @@
5577
 	j = strlen( filename );
5578
 	p = ( char * ) filename + j;
5579
 	/*  FIXME  need to handle subdirectories /dev/cua/...
5580
-	    SCO Unix use lowercase all the time
5581
+		SCO Unix use lowercase all the time
5582
 			taj
5583
 	*/
5584
 	while( *( p - 1 ) != '/' && j-- != 1 )
5585
@@ -5361,13 +5751,15 @@
5586
 	fd = open( file, O_CREAT | O_WRONLY | O_EXCL, 0444 );
5587
 	if( fd < 0 )
5588
 	{
5589
+		memset(&message[0], 0, sizeof(message));
5590
 		sprintf( message,
5591
 			"RXTX fhs_lock() Error: creating lock file: %s: %s\n",
5592
 			file, strerror(errno) );
5593
 		report_error( message );
5594
 		return 1;
5595
 	}
5596
-	sprintf( lockinfo, "%10d\n",(int) getpid() );
5597
+	sprintf( lockinfo, "%10d",(int) getpid() );
5598
+	memset(&message[0], 0, sizeof(message));
5599
 	sprintf( message, "fhs_lock: creating lockfile: %s\n", lockinfo );
5600
 	report( message );
5601
 	write( fd, lockinfo, 11 );
5602
@@ -5378,11 +5770,12 @@
5603
 /*----------------------------------------------------------
5604
  uucp_lock
5605
 
5606
-   accept:     char * filename.  Device to be locked
5607
-   perform:    Try to get a uucp_lock
5608
-   return:     int 0 on success
5609
-   exceptions: none
5610
-   comments:
5611
+	accept:		char * filename.  Device to be locked
5612
+	perform:	Try to get a uucp_lock
5613
+	return:		int 0 on success
5614
+	exceptions: none
5615
+	comments:
5616
+	
5617
 		The File System Hierarchy Standard
5618
 		http://www.pathname.com/fhs/
5619
 
5620
@@ -5408,9 +5801,9 @@
5621
 			/var/lock
5622
 		4) handle stale locks  (done except kermit locks)
5623
 		5) handle minicom lockfile contents (FSSTND?)
5624
-			"     16929 minicom root\n"  (done)
5625
+			"	16929 minicom root\n"  (done)
5626
 		6) there are other Lock conventions that use Major and Minor
5627
-		   numbers...
5628
+			numbers...
5629
 		7) Stevens recommends LCK..<pid>
5630
 
5631
 		most are caught above.  If they turn out to be problematic
5632
@@ -5424,7 +5817,8 @@
5633
 	int fd;
5634
 	struct stat buf;
5635
 
5636
-	sprintf( message, "uucp_lock( %s );\n", filename );
5637
+	memset(&message[0], 0, sizeof(message));
5638
+	sprintf( message, "uucp_lock(%s)\n", filename );
5639
 	report( message );
5640
 
5641
 	if ( check_lock_status( filename ) )
5642
@@ -5432,55 +5826,75 @@
5643
 		report( "RXTX uucp check_lock_status true\n" );
5644
 		return 1;
5645
 	}
5646
+	report("uucp_lock - getting STAT on lock dir\n");
5647
 	if ( stat( LOCKDIR, &buf ) != 0 )
5648
 	{
5649
 		report( "RXTX uucp_lock() could not find lock directory.\n" );
5650
 		return 1;
5651
 	}
5652
+	
5653
+	report("uucp_lock - getting STAT on filename\n");
5654
 	if ( stat( filename, &buf ) != 0 )
5655
 	{
5656
+		memset(&message[0], 0, sizeof(message));
5657
 		report( "RXTX uucp_lock() could not find device.\n" );
5658
 		sprintf( message, "uucp_lock: device was %s\n", name );
5659
 		report( message );
5660
 		return 1;
5661
 	}
5662
+	report("uucp_lock - generating lock filename\n");
5663
 	sprintf( lockfilename, "%s/LK.%03d.%03d.%03d",
5664
 		LOCKDIR,
5665
 		(int) major( buf.st_dev ),
5666
-	 	(int) major( buf.st_rdev ),
5667
+		(int) major( buf.st_rdev ),
5668
 		(int) minor( buf.st_rdev )
5669
 	);
5670
-	sprintf( lockinfo, "%10d\n", (int) getpid() );
5671
+	report("uucp_lock - generating lock info\n");
5672
+	sprintf( lockinfo, "%10d", (int) getpid() );
5673
+	
5674
+	report("uucp_lock - getting STAT on lock filename\n");
5675
 	if ( stat( lockfilename, &buf ) == 0 )
5676
 	{
5677
+		memset(&message[0], 0, sizeof(message));
5678
 		sprintf( message, "RXTX uucp_lock() %s is there\n",
5679
 			lockfilename );
5680
 		report( message );
5681
 		report_error( message );
5682
 		return 1;
5683
 	}
5684
+	
5685
+	report("uucp_lock - Opening lock file\n");
5686
 	fd = open( lockfilename, O_CREAT | O_WRONLY | O_EXCL, 0444 );
5687
+	
5688
+	
5689
 	if( fd < 0 )
5690
 	{
5691
+		memset(&message[0], 0, sizeof(message));
5692
 		sprintf( message,
5693
 			"RXTX uucp_lock() Error: creating lock file: %s\n",
5694
 			lockfilename );
5695
 		report_error( message );
5696
 		return 1;
5697
 	}
5698
+	else
5699
+	{
5700
+		report("uucp_lock - lock file created\n");
5701
+	}
5702
 	write( fd, lockinfo,11 );
5703
+	report("uucp_lock - Writen lockinfo, closing on lock filen\n");
5704
 	close( fd );
5705
+	report("uucp_lock - returning (0)\n");
5706
 	return 0;
5707
 }
5708
 
5709
 /*----------------------------------------------------------
5710
  check_lock_status
5711
 
5712
-   accept:      the lock name in question
5713
-   perform:     Make sure everything is sane
5714
-   return:      0 on success
5715
-   exceptions:  none
5716
-   comments:
5717
+	accept:	the lock name in question
5718
+	perform:	Make sure everything is sane
5719
+	return:	0 on success
5720
+	exceptions:	none
5721
+	comments:
5722
 ----------------------------------------------------------*/
5723
 int check_lock_status( const char *filename )
5724
 {
5725
@@ -5515,13 +5929,13 @@
5726
 /*----------------------------------------------------------
5727
  fhs_unlock
5728
 
5729
-   accept:      The name of the device to unlock
5730
-   perform:     delete the lock file
5731
-   return:      none
5732
-   exceptions:  none
5733
-   comments:    This is for linux only currently.  I see SVR4 does this
5734
-                differently and there are other proposed changes to the
5735
-		Filesystem Hierachy Standard
5736
+	accept:		The name of the device to unlock
5737
+	perform:	delete the lock file
5738
+	return:		none
5739
+	exceptions:	none
5740
+	comments:	This is for linux only currently.  I see SVR4 does this
5741
+				differently and there are other proposed changes to the
5742
+				Filesystem Hierachy Standard
5743
 ----------------------------------------------------------*/
5744
 void fhs_unlock( const char *filename, int openpid )
5745
 {
5746
@@ -5548,11 +5962,11 @@
5747
 /*----------------------------------------------------------
5748
  uucp_unlock
5749
 
5750
-   accept:     char *filename the device that is locked
5751
-   perform:    remove the uucp lockfile if it exists
5752
-   return:     none
5753
-   exceptions: none
5754
-   comments:   http://docs.freebsd.org/info/uucp/uucp.info.UUCP_Lock_Files.html
5755
+	accept:		char *filename the device that is locked
5756
+	perform:	remove the uucp lockfile if it exists
5757
+	return:		none
5758
+	exceptions: none
5759
+	comments:	http://docs.freebsd.org/info/uucp/uucp.info.UUCP_Lock_Files.html
5760
 ----------------------------------------------------------*/
5761
 void uucp_unlock( const char *filename, int openpid )
5762
 {
5763
@@ -5560,34 +5974,46 @@
5764
 	char file[80], message[80];
5765
 	/* FIXME */
5766
 
5767
-	sprintf( message, "uucp_unlock( %s );\n", filename );
5768
+	memset(&message[0], 0, sizeof(message));
5769
+	sprintf( message, "uucp_unlock(%s);\n", filename );
5770
 	report( message );
5771
 
5772
 	if ( stat( filename, &buf ) != 0 )
5773
 	{
5774
 		/* hmm the file is not there? */
5775
-		report( "uucp_unlock() no such device\n" );
5776
+		report( "uucp_unlock() - no such device\n" );
5777
 		return;
5778
 	}
5779
+	else
5780
+	{	
5781
+		report( "uucp_unlock() - device exists\n" );
5782
+	}
5783
+	
5784
 	sprintf( file, LOCKDIR"/LK.%03d.%03d.%03d",
5785
 		(int) major( buf.st_dev ),
5786
-	 	(int) major( buf.st_rdev ),
5787
+		(int) major( buf.st_rdev ),
5788
 		(int) minor( buf.st_rdev )
5789
 	);
5790
+	
5791
+	report( "uucp_unlock() - going to stat\n" );
5792
 	if ( stat( file, &buf ) != 0 )
5793
 	{
5794
 		/* hmm the file is not there? */
5795
 		report( "uucp_unlock no such lockfile\n" );
5796
 		return;
5797
 	}
5798
+	report( "uucp_unlock() - going to check lock pid\n" );
5799
 	if( !check_lock_pid( file, openpid ) )
5800
 	{
5801
+		memset(&message[0], 0, sizeof(message));
5802
 		sprintf( message, "uucp_unlock: unlinking %s\n", file );
5803
 		report( message );
5804
 		unlink(file);
5805
+		report( "uucp_unlock() - Unlink completed\n" );
5806
 	}
5807
 	else
5808
 	{
5809
+		memset(&message[0], 0, sizeof(message));
5810
 		sprintf( message, "uucp_unlock: unlinking failed %s\n", file );
5811
 		report( message );
5812
 	}
5813
@@ -5596,11 +6022,11 @@
5814
 /*----------------------------------------------------------
5815
  check_lock_pid
5816
 
5817
-   accept:     the name of the lockfile
5818
-   perform:    make sure the lock file is ours.
5819
-   return:     0 on success
5820
-   exceptions: none
5821
-   comments:
5822
+	accept:		the name of the lockfile
5823
+	perform:	make sure the lock file is ours.
5824
+	return:		0 on success
5825
+	exceptions: none
5826
+	comments:
5827
 ----------------------------------------------------------*/
5828
 int check_lock_pid( const char *file, int openpid )
5829
 {
5830
@@ -5624,6 +6050,7 @@
5831
 	/* Native threads JVM's have multiple pids */
5832
 	if ( lockpid != getpid() && lockpid != getppid() && lockpid != openpid )
5833
 	{
5834
+		memset(&message[0], 0, sizeof(message));
5835
 		sprintf(message, "check_lock_pid: lock = %s pid = %i gpid=%i openpid=%i\n",
5836
 			pid_buffer, (int) getpid(), (int) getppid(), openpid );
5837
 		report( message );
5838
@@ -5635,16 +6062,17 @@
5839
 /*----------------------------------------------------------
5840
  check_group_uucp
5841
 
5842
-   accept:     none
5843
-   perform:    check if the user is root or in group uucp
5844
-   return:     0 on success
5845
-   exceptions: none
5846
-   comments:
5847
+	accept:		none
5848
+	perform:	check if the user is root or in group uucp
5849
+	return:		0 on success
5850
+	exceptions: none
5851
+	comments:
5852
 		This checks if the effective user is in group uucp so we can
5853
 		create lock files.  If not we give them a warning and bail.
5854
 		If its root we just skip the test.
5855
 
5856
-		if someone really wants to override this they can use the			USER_LOCK_DIRECTORY --not recommended.
5857
+		if someone really wants to override this they can use the
5858
+		USER_LOCK_DIRECTORY --not recommended.
5859
 
5860
 		In a recent change RedHat 7.2 decided to use group lock.
5861
 		In order to get around this we just check the group id
5862
@@ -5674,7 +6102,7 @@
5863
 			+ strlen(testLockFileName) + 2, sizeof(char));
5864
 	if ( NULL == testLockAbsFileName )
5865
 	{
5866
-		report_error("check_group_uucp(): Insufficient memory");
5867
+		report_error("check_group_uucp(): Insufficient memory\n");
5868
 		return 1;
5869
 	}
5870
 	strcat(testLockAbsFileName, testLockFileDirName);
5871
@@ -5683,16 +6111,14 @@
5872
 	if ( NULL == mktemp(testLockAbsFileName) )
5873
 	{
5874
 		free(testLockAbsFileName);
5875
-		report_error("check_group_uucp(): mktemp malformed string - \
5876
-			should not happen");
5877
+		report_error("check_group_uucp(): mktemp malformed string - should not happen\n");
5878
 
5879
 		return 1;
5880
 	}
5881
 	testLockFile = fopen (testLockAbsFileName, "w+");
5882
 	if (NULL == testLockFile)
5883
 	{
5884
-		report_error("check_group_uucp(): error testing lock file "
5885
-			"creation Error details:");
5886
+		report_error("check_group_uucp(): error testing lock file creation Error details:\n");
5887
 		report_error(strerror(errno));
5888
 		free(testLockAbsFileName);
5889
 		return 1;
5890
@@ -5717,7 +6143,8 @@
5891
 
5892
 	if( stat( LOCKDIR, &buf) )
5893
 	{
5894
-		sprintf( msg, "check_group_uucp:  Can not find Lock Directory: %s\n", LOCKDIR );
5895
+		memset(&msg[0], 0, sizeof(msg));
5896
+		sprintf( msg, "check_group_uucp:	Can not find Lock Directory: %s\n", LOCKDIR );
5897
 		report_error( msg );
5898
 		return( 1 );
5899
 	}
5900
@@ -5741,6 +6168,7 @@
5901
 		}
5902
 		if( buf.st_gid == list[ group_count ] )
5903
 			return 0;
5904
+		memset(&msg[0], 0, sizeof(msg));
5905
 		sprintf( msg, "%i %i\n", buf.st_gid, list[ group_count ] );
5906
 		report_error( msg );
5907
 		report_error( UUCP_ERROR );
5908
@@ -5776,7 +6204,7 @@
5909
  for information.
5910
 
5911
  * realpath() doesn't exist on all of the systems my code has to run
5912
-   on (HP-UX 9.x, specifically)
5913
+	on (HP-UX 9.x, specifically)
5914
 ----------------------------------------------------------
5915
 int different_from_LOCKDIR(const char* ld)
5916
 {
5917
@@ -5798,13 +6226,13 @@
5918
 /*----------------------------------------------------------
5919
  is_device_locked
5920
 
5921
-   accept:      char * filename.  The device in question including the path.
5922
-   perform:     see if one of the many possible lock files is aready there
5923
-		if there is a stale lock, remove it.
5924
-   return:      1 if the device is locked or somethings wrong.
5925
-		0 if its possible to create our own lock file.
5926
-   exceptions:  none
5927
-   comments:    check if the device is already locked
5928
+	accept:		char * filename.  The device in question including the path.
5929
+	perform:	see if one of the many possible lock files is aready there
5930
+				if there is a stale lock, remove it.
5931
+	return:		1 if the device is locked or somethings wrong.
5932
+				0 if its possible to create our own lock file.
5933
+	exceptions:	none
5934
+	comments:	check if the device is already locked
5935
 ----------------------------------------------------------*/
5936
 int is_device_locked( const char *port_filename )
5937
 {
5938
@@ -5828,12 +6256,12 @@
5939
 	while( lockdirs[i] )
5940
 	{
5941
 		/*
5942
-		   Look for lockfiles in all known places other than the
5943
-		   defined lock directory for this system
5944
-		   report any unexpected lockfiles.
5945
+			Look for lockfiles in all known places other than the
5946
+			defined lock directory for this system
5947
+			report any unexpected lockfiles.
5948
 
5949
-		   Is the suspect lockdir there?
5950
-		   if it is there is it not the expected lock dir?
5951
+			Is the suspect lockdir there?
5952
+			if it is there is it not the expected lock dir?
5953
 		*/
5954
 		if( !stat( lockdirs[i], &buf2 ) &&
5955
 			buf2.st_ino != lockbuf.st_ino &&
5956
@@ -5842,7 +6270,7 @@
5957
 			j = strlen( port_filename );
5958
 			p = ( char *  ) port_filename + j;
5959
 		/*
5960
-		   SCO Unix use lowercase all the time
5961
+			SCO Unix use lowercase all the time
5962
 			taj
5963
 		*/
5964
 			while( *( p - 1 ) != '/' && j-- != 1 )
5965
@@ -5860,7 +6288,8 @@
5966
 					lockprefixes[k], p );
5967
 				if( stat( file, &buf ) == 0 )
5968
 				{
5969
-					sprintf( message, UNEXPECTED_LOCK_FILE,
5970
+					memset(&message[0], 0, sizeof(message));
5971
+					sprintf( message, "%s%s\n", UNEXPECTED_LOCK_FILE,
5972
 						file );
5973
 					report_warning( message );
5974
 					return 1;
5975
@@ -5877,7 +6306,8 @@
5976
 				);
5977
 				if( stat( file, &buf ) == 0 )
5978
 				{
5979
-					sprintf( message, UNEXPECTED_LOCK_FILE,
5980
+					memset(&message[0], 0, sizeof(message));
5981
+					sprintf( message, "%s%s\n", UNEXPECTED_LOCK_FILE,
5982
 						file );
5983
 					report_warning( message );
5984
 					return 1;
5985
@@ -5934,13 +6364,15 @@
5986
 
5987
 		if( kill( (pid_t) pid, 0 ) && errno==ESRCH )
5988
 		{
5989
+			memset(&message[0], 0, sizeof(message));
5990
 			sprintf( message,
5991
-				"RXTX Warning:  Removing stale lock file. %s\n",
5992
+				"RXTX Warning:	Removing stale lock file. %s\n",
5993
 				file );
5994
 			report_warning( message );
5995
 			if( unlink( file ) != 0 )
5996
 			{
5997
-				snprintf( message, 80, "RXTX Error:  Unable to \
5998
+				memset(&message[0], 0, sizeof(message));
5999
+				snprintf( message, 80, "RXTX Error:	Unable to \
6000
 					remove stale lock file: %s\n",
6001
 					file
6002
 				);
6003
@@ -5956,11 +6388,11 @@
6004
 /*----------------------------------------------------------
6005
  system_does_not_lock
6006
 
6007
-   accept:      the filename the system thinks should be locked.
6008
-   perform:     avoid trying to create lock files on systems that dont use them
6009
-   return:      0 for success ;)
6010
-   exceptions:  none
6011
-   comments:    OS's like Win32 may not have lock files.
6012
+	accept:		the filename the system thinks should be locked.
6013
+	perform:	avoid trying to create lock files on systems that dont use them
6014
+	return:		0 for success ;)
6015
+	exceptions:	none
6016
+	comments:	OS's like Win32 may not have lock files.
6017
 ----------------------------------------------------------*/
6018
 int system_does_not_lock( const char * filename, int pid )
6019
 {
6020
@@ -5970,11 +6402,11 @@
6021
 /*----------------------------------------------------------
6022
  system_does_not_unlock
6023
 
6024
-   accept:      the filename the system thinks should be locked.
6025
-   perform:     avoid trying to create lock files on systems that dont use them
6026
-   return:      none
6027
-   exceptions:  none
6028
-   comments:    OS's like Win32 may not have lock files.
6029
+	accept:		the filename the system thinks should be locked.
6030
+	perform:	avoid trying to create lock files on systems that dont use them
6031
+	return:		none
6032
+	exceptions:	none
6033
+	comments:	OS's like Win32 may not have lock files.
6034
 ----------------------------------------------------------*/
6035
 void system_does_not_unlock( const char * filename, int openpid )
6036
 {
6037
@@ -5984,12 +6416,12 @@
6038
 /*----------------------------------------------------------
6039
  dump_termios
6040
 
6041
-   accept:      string to indicate where this was called.
6042
-                termios struct
6043
-   perform:     print the termios struct to stderr.
6044
-   return:      none
6045
-   exceptions:  none
6046
-   comments:    used to debug the termios struct.
6047
+	accept:		string to indicate where this was called.
6048
+				termios struct
6049
+	perform:	print the termios struct to stderr.
6050
+	return:		none
6051
+	exceptions:	none
6052
+	comments:	used to debug the termios struct.
6053
 ----------------------------------------------------------*/
6054
 void dump_termios(char *foo,struct termios *ttyset)
6055
 {
6056
@@ -6012,12 +6444,12 @@
6057
 /*----------------------------------------------------------
6058
 get_java_environment
6059
 
6060
-   accept:      pointer to the virtual machine
6061
-		flag to know if we are attached
6062
-   return:      pointer to the Java Environment
6063
-   exceptions:  none
6064
-   comments:    see JNI_OnLoad.  For getting the JNIEnv in the thread
6065
-		used to monitor for output buffer empty.
6066
+	accept:		pointer to the virtual machine
6067
+				flag to know if we are attached
6068
+	return:		pointer to the Java Environment
6069
+	exceptions:	none
6070
+	comments:	see JNI_OnLoad.  For getting the JNIEnv in the thread
6071
+				used to monitor for output buffer empty.
6072
 ----------------------------------------------------------*/
6073
 JNIEnv *get_java_environment(JavaVM *java_vm,  jboolean *was_attached){
6074
 	void **env = NULL;
6075
@@ -6045,15 +6477,15 @@
6076
 /*----------------------------------------------------------
6077
 JNI_OnLoad
6078
 
6079
-   accept:      JavaVM pointer to the Vertial Machine
6080
-		void * reserved ???
6081
-   return:      jint JNI version used.
6082
-   exceptions:  none
6083
-   comments:    http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html
6084
-		http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html
6085
-		grab the Java VM pointer when the library loads for later use
6086
-		in the drain thread.  Also lets Java know we are using the
6087
-		1.4 API so we can get pointers later.
6088
+	accept:		JavaVM pointer to the Vertial Machine
6089
+				void * reserved ???
6090
+	return:		jint JNI version used.
6091
+	exceptions:	none
6092
+	comments:	http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html
6093
+				http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html
6094
+				grab the Java VM pointer when the library loads for later use
6095
+				in the drain thread.  Also lets Java know we are using the
6096
+				1.4 API so we can get pointers later.
6097
 ----------------------------------------------------------*/
6098
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *java_vm, void *reserved)
6099
 {
6100
@@ -6065,28 +6497,28 @@
6101
 /*----------------------------------------------------------
6102
 JNI_OnUnload
6103
 
6104
-   accept:      JavaVM pointer to the Vertial Machine
6105
-		void * reserved ???
6106
-   return:      none
6107
-   exceptions:  none
6108
-   comments:    http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html
6109
-		http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html
6110
-		final library cleanup here.
6111
+	accept:		JavaVM pointer to the Vertial Machine
6112
+				void * reserved ???
6113
+	return:		none
6114
+	exceptions:	none
6115
+	comments:	http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html
6116
+				http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html
6117
+				final library cleanup here.
6118
 ----------------------------------------------------------*/
6119
 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
6120
 {
6121
 	/* never called it appears */
6122
-	printf("Experimental:  JNI_OnUnload called.\n");
6123
+	printf("Experimental:	JNI_OnUnload called.\n");
6124
 }
6125
 
6126
 #ifdef asdf
6127
 /*----------------------------------------------------------
6128
 printj
6129
 
6130
-   accept:      like vwprintf()
6131
-   return:      number of jchars written or -1
6132
-   exceptions:  none
6133
-   comments:    prints data using System.out.print()
6134
+	accept:		like vwprintf()
6135
+	return:		number of jchars written or -1
6136
+	exceptions:	none
6137
+	comments:	prints data using System.out.print()
6138
 ----------------------------------------------------------*/
6139
 int printj(JNIEnv *env, wchar_t *fmt, ...)
6140
 {
6141
@@ -6158,4 +6590,3 @@
6142
 	(*env)->CallStaticVoidMethod(env, cls, mid, 1);
6143
 */
6144
 #endif /* asdf */
6145
-
(-)files/patch-src-gnu-io-CommPort.java (+44 lines)
Line 0 Link Here
1
--- src/gnu/io/CommPort.java.orig	2007-04-26 06:26:05.000000000 +0100
2
+++ src/gnu/io/CommPort.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -73,7 +73,7 @@
4
   */
5
 public abstract class CommPort extends Object {
6
 	protected String name;
7
-	private final static boolean debug = false;
8
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
9
 
10
 	public abstract void enableReceiveFraming( int f ) 
11
 		throws UnsupportedCommOperationException;
12
@@ -94,6 +94,7 @@
13
 	public abstract int getInputBufferSize();
14
 	public abstract void setOutputBufferSize( int size );
15
 	public abstract int getOutputBufferSize();
16
+	
17
 	public void close() 
18
 	{
19
 		if (debug) System.out.println("CommPort:close()");
20
@@ -102,12 +103,23 @@
21
 		{
22
 			CommPortIdentifier cp = 
23
 				CommPortIdentifier.getPortIdentifier(this);
24
-			if ( cp != null )
25
+				
26
+			if (cp != null)
27
+			{
28
+				
29
+				if (debug) System.out.println(" Not Null");
30
+				
31
 				cp.getPortIdentifier(this).internalClosePort();
32
+				
33
+			}
34
 		}
35
 		catch (NoSuchPortException e)
36
 		{
37
+			if (debug) System.out.println("CommPort:close(): No Such Port");
38
 		}
39
+		
40
+		if (debug) System.out.println("CommPort:close:Exit");
41
+		
42
 	};
43
 
44
 	public abstract InputStream getInputStream() throws IOException;
(-)files/patch-src-gnu-io-CommPortEnumerator.java (+108 lines)
Line 0 Link Here
1
--- src/gnu/io/CommPortEnumerator.java.orig	2007-04-26 06:26:05.000000000 +0100
2
+++ src/gnu/io/CommPortEnumerator.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -69,50 +69,79 @@
4
 class CommPortEnumerator implements Enumeration
5
 {
6
 	private CommPortIdentifier index;
7
-	private final static boolean debug = false;
8
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
9
 	static
10
 	{
11
-		if (debug)
12
-			System.out.println("CommPortEnumerator:{}");
13
+		if (debug) System.out.println("CommPortEnumerator:Static{}");
14
 	}
15
 
16
 	CommPortEnumerator()
17
 	{
18
 	}
19
-/*------------------------------------------------------------------------------
20
-        nextElement()
21
-        accept:
22
-        perform:
23
-        return:
24
-        exceptions:
25
-        comments:
26
-------------------------------------------------------------------------------*/
27
+
28
 	public Object nextElement()
29
 	{
30
-		if(debug) System.out.println("CommPortEnumerator:nextElement()");
31
+		if (debug) System.out.println("CommPortEnumerator:nextElement()");
32
+		
33
 		synchronized (CommPortIdentifier.Sync)
34
 		{
35
-			if(index != null) index = index.next;
36
-			else index=CommPortIdentifier.CommPortIndex;
37
+			if(index != null)
38
+			{
39
+				index = index.next;
40
+			}
41
+			else
42
+			{
43
+				index=CommPortIdentifier.CommPortIndex;
44
+			}
45
+			if (debug) System.out.println(" CommPortEnumerator:nextElement(" + index + ")");
46
 			return(index);
47
 		}
48
 	}
49
-/*------------------------------------------------------------------------------
50
-        hasMoreElements()
51
-        accept:
52
-        perform:
53
-        return:
54
-        exceptions:
55
-        comments:
56
-------------------------------------------------------------------------------*/
57
+
58
 	public boolean hasMoreElements()
59
 	{
60
-		if(debug) System.out.println("CommPortEnumerator:hasMoreElements() " + CommPortIdentifier.CommPortIndex == null ? false : true );
61
+		if (debug) System.out.println("CommPortEnumerator:hasMoreElements()");
62
+		
63
+		if (CommPortIdentifier.CommPortIndex == null)
64
+		{
65
+			 if (debug) System.out.println(" ComPortIndex is null...");
66
+		}
67
+		else
68
+		{
69
+			if (debug) System.out.println(" ComPortIndex is not null...");
70
+		}
71
+		
72
 		synchronized (CommPortIdentifier.Sync)
73
 		{
74
-			if(index != null) return index.next == null ? false : true;
75
-			else return CommPortIdentifier.CommPortIndex == null ?
76
-				false : true;
77
+			if (debug) System.out.println(" Syncronised");
78
+			if(index != null) 
79
+			{
80
+				if (debug) System.out.println(" Valid index");
81
+				if (index.next == null)
82
+				{
83
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(Next index is null - false)");
84
+					return false;
85
+				}
86
+				else
87
+				{
88
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(Next index is not null - true)");
89
+					return true;
90
+				}
91
+			}
92
+			else 
93
+			{
94
+				if (debug) System.out.println(" Index is not valid");
95
+				if (CommPortIdentifier.CommPortIndex == null)
96
+				{
97
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(CommPortIdentifier.CommPortIndex is null - false)");
98
+					return false;
99
+				}
100
+				else
101
+				{
102
+					if (debug) System.out.println("CommPortEnumerator:hasMoreElements: Exit(CommPortIdentifier.CommPortIndex is not null - true)");
103
+					return true;
104
+				}
105
+			}
106
 		}
107
 	}
108
 }
(-)files/patch-src-gnu-io-CommPortIdentifier.java (+850 lines)
Line 0 Link Here
1
--- src/gnu/io/CommPortIdentifier.java.orig	2008-11-27 20:02:34.000000000 +0000
2
+++ src/gnu/io/CommPortIdentifier.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -76,85 +76,138 @@
4
 	public static final int PORT_RS485    = 4;  // rs485 Port
5
 	public static final int PORT_RAW      = 5;  // Raw Port
6
 	private String PortName;
7
-	private boolean Available = true;    
8
+	private static boolean init_clean = false;
9
+	private boolean Available = true;
10
 	private String Owner;    
11
 	private CommPort commport;
12
 	private CommDriver RXTXDriver;
13
  	static CommPortIdentifier   CommPortIndex;
14
 	CommPortIdentifier next;
15
 	private int PortType;
16
-	private final static boolean debug = false;
17
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
18
 	static Object Sync;
19
 	Vector ownershipListener;
20
 
21
 
22
 
23
-/*------------------------------------------------------------------------------
24
-	static {}   aka initialization
25
-	accept:       -
26
-	perform:      load the rxtx driver
27
-	return:       -
28
-	exceptions:   Throwable
29
-	comments:     static block to initialize the class
30
-------------------------------------------------------------------------------*/
31
-	// initialization only done once....
32
+	/**
33
+	*	static {}   aka initialization
34
+	*	accept:       -
35
+	*	perform:      load the rxtx driver
36
+	*	return:       -
37
+	*	exceptions:   Throwable
38
+	*	comments:     static block to initialize the class
39
+	* 	
40
+	* 	initialization only done once....
41
+	* 	
42
+	**/
43
+	
44
 	static 
45
 	{
46
-		if(debug) System.out.println("CommPortIdentifier:static initialization()");
47
+		if(debug) System.out.println("CommPortIdentifier:Static()");
48
+		
49
 		Sync = new Object();
50
 		try 
51
 		{
52
+			if(debug) System.out.println(" Pre RXTXDriver.Loading New Class (Clean)");
53
+			
54
+			init_clean = true;
55
+			
56
 			CommDriver RXTXDriver = (CommDriver) Class.forName("gnu.io.RXTXCommDriver").newInstance();
57
+			
58
+			if(debug) System.out.println(" Pre RXTXDriver.initialize()");
59
+			
60
 			RXTXDriver.initialize();
61
+			
62
+			if(debug) System.out.println(" Post RXTXDriver.initialize()");
63
+			
64
 		} 
65
 		catch (Throwable e) 
66
 		{
67
-			System.err.println(e + " thrown while loading " + "gnu.io.RXTXCommDriver");
68
+			
69
+			if(debug) System.out.println(" " + e + " thrown while loading gnu.io.RXTXCommDriver");
70
+			
71
+			System.err.println(e + " thrown while loading gnu.io.RXTXCommDriver");
72
+			
73
+			init_clean = false;
74
+			
75
 		}
76
 
77
 		String OS;
78
 
79
 		OS = System.getProperty("os.name");
80
+		
81
+		if(debug) System.out.println(" The OS is " + OS);
82
+		
83
 		if(OS.toLowerCase().indexOf("linux") == -1)
84
 		{
85
-			if (debug)
86
-				System.out.println("Have not implemented native_psmisc_report_owner(PortName)); in CommPortIdentifier");
87
+			if (debug) 
88
+			{
89
+				System.out.println(" WARNING:");
90
+				System.out.println(" native_psmisc_System.out.println_owner(@)) not implemented");
91
+				
92
+				/**
93
+				*	Not Implemented:
94
+				* 	
95
+				*	native_psmisc_System.out.println_owner(PortName)
96
+				* 	in CommPortIdentifier")
97
+				**/
98
+				
99
+			}
100
 		}
101
+		
102
+		if(debug) System.out.println(" Loading Library...");
103
+		
104
 		System.loadLibrary( "rxtxSerial" );
105
-	}
106
-	CommPortIdentifier ( String pn, CommPort cp, int pt, CommDriver driver) 
107
+		
108
+		if(debug) System.out.println(" init_clean is " + init_clean);
109
+		if(debug) System.out.println("CommPortIdentifier:Static:Exit");
110
+		
111
+	}
112
+	CommPortIdentifier 
113
+	(
114
+		String pn,
115
+		CommPort cp,
116
+		int pt,
117
+		CommDriver driver
118
+	) 
119
 	{
120
 		PortName        = pn;
121
 		commport        = cp;
122
 		PortType        = pt;
123
 		next            = null;
124
 		RXTXDriver      = driver;
125
-
126
 	}
127
 
128
-/*------------------------------------------------------------------------------
129
-	addPortName()
130
-	accept:         Name of the port s, Port type, 
131
-                        reverence to RXTXCommDriver.
132
-	perform:        place a new CommPortIdentifier in the linked list
133
-	return: 	none.
134
-	exceptions:     none.
135
-	comments:
136
-------------------------------------------------------------------------------*/
137
+	/**
138
+	*	addPortName()
139
+	*	accept:		Name of the port s, Port type,
140
+	*				reference to RXTXCommDriver.
141
+	*	perform:	place a new CommPortIdentifier in the linked list
142
+	*	return:		none.
143
+	*	exceptions:	none.
144
+	*	comments:
145
+	**/
146
+	
147
 	public static void addPortName(String s, int type, CommDriver c) 
148
 	{ 
149
 
150
-		if(debug) System.out.println("CommPortIdentifier:addPortName("+s+")");
151
+		if(debug) System.out.println("CommPortIdentifier:addPortName(" + s + ")");
152
+		
153
 		AddIdentifierToList(new CommPortIdentifier(s, null, type, c));
154
+		
155
+		if(debug) System.out.println("CommPortIdentifier:addPortName:Exit");
156
 	}
157
-/*------------------------------------------------------------------------------
158
-	AddIdentifierToList()
159
-	accept:        The cpi to add to the list. 
160
-	perform:        
161
-	return: 	
162
-	exceptions:    
163
-	comments:
164
-------------------------------------------------------------------------------*/
165
+	
166
+	/**
167
+	*	AddIdentifierToList()
168
+	*	accept:		The cpi to add to the list. 
169
+	*	perform:        
170
+	*	return: 	
171
+	*	exceptions:    
172
+	*	comments:
173
+	**/
174
+	
175
 	private static void AddIdentifierToList( CommPortIdentifier cpi)
176
 	{
177
 		if(debug) System.out.println("CommPortIdentifier:AddIdentifierToList()");
178
@@ -163,7 +216,7 @@
179
 			if (CommPortIndex == null) 
180
 			{
181
 				CommPortIndex = cpi;
182
-				if(debug) System.out.println("CommPortIdentifier:AddIdentifierToList() null");
183
+				if(debug) System.out.println(" Com Port Index is null!");
184
 			}
185
 			else
186
 			{ 
187
@@ -171,264 +224,351 @@
188
 				while (index.next != null)
189
 				{
190
 					index = index.next;
191
-					if(debug) System.out.println("CommPortIdentifier:AddIdentifierToList() index.next");
192
 				}
193
 				index.next = cpi;
194
 			} 
195
 		}
196
+		
197
+		if(debug) System.out.println("CommPortIdentifier:addIdentifier:Exit");
198
+		
199
 	}
200
-/*------------------------------------------------------------------------------
201
-	addPortOwnershipListener()
202
-	accept:
203
-	perform:
204
-	return:
205
-	exceptions:
206
-	comments:   
207
-------------------------------------------------------------------------------*/
208
+	
209
 	public void addPortOwnershipListener(CommPortOwnershipListener c) 
210
 	{ 
211
 		if(debug) System.out.println("CommPortIdentifier:addPortOwnershipListener()");
212
 
213
-		/*  is the Vector instantiated? */
214
+		/**
215
+		*	is the Vector instantiated?
216
+		**/
217
 
218
 		if( ownershipListener == null )
219
 		{
220
 			ownershipListener = new Vector();
221
 		}
222
 
223
-		/* is the ownership listener already in the list? */
224
+		/**
225
+		*	is the ownership listener already in the list?
226
+		**/
227
 
228
 		if ( ownershipListener.contains(c) == false)
229
 		{
230
 			ownershipListener.addElement(c);
231
 		}
232
+		
233
+		if(debug) System.out.println("CommPortIdentifier:addPortOwnershipListener:Exit");
234
 	}
235
-/*------------------------------------------------------------------------------
236
-	getCurrentOwner()
237
-	accept:
238
-	perform:
239
-	return:
240
-	exceptions:
241
-	comments:    
242
-------------------------------------------------------------------------------*/
243
+
244
 	public String getCurrentOwner() 
245
 	{ 
246
 		if(debug) System.out.println("CommPortIdentifier:getCurrentOwner()");
247
+		
248
 		return( Owner );
249
+		
250
 	}
251
-/*------------------------------------------------------------------------------
252
-	getName()
253
-	accept:
254
-	perform:
255
-	return:
256
-	exceptions:
257
-	comments:
258
-------------------------------------------------------------------------------*/
259
+	
260
 	public String getName() 
261
 	{ 
262
-		if(debug) System.out.println("CommPortIdentifier:getName()");
263
+		if(debug) System.out.println("CommPortIdentifier:getName(" + PortName + ")");
264
+		
265
 		return( PortName );
266
+		
267
+		
268
 	}
269
-/*------------------------------------------------------------------------------
270
-	getPortIdentifier()
271
-	accept:
272
-	perform:
273
-	return:
274
-	exceptions:
275
-	comments:   
276
-------------------------------------------------------------------------------*/
277
+	
278
 	static public CommPortIdentifier getPortIdentifier(String s) throws NoSuchPortException 
279
 	{ 
280
 		if(debug) System.out.println("CommPortIdentifier:getPortIdentifier(" + s +")");
281
+		
282
 		CommPortIdentifier index;
283
 
284
 		synchronized (Sync) 
285
 		{
286
 		 	index = CommPortIndex;
287
-			while (index != null && !index.PortName.equals(s)) { 
288
+		 	
289
+			while (index != null && !index.PortName.equals(s))
290
+			{ 
291
 				index = index.next;
292
 			}
293
+			
294
 			if (index == null) {
295
-				/* This may slow things down but if you pass the string for the port after
296
-				   a device is plugged in, you can find it now.
297
-
298
-				   http://bugzilla.qbang.org/show_bug.cgi?id=48
299
-				*/
300
+				
301
+				/**
302
+				*	This may slow things down but if you pass the string for the port after
303
+				*	a device is plugged in, you can find it now.
304
+				*	
305
+				*	http://bugzilla.qbang.org/show_bug.cgi?id=48
306
+				**/
307
+				
308
 				getPortIdentifiers();
309
+				
310
 			 	index = CommPortIndex;
311
-				while (index != null && !index.PortName.equals(s)) { 
312
+			 	
313
+				while (index != null && !index.PortName.equals(s))
314
+				{ 
315
 					index = index.next;
316
 				}
317
+				
318
 			}
319
+			
320
 		}
321
+		
322
 		if (index != null) return index;
323
 		else
324
 		{
325
-			if ( debug )
326
-				System.out.println("not found!" + s);
327
+			if (debug) System.out.println(" not found!" + s);
328
+			
329
 			throw new NoSuchPortException();
330
 		}
331
+		
332
+		
333
+		
334
 	}
335
-/*------------------------------------------------------------------------------
336
-	getPortIdentifier()
337
-	accept:
338
-	perform:
339
-	return:
340
-	exceptions:
341
-	comments:    
342
-------------------------------------------------------------------------------*/
343
+		
344
 	static public CommPortIdentifier getPortIdentifier(CommPort p) 
345
 		throws NoSuchPortException 	
346
 	{ 
347
-		if(debug) System.out.println("CommPortIdentifier:getPortIdentifier(CommPort)");
348
+		if(debug) System.out.println("CommPortIdentifier:getPortIdentifier(" + p + ")");
349
+		
350
 		CommPortIdentifier c;
351
+		
352
 		synchronized( Sync )
353
 		{
354
+			
355
 			c = CommPortIndex;
356
-			while ( c != null && c.commport != p )
357
+			
358
+			while
359
+			(
360
+				c != null &&
361
+				c.commport != p
362
+			)
363
+			{
364
 				c = c.next;
365
+			}
366
 		}
367
+		
368
 		if ( c != null )
369
 			return (c);
370
 
371
-		if ( debug )
372
-			System.out.println("not found!" + p.getName());
373
+		if ( debug ) System.out.println(" not found!" + p.getName());
374
+		
375
 		throw new NoSuchPortException();
376
+		
377
+		
378
 	}
379
-/*------------------------------------------------------------------------------
380
-	getPortIdentifiers()
381
-	accept:
382
-	perform:
383
-	return:
384
-	exceptions:
385
-	comments:
386
-------------------------------------------------------------------------------*/
387
+	
388
 	static public Enumeration getPortIdentifiers() 
389
 	{ 
390
-		if(debug) System.out.println("static CommPortIdentifier:getPortIdentifiers()");
391
-		//Do not allow anybody get any ports while we are re-initializing
392
-		//because the CommPortIndex points to invalid instances during that time
393
+		if(debug) System.out.println("CommPortIdentifier:getPortIdentifiers()");
394
+		
395
+		/** 
396
+		*	Do not allow anybody get any ports while we are re-initializing
397
+		*	because the CommPortIndex points to invalid instances during that time
398
+		*/
399
+		
400
 		synchronized(Sync) {
401
-			//Remember old ports in order to restore them for ownership events later
402
+			
403
+			/**
404
+			*	Remember old ports in order to restore them for ownership events later
405
+			**/
406
+			if(debug) System.out.println(" backing up current ports");
407
 			HashMap oldPorts = new HashMap();
408
 			CommPortIdentifier p = CommPortIndex;
409
-			while(p!=null) {
410
+			
411
+			while(p!=null) 
412
+			{
413
 				oldPorts.put(p.PortName, p);
414
 				p = p.next;
415
 			}
416
+			
417
 			CommPortIndex = null;
418
+			
419
 			try 
420
 			{
421
-				//Initialize RXTX: This leads to detecting all ports
422
-				//and writing them into our CommPortIndex through our method
423
-				//{@link #addPortName(java.lang.String, int, gnu.io.CommDriver)}
424
-				//This works while lock on Sync is held
425
-				CommDriver RXTXDriver = (CommDriver) Class.forName("gnu.io.RXTXCommDriver").newInstance();
426
-				RXTXDriver.initialize();
427
-				//Restore old CommPortIdentifier objects where possible, 
428
-				//in order to support proper ownership event handling.
429
-				//Clients might still have references to old identifiers!
430
+				/**
431
+				*	Initialize RXTX: This leads to detecting all ports
432
+				*	and writing them into our CommPortIndex through our method
433
+				*	{@link #addPortName(java.lang.String, int, gnu.io.CommDriver)}
434
+				*	This works while lock on Sync is held
435
+				**/
436
+				
437
+				/**
438
+				*	However, if RXTX is being called invoked by 
439
+				* 	CommPortIdentifier:getPortIdentifiers for the first
440
+				* 	time, they have just been enumerated by static() in 
441
+				*	this class, so we don't need to repeat on the first
442
+				* 	time.
443
+				**/
444
+				
445
+				if ( init_clean == false )
446
+				{
447
+					if(debug) System.out.println(" RXTX init() is dirty");
448
+					if(debug) System.out.println(" Creating RXTX new instance");
449
+					CommDriver RXTXDriver = (CommDriver) Class.forName("gnu.io.RXTXCommDriver").newInstance();
450
+					if(debug) System.out.println(" Creating RXTX new instance");
451
+					RXTXDriver.initialize();
452
+					
453
+				}
454
+				else
455
+				{
456
+					if(debug) System.out.println(" RXTX init() still clean, now marking as dirty");
457
+					init_clean = false;
458
+				}
459
+				
460
+				/**
461
+				*	Restore old CommPortIdentifier objects where possible, 
462
+				*	in order to support proper ownership event handling.
463
+				*	Clients might still have references to old identifiers!
464
+				**/
465
+				
466
 				CommPortIdentifier curPort = CommPortIndex;
467
 				CommPortIdentifier prevPort = null;
468
-				while(curPort!=null) {
469
+				while(curPort!=null)
470
+				{
471
 					CommPortIdentifier matchingOldPort = (CommPortIdentifier)oldPorts.get(curPort.PortName);
472
-					if(matchingOldPort!=null && matchingOldPort.PortType == curPort.PortType) {
473
-						//replace new port by old one
474
+					if
475
+					(
476
+						matchingOldPort!=null && 
477
+						matchingOldPort.PortType == curPort.PortType
478
+					)
479
+					{
480
+						/**
481
+						*	replace new port by old one
482
+						**/
483
+						
484
 						matchingOldPort.RXTXDriver = curPort.RXTXDriver;
485
 						matchingOldPort.next = curPort.next;
486
-						if(prevPort==null) {
487
+						
488
+						if (prevPort==null)
489
+						{
490
 							CommPortIndex = matchingOldPort;
491
-						} else {
492
+						}
493
+						else
494
+						{
495
 							prevPort.next = matchingOldPort;
496
 						}
497
 						prevPort = matchingOldPort;
498
-					} else {
499
+					}
500
+					else
501
+					{
502
 						prevPort = curPort;
503
 					}
504
+					
505
 					curPort = curPort.next;
506
+					
507
 				}
508
+				
509
 			} 
510
 			catch (Throwable e) 
511
 			{
512
+				
513
+				System.out.println(" " + e + " thrown while loading gnu.io.RXTXCommDriver");
514
+				
515
 				System.err.println(e + " thrown while loading " + "gnu.io.RXTXCommDriver");
516
+				
517
 				System.err.flush();
518
+				
519
 			}
520
 		}
521
+		
522
+		if(debug) System.out.println("CommPortIdentifier:getPortIdentifiers:Exit");
523
+		
524
 		return new CommPortEnumerator();
525
+		
526
+		
527
+		
528
 	}
529
-/*------------------------------------------------------------------------------
530
-	getPortType()
531
-	accept:
532
-	perform:
533
-	return:
534
-	exceptions:
535
-	comments:
536
-------------------------------------------------------------------------------*/
537
+	
538
 	public int getPortType() 
539
 	{ 
540
-		if(debug) System.out.println("CommPortIdentifier:getPortType()");
541
+		if(debug) System.out.println("CommPortIdentifier:getPortType(" + PortType + ")");
542
+		
543
 		return( PortType );
544
+		
545
+		
546
 	}
547
-/*------------------------------------------------------------------------------
548
-	isCurrentlyOwned()
549
-	accept:
550
-	perform:
551
-	return:
552
-	exceptions:
553
-	comments:    
554
-------------------------------------------------------------------------------*/
555
+		
556
 	public synchronized boolean isCurrentlyOwned() 
557
 	{ 
558
 		if(debug) System.out.println("CommPortIdentifier:isCurrentlyOwned()");
559
+		
560
 		return(!Available);
561
+		
562
+		
563
 	}
564
-/*------------------------------------------------------------------------------
565
-	open()
566
-	accept:
567
-	perform:
568
-	return:
569
-	exceptions:
570
-	comments:
571
-------------------------------------------------------------------------------*/
572
+		
573
 	public synchronized CommPort open(FileDescriptor f) throws UnsupportedCommOperationException 
574
 	{ 
575
 		if(debug) System.out.println("CommPortIdentifier:open(FileDescriptor)");
576
+		
577
 		throw new UnsupportedCommOperationException();
578
+		
579
 	}
580
 	private native String native_psmisc_report_owner(String PortName);
581
 
582
-/*------------------------------------------------------------------------------
583
-	open()
584
-	accept:      application making the call and milliseconds to block
585
-                     during open.
586
-	perform:     open the port if possible
587
-	return:      CommPort if successful
588
-	exceptions:  PortInUseException if in use.
589
-	comments:
590
-------------------------------------------------------------------------------*/
591
+	/**
592
+	*	open()
593
+	*	accept:		application making the call and milliseconds to block
594
+    *				during open.
595
+	*	perform:	open the port if possible
596
+	*	return:		CommPort if successful
597
+	*	exceptions:	PortInUseException if in use.
598
+	*	comments:	
599
+	**/
600
+	
601
 	private boolean HideOwnerEvents;
602
 
603
-	public CommPort open(String TheOwner, int i) 
604
-		throws gnu.io.PortInUseException 
605
+	public CommPort open(
606
+		String TheOwner, 
607
+		int i
608
+	) 
609
+	throws gnu.io.PortInUseException 
610
 	{ 
611
-		if(debug) System.out.println("CommPortIdentifier:open("+TheOwner + ", " +i+")");
612
+		if(debug) System.out.println("CommPortIdentifier:open(" + TheOwner + ", " + i + ")");
613
+		
614
 		boolean isAvailable;
615
-		synchronized(this) {
616
+		
617
+		synchronized(this)
618
+		{
619
 			isAvailable = this.Available;
620
+			
621
 			if (isAvailable) {
622
-			    //assume ownership inside the synchronized block
623
+				
624
+				/**
625
+				*	assume ownership inside the synchronized block
626
+				*	? Of you and me !
627
+				**/
628
+				
629
 			    this.Available = false;
630
 			    this.Owner = TheOwner;
631
 			}
632
 		}
633
+		
634
 		if (!isAvailable)
635
 		{
636
 			long waitTimeEnd = System.currentTimeMillis() + i;
637
-			//fire the ownership event outside the synchronized block
638
-			fireOwnershipEvent(CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED);
639
+			
640
+			/**
641
+			*	Fire the ownership event outside the synchronized block
642
+			**/
643
+			
644
+			fireOwnershipEvent
645
+			(
646
+				CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED
647
+			);
648
+			
649
 			long waitTimeCurr;
650
-			synchronized(this) {
651
-				while(!Available && (waitTimeCurr=System.currentTimeMillis()) < waitTimeEnd) {
652
+			
653
+			synchronized(this)
654
+			{
655
+				
656
+				while
657
+				(
658
+					!Available && 
659
+					(
660
+						waitTimeCurr=System.currentTimeMillis()
661
+					) < waitTimeEnd
662
+				) 
663
+				{
664
 					try
665
 					{
666
 						wait(waitTimeEnd - waitTimeCurr);
667
@@ -439,91 +579,134 @@
668
 						break;
669
 					}
670
 				}
671
+				
672
 				isAvailable = this.Available;
673
+				
674
 				if (isAvailable) {
675
-					//assume ownership inside the synchronized block
676
+					/**
677
+					*	Assume ownership inside the synchronized block
678
+					* 	? of you an me !
679
+					**/
680
 					this.Available = false;
681
 					this.Owner = TheOwner;
682
 				}
683
 			}
684
 		}
685
+		
686
 		if (!isAvailable)
687
 		{
688
 			throw new gnu.io.PortInUseException(getCurrentOwner());
689
 		}
690
-		//At this point, the CommPortIdentifier is owned by us.
691
-		try {
692
+		
693
+		/**
694
+		*	At this point, the CommPortIdentifier is owned by us.
695
+		**/
696
+		
697
+		try
698
+		{
699
 			if(commport == null)
700
 			{
701
-				commport = RXTXDriver.getCommPort(PortName,PortType);
702
+				commport = RXTXDriver.getCommPort(
703
+					PortName,
704
+					PortType
705
+				);
706
 			}
707
+			
708
 			if(commport != null)
709
 			{
710
-				fireOwnershipEvent(CommPortOwnershipListener.PORT_OWNED);
711
+				fireOwnershipEvent(
712
+					CommPortOwnershipListener.PORT_OWNED
713
+				);
714
+				
715
 				return commport;
716
 			}
717
 			else
718
 			{
719
-				throw new gnu.io.PortInUseException(
720
-						native_psmisc_report_owner(PortName));
721
+				throw new gnu.io.PortInUseException
722
+				(
723
+					native_psmisc_report_owner(PortName)
724
+				);
725
 			}
726
-		} finally {
727
+		}
728
+		finally 
729
+		{
730
 			if(commport == null) {
731
-				//something went wrong reserving the commport -> unown the port
732
+				
733
+				/**
734
+				*	something went wrong reserving the commport
735
+				*	-> release ownership (internal) of the port
736
+				**/
737
+				
738
 				synchronized(this) {
739
+					
740
 					this.Available = true;
741
 					this.Owner = null;
742
+					
743
 				}
744
 			}
745
+			if(debug) System.out.println("CommPortIdentifier:open:Exit");
746
 		}
747
-	}
748
-/*------------------------------------------------------------------------------
749
-	removePortOwnership()
750
-	accept:
751
-	perform:
752
-	return:
753
-	exceptions:
754
-	comments:
755
-------------------------------------------------------------------------------*/
756
+		
757
+		
758
+		
759
+	}	
760
+	
761
 	public void removePortOwnershipListener(CommPortOwnershipListener c) 
762
 	{ 
763
 		if(debug) System.out.println("CommPortIdentifier:removePortOwnershipListener()");
764
-		/* why is this called twice? */
765
-		if(ownershipListener != null)
766
+		
767
+		/**
768
+		*	why is this called twice?
769
+		**/
770
+		
771
+		if(ownershipListener != null) 
772
+		{
773
+			if(debug) System.out.println(" I was owned!");
774
 			ownershipListener.removeElement(c);
775
+		}
776
+		
777
+		if(debug) System.out.println("CommPortIdentifier:removePortOwnershipListener()");
778
 	}
779
 
780
-/*------------------------------------------------------------------------------
781
-	internalClosePort()
782
-	accept:       None
783
-	perform:      clean up the Ownership information and send the event
784
-	return:       None
785
-	exceptions:   None
786
-	comments:     None
787
-------------------------------------------------------------------------------*/
788
+	/**
789
+	*	internalClosePort()
790
+	*	accept:		None
791
+	*	perform:	clean up the Ownership information and send the event
792
+	*	return:		
793
+	*	exceptions:	
794
+	*	comments:	
795
+	**/
796
+	
797
 	void internalClosePort() 
798
 	{
799
+		
800
+		if(debug) System.out.println("CommPortIdentifier:internalClosePort()");
801
+		
802
 		synchronized(this) {
803
-			if(debug) System.out.println("CommPortIdentifier:internalClosePort()");
804
+			
805
 			Owner = null;
806
 			Available = true;
807
 			commport = null;
808
-			/*  this tosses null pointer?? */
809
+			
810
+			/**
811
+			*	this tosses null pointer??
812
+			**/
813
+			if(debug) System.out.println(" Notifying all...");
814
+			
815
 			notifyAll();
816
+			
817
 		}
818
+		
819
 		fireOwnershipEvent(CommPortOwnershipListener.PORT_UNOWNED);
820
+		
821
+		if(debug) System.out.println("CommPortIdentifier:internalClosePort:Exit");
822
 	}
823
-/*------------------------------------------------------------------------------
824
-	fireOwnershipEvent()
825
-	accept:
826
-	perform:
827
-	return:
828
-	exceptions:
829
-	comments:
830
-------------------------------------------------------------------------------*/
831
+	
832
 	void fireOwnershipEvent(int eventType)
833
 	{
834
+		
835
 		if(debug) System.out.println("CommPortIdentifier:fireOwnershipEvent( " + eventType + " )");
836
+		
837
 		if (ownershipListener != null)
838
 		{
839
 			CommPortOwnershipListener c;
840
@@ -532,6 +715,10 @@
841
 				c.ownershipChange(eventType))
842
 				c = (CommPortOwnershipListener) e.nextElement();
843
 		}
844
+		
845
+		if(debug) System.out.println("CommPortIdentifier:fireOwnershipEvent:Exit");
846
 	}
847
+	
848
+	
849
 }
850
 
(-)files/patch-src-gnu-io-Configure.java (+31 lines)
Line 0 Link Here
1
--- src/gnu/io/Configure.java.orig	2007-11-18 22:32:41.000000000 +0000
2
+++ src/gnu/io/Configure.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -61,6 +61,7 @@
4
 import java.awt.event.*;
5
 import java.io.*;
6
 
7
+
8
 class Configure extends Frame
9
 {
10
 	Checkbox cb[];
11
@@ -68,7 +69,9 @@
12
 	static final int PORT_SERIAL	=	1;
13
 	static final int PORT_PARALLEL	=	2;
14
 	int PortType = PORT_SERIAL;
15
-
16
+	
17
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
18
+	
19
 	private void saveSpecifiedPorts()
20
 	{
21
 		String filename;
22
@@ -212,7 +215,9 @@
23
 	}
24
 	public static void main (String[] args)
25
 	{
26
+		if (debug) System.out.println("Configure - Before New");
27
 		new Configure();
28
+		if (debug) System.out.println("Configure - After New");
29
 	}
30
 	String EnumMessage = "gnu.io.rxtx.properties has not been detected.\n\nThere is no consistant means of detecting ports on this operating System.  It is necessary to indicate which ports are valid on this system before proper port enumeration can happen.  Please check the ports that are valid on this system and select Save";
31
 }
(-)files/patch-src-gnu-io-LPRPort.java (+11 lines)
Line 0 Link Here
1
--- src/gnu/io/LPRPort.java.orig	2007-04-26 06:26:05.000000000 +0100
2
+++ src/gnu/io/LPRPort.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -77,7 +77,7 @@
4
 
5
 	/** Initialize the native library */
6
 	private native static void Initialize();
7
-	private final static boolean debug = false;
8
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
9
 
10
 	/** Open the named port */
11
 	public LPRPort( String name ) throws PortInUseException
(-)files/patch-src-gnu-io-NoSuchPortException.java (+12 lines)
Line 0 Link Here
1
--- src/gnu/io/NoSuchPortException.java.orig	2007-04-26 06:26:05.000000000 +0100
2
+++ src/gnu/io/NoSuchPortException.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -67,6 +67,9 @@
4
 
5
 public class NoSuchPortException extends Exception
6
 {
7
+	
8
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
9
+	
10
 	NoSuchPortException( String str )
11
 	{
12
 		super( str );
(-)files/patch-src-gnu-io-RXTXCommDriver.java (-13 / +1635 lines)
Lines 1-13 Link Here
1
--- src/gnu/io/RXTXCommDriver.java.orig	2011-03-07 01:33:36.824057319 -0700
1
--- src/gnu/io/RXTXCommDriver.java.orig	2008-11-14 00:44:01.000000000 +0000
2
+++ src/gnu/io/RXTXCommDriver.java	2011-03-07 01:33:39.527398898 -0700
2
+++ src/gnu/io/RXTXCommDriver.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -648,6 +648,10 @@
3
@@ -56,10 +56,15 @@
4
 						String[] Temp = {
4
 |   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5
 							"ttyd",    //general purpose serial ports
5
 |   All trademarks belong to their respective owners.
6
 							"cuaa",    //dialout serial ports
6
 --------------------------------------------------------------------------*/
7
+							"ttyu",    //general purpose serial ports (uart)
7
-/* Martin Pool <mbp@linuxcare.com> added support for explicitly-specified
8
+							"cuau",    //dialout serial ports (uart)
8
- * lists of ports, October 2000. */
9
+							"ttyU",    //USB serial ports
9
-/* Joseph Goldstone <joseph@lp.com> reorganized to support registered ports,
10
+							"cuaU",    //USB dial in serial ports
10
- * known ports, and scanned ports, July 2001 */
11
 							"ttyA",    //Specialix SI/XIO dialin ports
11
+/**
12
 							"cuaA",    //Specialix SI/XIO dialout ports
12
+* 	
13
 							"ttyD",    //Digiboard - 16 dialin ports
13
+*	Martin Pool <mbp@linuxcare.com> added support for
14
+* 	explicitly-specified lists of ports, October 2000.
15
+*	
16
+* 	Joseph Goldstone <joseph@lp.com> reorganized to support registered
17
+* 	ports, known ports, and scanned ports, July 2001.
18
+* 	
19
+**/
20
 
21
 package gnu.io;
22
 
23
@@ -69,132 +74,196 @@
24
 import java.util.StringTokenizer;
25
 
26
 /**
27
-   This is the JavaComm for Linux driver.
28
+*   This is the JavaComm for Linux driver.
29
 */
30
+
31
 public class RXTXCommDriver implements CommDriver
32
 {
33
 
34
-	private final static boolean debug = false;
35
-	private final static boolean devel = false;
36
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
37
+	private final static boolean CheckLPT = "true".equals( System.getProperty( "gnu.io.rxtx.CheckL" ) );
38
 	private final static boolean noVersionOutput = "true".equals( System.getProperty( "gnu.io.rxtx.NoVersionOutput" ) );
39
-
40
+	
41
+	
42
 	static
43
 	{
44
-		if(debug ) System.out.println("RXTXCommDriver {}");
45
+		if(debug) System.out.println("RXTXCommDriver{}:Static");
46
 		System.loadLibrary( "rxtxSerial" );
47
 
48
-		/*
49
-		   Perform a crude check to make sure people don't mix
50
-		   versions of the Jar and native lib
51
-
52
-		   Mixing the libs can create a nightmare.
53
-
54
-		   It could be possible to move this over to RXTXVersion
55
-		   but All we want to do is warn people when first loading
56
-		   the Library.
57
-		*/
58
+		/**
59
+		*	Perform a crude check to make sure people don't mix
60
+		*	versions of the Jar and native lib
61
+		*
62
+		*	Mixing the libs can create a nightmare.
63
+		*	
64
+		*	It could be possible to move this over to RXTXVersion
65
+		*	but All we want to do is warn people when first loading
66
+		*	the Library.
67
+		**/
68
+		
69
 		String JarVersion = RXTXVersion.getVersion();
70
 		String LibVersion;
71
-		try {
72
-		        LibVersion = RXTXVersion.nativeGetVersion();
73
-		} catch ( Error UnsatisfiedLinkError )
74
+		
75
+		try 
76
+		{
77
+			LibVersion = RXTXVersion.nativeGetVersion();
78
+		} 
79
+		catch ( Error UnsatisfiedLinkError )
80
 		{
81
-			// for rxtx prior to 2.1.7
82
+			
83
+			/**
84
+			*	for rxtx prior to 2.1.7
85
+			**/
86
+			
87
 			LibVersion = nativeGetVersion();
88
 		}
89
-		if ( devel )
90
+		if (!debug)
91
 		{
92
 			if ( ! noVersionOutput )
93
 			{
94
-				System.out.println("Stable Library");
95
-				System.out.println("=========================================");
96
-				System.out.println("Native lib Version = " + LibVersion );
97
-				System.out.println("Java lib Version   = " + JarVersion );
98
+				System.out.println(" RXTX Comm  - Stable Library");
99
+				System.out.println(" =================================");
100
+				System.out.println(" Native lib Version = " + LibVersion);
101
+				System.out.println(" Java lib Version   = " + JarVersion);
102
 			}
103
+			
104
+		}
105
+		else
106
+		{
107
+			System.out.println(" ==================================");
108
+			System.out.println(" =                                =");
109
+			System.out.println(" = RXTX Comm - In Java DEBUG mode =");
110
+			System.out.println(" =                                =");
111
+			System.out.println(" ==================================");
112
+			
113
 		}
114
 
115
 		if ( ! JarVersion.equals( LibVersion ) )
116
 		{
117
-			System.out.println( "WARNING:  RXTX Version mismatch\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
118
+			System.out.println(" WARNING:  RXTX Version mismatch");
119
+			System.out.println(" ** Jar version = " + JarVersion);
120
+			System.out.println(" ** Native lib Version = " + LibVersion);
121
 		}
122
-		else if ( debug )
123
+		else if (debug)
124
 		{
125
-			System.out.println( "RXTXCommDriver:\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
126
+			System.out.println(" ** Jar version = " + JarVersion);
127
+			System.out.println(" ** Native lib Version = " + LibVersion);
128
 		}
129
+		
130
+		if(debug) System.out.println("RXTXCommDriver{}:Static:Exit");
131
+		
132
 	}
133
 
134
-	/** Get the Serial port prefixes for the running OS */
135
+	/** 
136
+	*	Get the Serial port prefixes for the running OS
137
+	**/
138
+	
139
 	private String deviceDirectory;
140
 	private String osName;
141
 	private native boolean registerKnownPorts(int PortType);
142
 	private native boolean isPortPrefixValid(String dev);
143
 	private native boolean testRead(String dev, int type);
144
 	private native String getDeviceDirectory();
145
-	// for rxtx prior to 2.1.7
146
+	
147
+	/**
148
+	*	for rxtx prior to 2.1.7
149
+	**/
150
+	
151
 	public static native String nativeGetVersion();
152
 
153
-	private final String[] getValidPortPrefixes(String CandidatePortPrefixes[])
154
+	private final String[] getValidPortPrefixes(
155
+		String CandidatePortPrefixes[]
156
+	)
157
 	{
158
-		/*
159
-		256 is the number of prefixes ( COM, cua, ttyS, ...) not
160
-		the number of devices (ttyS0, ttyS1, ttyS2, ...)
161
-
162
-		On a Linux system there are about 400 prefixes in
163
-		deviceDirectory.
164
-		registerScannedPorts() assigns CandidatePortPrefixes to
165
-		something less than 50 prefixes.
166
-
167
-		Trent
168
-		*/
169
-
170
+		/**
171
+		*  	256 is the number of prefixes ( COM, cua, ttyS, ...) not
172
+		*	the number of devices (ttyS0, ttyS1, ttyS2, ...)
173
+		*	
174
+		*	On a Linux system there are about 400 prefixes in
175
+		*	deviceDirectory.
176
+		*	registerScannedPorts() assigns CandidatePortPrefixes to
177
+		*	something less than 50 prefixes.
178
+		*
179
+		*	Trent
180
+		**/
181
+		
182
 		String ValidPortPrefixes[]=new String [256];
183
-		if (debug)
184
-			System.out.println("\nRXTXCommDriver:getValidPortPrefixes()");
185
+		
186
+		if (debug) System.out.println("RXTXCommDriver:getValidPortPrefixes()");
187
+		
188
 		if(CandidatePortPrefixes==null)
189
 		{
190
-			if (debug)
191
-				System.out.println("\nRXTXCommDriver:getValidPortPrefixes() No ports prefixes known for this System.\nPlease check the port prefixes listed for " + osName + " in RXTXCommDriver:registerScannedPorts()\n");
192
+			if (debug) 
193
+			{
194
+				System.out.println(" No ports prefixes known for this System.");
195
+				System.out.println(" Please check the port prefixes listed");
196
+				System.out.println(" for " + osName + " in registerScannedPorts()");
197
+			}
198
 		}
199
+		
200
 		int i=0;
201
-		for(int j=0;j<CandidatePortPrefixes.length;j++){
202
+		for(int j=0;j<CandidatePortPrefixes.length;j++)
203
+		{
204
 			if(isPortPrefixValid(CandidatePortPrefixes[j])) {
205
-				ValidPortPrefixes[i++]=
206
-					CandidatePortPrefixes[j];
207
+				ValidPortPrefixes[i++]= CandidatePortPrefixes[j];
208
 			}
209
 		}
210
+		
211
 		String[] returnArray=new String[i];
212
 		System.arraycopy(ValidPortPrefixes, 0, returnArray, 0, i);
213
+		
214
 		if(ValidPortPrefixes[0]==null)
215
 		{
216
 			if (debug)
217
 			{
218
-				System.out.println("\nRXTXCommDriver:getValidPortPrefixes() No ports matched the list assumed for this\nSystem in the directory " + deviceDirectory + ".  Please check the ports listed for \"" + osName + "\" in\nRXTXCommDriver:registerScannedPorts()\nTried:");
219
+				System.out.println(" No ports matched the list assumed for this");
220
+				System.out.println(" System in the directory " + deviceDirectory);
221
+				System.out.println(" Please check the ports listed for");
222
+				System.out.println(" \"" + osName + "\" in");
223
+				System.out.println(" RXTXCommDriver:registerScannedPorts()");
224
+				System.out.println(" Tried:");
225
 				for(int j=0;j<CandidatePortPrefixes.length;j++){
226
-					System.out.println("\t" +
227
-						CandidatePortPrefixes[i]);
228
+					System.out.println(" - " + CandidatePortPrefixes[i]);
229
 				}
230
 			}
231
 		}
232
 		else
233
 		{
234
 			if (debug)
235
-				System.out.println("\nRXTXCommDriver:getValidPortPrefixes()\nThe following port prefixes have been identified as valid on " + osName + ":\n");
236
-/*
237
-			for(int j=0;j<returnArray.length;j++)
238
 			{
239
-				if (debug)
240
-					System.out.println("\t" + j + " " +
241
-						returnArray[j]);
242
+				System.out.println(" The following port prefixes have been"); 
243
+				System.out.println(" identified as valid on " + osName + ":");
244
+				System.out.println(" -- ouput withheld --");
245
+			
246
+				/**
247
+				*	for(int j=0;j<returnArray.length;j++)
248
+				*	{
249
+				*	if (debug) System.out.println("\t" + j + " " + returnArray[j]);
250
+				*	}
251
+				**/
252
 			}
253
-*/
254
 		}
255
+		if (debug) System.out.println("RXTXCommDriver:getValidPortPrefixes:Exit");
256
+		
257
 		return returnArray;
258
+		
259
+		
260
+		
261
 	}
262
 
263
-	/** handle solaris/sunos /dev/cua/a convention */
264
-		private void checkSolaris(String PortName, int PortType)
265
+	/** 
266
+	*	handle solaris/sunos /dev/cua/a convention
267
+	**/
268
+	
269
+	private void checkSolaris(
270
+		String PortName, 
271
+		int PortType
272
+	)
273
 	{
274
+		System.out.println("RXTXCommDriver:checkSolaris()");
275
+		
276
 		char p[] =  { 91 };
277
+		
278
 		for( p[0] =97 ;p[0] < 123; p[0]++ )
279
 		{
280
 			if (testRead(PortName.concat(new String(p)),PortType))
281
@@ -206,7 +275,11 @@
282
 				);
283
 			}
284
 		}
285
-		/** check for 0-9 in case we have them (Solaris USB) */
286
+		
287
+		/**
288
+		*	check for 0-9 in case we have them (Solaris USB) 
289
+		**/
290
+		
291
 		for( p[0] =48 ;p[0] <= 57; p[0]++ )
292
 		{
293
 			if (testRead(PortName.concat(new String(p)),PortType))
294
@@ -218,73 +291,109 @@
295
 				);
296
 			}
297
 		}
298
+		
299
+		if (debug) System.out.println("RXTXCommDriver:checkSolaris:Exit");
300
 	}
301
-        private void registerValidPorts(
302
+	
303
+	private void registerValidPorts(
304
 		String CandidateDeviceNames[],
305
 		String ValidPortPrefixes[],
306
 		int PortType
307
-	) {
308
+	) 
309
+	{
310
+		if (debug) System.out.println("RXTXCommDriver:registerValidPorts(" + PortType + ")");
311
+		
312
 		int i =0;
313
-		int p =0 ;
314
-		/* FIXME quick fix to get COM1-8 on windows working.  The
315
-		   Read test is not working properly and its crunch time...
316
-		if(osName.toLowerCase().indexOf("windows") != -1 )
317
+		int p =0;
318
+		
319
+		/**
320
+		*	FIXME quick fix to get COM1-8 on windows working.  The
321
+		*	Read test is not working properly and its crunch time...
322
+		*	if(osName.toLowerCase().indexOf("windows") != -1 )
323
+		*	{
324
+		*		for( i=0;i < CandidateDeviceNames.length;i++ )
325
+		*		{
326
+		*			CommPortIdentifier.addPortName(
327
+		*				CandidateDeviceNames[i],
328
+		*				PortType, 
329
+		*				this
330
+		*			);
331
+		*		}
332
+		*		return;
333
+		*
334
+		*	}
335
+		**/
336
+		
337
+		if (debug)
338
 		{
339
-			for( i=0;i < CandidateDeviceNames.length;i++ )
340
+			
341
+			System.out.println(" Candidate Ports");
342
+			for (
343
+				int dn=0;
344
+				dn<CandidateDeviceNames.length;
345
+				dn++
346
+			)
347
 			{
348
-			CommPortIdentifier.addPortName( CandidateDeviceNames[i],
349
-							PortType, this );
350
+				System.out.println(" - " + CandidateDeviceNames[dn]);
351
+			}
352
+			System.out.println(" Valid port prefixes:");
353
+			for (
354
+				int pp=0;
355
+				pp<ValidPortPrefixes.length;
356
+				pp++
357
+			)
358
+			{
359
+				System.out.println(" - " + ValidPortPrefixes[pp]);
360
 			}
361
-			return;
362
-
363
-		}
364
-		*/
365
-		if (debug)
366
-		{
367
-			System.out.println("Entering registerValidPorts()");
368
-	/* */
369
-			System.out.println(" Candidate devices:");
370
-			for (int dn=0;dn<CandidateDeviceNames.length;dn++)
371
-				System.out.println("  "	+
372
-					CandidateDeviceNames[dn]);
373
-			System.out.println(" valid port prefixes:");
374
-			for (int pp=0;pp<ValidPortPrefixes.length;pp++)
375
-				System.out.println("  "+ValidPortPrefixes[pp]);
376
-	/* */
377
 		}
378
+		
379
 		if ( CandidateDeviceNames!=null && ValidPortPrefixes!=null)
380
 		{
381
-			for( i = 0;i<CandidateDeviceNames.length; i++ ) {
382
-				for( p = 0;p<ValidPortPrefixes.length; p++ ) {
383
-					/* this determines:
384
-					 * device file         Valid ports
385
-					 * /dev/ttyR[0-9]*  != /dev/ttyS[0-9]*
386
-					 * /dev/ttySI[0-9]* != /dev/ttyS[0-9]*
387
-					 * /dev/ttyS[0-9]*  == /dev/ttyS[0-9]*
388
-
389
-					 * Otherwise we check some ports
390
-					 * multiple times.  Perl would rock
391
-					 * here.
392
-					 *
393
-					 * If the above passes, we try to read
394
-					 * from the port.  If there is no err
395
-					 * the port is added.
396
-					 * Trent
397
-					 */
398
+			for( i = 0;i<CandidateDeviceNames.length; i++ )
399
+			{
400
+				for( p = 0;p<ValidPortPrefixes.length; p++ )
401
+				{
402
+					/**
403
+					*	this determines:
404
+					* 	device file Valid ports
405
+					* 	/dev/ttyR[0-9]*  != /dev/ttyS[0-9]*
406
+					* 	/dev/ttySI[0-9]* != /dev/ttyS[0-9]*
407
+					* 	/dev/ttyS[0-9]*  == /dev/ttyS[0-9]*
408
+					*
409
+					*	Otherwise we check some ports
410
+					*	multiple times.  Perl would rock
411
+					*	here.
412
+					*	
413
+					*	If the above passes, we try to read
414
+					*	from the port.  If there is no err
415
+					*	the port is added.
416
+					*	
417
+					*	Trent
418
+					**/
419
+					
420
 					String V =  ValidPortPrefixes[ p ];
421
-					int VL = V.length();
422
 					String C =   CandidateDeviceNames[ i ];
423
+					
424
+					int VL = V.length();
425
+					
426
 					if( C.length() < VL ) continue;
427
-					String CU =
428
-						C.substring(VL).toUpperCase();
429
-					String Cl =
430
-						C.substring(VL).toLowerCase();
431
-					if( !( C.regionMatches(0, V, 0, VL ) &&
432
-						CU.equals( Cl ) ) )
433
+					
434
+					String CU =	C.substring(VL).toUpperCase();
435
+					String Cl =	C.substring(VL).toLowerCase();
436
+					
437
+					if
438
+					(
439
+						!( 
440
+							C.regionMatches(0, V, 0, VL ) &&
441
+							CU.equals( Cl ) 
442
+						) 
443
+					)
444
 					{
445
 						continue;
446
 					}
447
+					
448
 					String PortName;
449
+					
450
 					if(osName.toLowerCase().indexOf("windows") == -1 )
451
 					{
452
 						PortName = deviceDirectory + C;
453
@@ -293,85 +402,136 @@
454
 					{
455
 						PortName = C;
456
 					}
457
+					
458
 					if (debug)
459
 					{
460
-						System.out.println( C +
461
-								" " + V );
462
-						System.out.println( CU +
463
-								" " + Cl );
464
+						System.out.println( " - " + C + " " + V );
465
+						System.out.println( " - " + CU + " " + Cl );
466
 					}
467
-					if( osName.equals("Solaris") ||
468
+					
469
+					if
470
+					(
471
+						osName.equals("Solaris") ||
472
 						osName.equals("SunOS"))
473
 						checkSolaris(PortName,PortType);
474
-					else if (testRead(PortName, PortType))
475
+					else 
476
 					{
477
-						CommPortIdentifier.addPortName(
478
+						if (debug) System.out.println(" CheckLPT is " + CheckLPT + " and PortType is" + PortType);
479
+						if ( (!CheckLPT) && (PortType!=1) )
480
+						{
481
+							/**
482
+							*	Don't attempt to check LPT ports,
483
+							*	if CheckLPT is set to false in env args
484
+							**/
485
+							
486
+							CommPortIdentifier.addPortName
487
+							(
488
 								PortName,
489
 								PortType,
490
 								this
491
-						);
492
+							);
493
+						}
494
+						else
495
+						{
496
+							if (testRead(PortName, PortType))
497
+							{
498
+								CommPortIdentifier.addPortName
499
+								(
500
+									PortName,
501
+									PortType,
502
+									this
503
+								);
504
+							}
505
+						}
506
+						
507
 					}
508
 				}
509
 			}
510
 		}
511
-		if (debug)
512
-			System.out.println("Leaving registerValidPorts()");
513
+		
514
+		if (debug) System.out.println("RXTXCommDriver:registerValidPorts:Exit");
515
+		
516
 	}
517
 
518
 
519
-   /*
520
-    * initialize() will be called by the CommPortIdentifier's static
521
-    * initializer. The responsibility of this method is:
522
-    * 1) Ensure that that the hardware is present.
523
-    * 2) Load any required native libraries.
524
-    * 3) Register the port names with the CommPortIdentifier.
525
-	*
526
-	* <p>From the NullDriver.java CommAPI sample.
527
-	*
528
-	* added printerport stuff
529
-	* Holger Lehmann
530
-	* July 12, 1999
531
-	* IBM
532
-
533
-	* Added ttyM for Moxa boards
534
-	* Removed obsolete device cuaa
535
-	* Peter Bennett
536
-	* January 02, 2000
537
-	* Bencom
538
-
539
-    */
540
+	/**
541
+	*	initialize() will be called by the CommPortIdentifier's static
542
+*	initializer. The responsibility of this method is:
543
+*	1) Ensure that that the hardware is present.
544
+*	2) Load any required native libraries.
545
+*	3) Register the port names with the CommPortIdentifier.
546
+	*	
547
+	*	<p>From the NullDriver.java CommAPI sample.
548
+	*	added printerport stuff
549
+	*	Holger Lehmann
550
+	*	July 12, 1999
551
+	*	IBM
552
+	* 	
553
+	* 	Added ttyM for Moxa boards
554
+	* 	Removed obsolete device cuaa
555
+	* 	Peter Bennett
556
+	* 	January 02, 2000
557
+	* 	Bencom
558
+**/
559
 
560
 	/**
561
-	*  Determine the OS and where the OS has the devices located
562
-	*/
563
+	*	Determine the OS and where the OS has the devices located
564
+	**/
565
 	public void initialize()
566
 	{
567
-
568
+		
569
 		if (debug) System.out.println("RXTXCommDriver:initialize()");
570
-
571
+		
572
 		osName=System.getProperty("os.name");
573
 		deviceDirectory=getDeviceDirectory();
574
-
575
-	/*
576
-	 First try to register ports specified in the properties
577
-	 file.  If that doesn't exist, then scan for ports.
578
-	*/
579
-		for (int PortType=CommPortIdentifier.PORT_SERIAL;PortType<=CommPortIdentifier.PORT_PARALLEL;PortType++) {
580
-			if (!registerSpecifiedPorts(PortType)) {
581
-				if (!registerKnownPorts(PortType)) {
582
+		
583
+		/**
584
+		*	First try to register ports specified in the properties
585
+		*	file.  If that doesn't exist, then scan for ports.
586
+		**/
587
+		
588
+		for 
589
+		(
590
+			int PortType=CommPortIdentifier.PORT_SERIAL;
591
+			PortType<=CommPortIdentifier.PORT_PARALLEL;
592
+			PortType++
593
+		)
594
+		{
595
+			/**
596
+			*	Load prefixes for all ports from env and file pairs
597
+			**/
598
+			if (!registerSpecifiedPorts(PortType))
599
+			{
600
+				
601
+				/**
602
+				*	Load OS knoow ports (APPLE thing)
603
+				**/
604
+				if (!registerKnownPorts(PortType)) 
605
+				{
606
+					
607
+					/**
608
+					*	Load ports via a scan...
609
+					**/
610
 					registerScannedPorts(PortType);
611
 				}
612
 			}
613
 		}
614
+		
615
+		if (debug) System.out.println("RXTXCommDriver:initialize:Exit");
616
+		
617
 	}
618
 
619
-	private void addSpecifiedPorts(String names, int PortType)
620
+	private void addSpecifiedPorts(
621
+		String names, 
622
+		int PortType
623
+	)
624
 	{
625
+		
626
+		if (debug) System.out.println("RXTXCommDriver:addSpecifiedPorts()");
627
+			
628
 		final String pathSep = System.getProperty("path.separator", ":");
629
 		final StringTokenizer tok = new StringTokenizer(names, pathSep);
630
 
631
-		if (debug)
632
-			System.out.println("\nRXTXCommDriver:addSpecifiedPorts()");
633
 		while (tok.hasMoreElements())
634
 		{
635
 			String PortName = tok.nextToken();
636
@@ -380,94 +540,186 @@
637
 				CommPortIdentifier.addPortName(PortName,
638
 					PortType, this);
639
 		}
640
+		
641
+		if (debug) System.out.println("RXTXCommDriver:addSpecifiedPorts:Exit");
642
+		
643
 	}
644
 
645
-   /*
646
-    * Register ports specified in the file "gnu.io.rxtx.properties"
647
-    * Key system properties:
648
-    *                   gnu.io.rxtx.SerialPorts
649
-    * 			gnu.io.rxtx.ParallelPorts
650
-    *
651
-    * Tested only with sun jdk1.3
652
-    * The file gnu.io.rxtx.properties must reside in the java extension dir
653
-    *
654
-    * Example: /usr/local/java/jre/lib/ext/gnu.io.rxtx.properties
655
-    *
656
-    * The file contains the following key properties:
657
-    *
658
-    *  gnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:
659
-    *  gnu.io.rxtx.ParallelPorts=/dev/lp0:
660
-    *
661
-    */
662
-	private boolean registerSpecifiedPorts(int PortType)
663
+	/**
664
+*	Register ports specified in the file "gnu.io.rxtx.properties"
665
+*	Key system properties:
666
+*	gnu.io.rxtx.SerialPorts
667
+*	gnu.io.rxtx.ParallelPorts
668
+*	
669
+*	Tested only with sun jdk1.3
670
+* 
671
+*	The file gnu.io.rxtx.properties must reside in the java extension dir
672
+*	
673
+*	Example: /usr/local/java/jre/lib/ext/gnu.io.rxtx.properties
674
+*	
675
+*	The file contains the following key properties:
676
+*	
677
+*  	gnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:
678
+*  	gnu.io.rxtx.ParallelPorts=/dev/lp0:
679
+*	
680
+**/
681
+	private boolean registerSpecifiedPorts(
682
+		int PortType
683
+	)
684
 	{
685
+		if (debug) System.out.println("RXTXCommDriver:registerSpecifiedPorts(" + PortType + ")");
686
+		
687
+		final String pathSep = System.getProperty("path.separator", ":");
688
+		final String fileSep = System.getProperty("file.separator");
689
 		String val = null;
690
-		Properties origp = System.getProperties();//save system properties
691
-
692
-		try
693
-		    {
694
-
695
-		     String ext_dir=System.getProperty("java.ext.dirs")+System.getProperty("file.separator");
696
-		     FileInputStream rxtx_prop=new FileInputStream(ext_dir+"gnu.io.rxtx.properties");
697
-		     Properties p=new Properties();
698
-		     p.load(rxtx_prop);
699
-		     System.setProperties(p);
700
-		     for (Iterator it = p.keySet().iterator(); it.hasNext();) {
701
-		          String key = (String) it.next();
702
-		          System.setProperty(key, p.getProperty(key));
703
-		     }
704
-		    }catch(Exception e){
705
-			if (debug){
706
-			    System.out.println("The file: gnu.io.rxtx.properties doesn't exists.");
707
-			    System.out.println(e.toString());
708
-			    }//end if
709
-			}//end catch
710
-
711
-		if (debug)
712
-			System.out.println("checking for system-known ports of type "+PortType);
713
+		String err_str = null;
714
+		String ext_loc[];
715
+		boolean props_loaded = false;
716
+		
717
+		/**
718
+		*	Save System properties, to restore on func exit.
719
+		**/
720
+		
721
+		Properties origp = System.getProperties();
722
+		
723
+		String ext_dir=System.getProperty("java.ext.dirs");
724
+		
725
+		if (ext_dir.length() > 0)
726
+		{
727
+			
728
+			if (ext_dir.indexOf(":") > 0)
729
+			{
730
+				ext_loc = ext_dir.split(pathSep);
731
+			}
732
+			else
733
+			{
734
+				ext_loc = new String[1];
735
+				ext_loc[1] = ext_dir;
736
+				
737
+			}
738
+			
739
+			for (
740
+				int el=0;
741
+				el<ext_loc.length;
742
+				el++
743
+			)
744
+			{
745
+				ext_loc[el] = ext_loc[el] + fileSep;
746
+				
747
+				if (debug)
748
+					System.out.println(" - searching config location " + ext_loc[el]);
749
+				
750
+				try
751
+				{
752
+					FileInputStream rxtx_prop=new FileInputStream(ext_loc[el] + "gnu.io.rxtx.properties");
753
+					Properties p=new Properties();
754
+					p.load(rxtx_prop);
755
+					System.setProperties(p);
756
+					for (Iterator it = p.keySet().iterator(); it.hasNext();)
757
+					{
758
+						String key = (String) it.next();
759
+						System.setProperty(key, p.getProperty(key));
760
+					}
761
+				}
762
+				catch(Exception e)
763
+				{
764
+					err_str = e.toString();
765
+					
766
+					if (debug)
767
+					{
768
+						if (err_str.indexOf("java.io.FileNotFoundException") < 0)
769
+						{
770
+							System.out.println(err_str);
771
+						}
772
+						else
773
+						{
774
+							System.out.println("   -> The file '" + ext_loc[el] + "gnu.io.rxtx.properties' doesn't exists.");
775
+						}
776
+					}
777
+				}
778
+			}
779
+		}
780
 		if (debug)
781
-			System.out.println("checking registry for ports of type "+PortType);
782
+			System.out.println(" Checking Environment Properties for ports of type " + PortType);
783
 
784
 		switch (PortType) {
785
 			case CommPortIdentifier.PORT_SERIAL:
786
 				if ((val = System.getProperty("gnu.io.rxtx.SerialPorts")) == null)
787
-				val = System.getProperty("gnu.io.SerialPorts");
788
+				{
789
+					val = System.getProperty("gnu.io.SerialPorts");
790
+					if (debug)
791
+						System.out.println(" - Capture gnu.io.SerialPorts = '" + val + "' where Port Type =" + PortType);
792
+				}
793
 				break;
794
 
795
 			case CommPortIdentifier.PORT_PARALLEL:
796
 				if ((val = System.getProperty("gnu.io.rxtx.ParallelPorts")) == null)
797
-				val = System.getProperty("gnu.io.ParallelPorts");
798
+				{
799
+					val = System.getProperty("gnu.io.ParallelPorts");
800
+					if (debug)
801
+						System.out.println(" - Capture gnu.io.ParallelPorts = '" + val + "' where Port Type =" + PortType);
802
+				}
803
 				break;
804
 			default:
805
 				if (debug)
806
-				System.out.println("unknown port type "+PortType+" passed to RXTXCommDriver.registerSpecifiedPorts()");
807
+				System.out.println(" !!ERROR - Unknown port type " + PortType + " passed to RXTXCommDriver.registerSpecifiedPorts()");
808
 		}
809
 
810
+		/**
811
+		*	Not sure if the following line undoes the properties load, 
812
+		*	or just ensures properties before the proc is called are
813
+		*	not manipulated.  Anti-injection?  - We've finished with
814
+		*	them anyway...
815
+		**/
816
 		System.setProperties(origp); //recall saved properties
817
-		if (val != null) {
818
+		
819
+		if (val != null)
820
+		{
821
+			
822
 			addSpecifiedPorts(val, PortType);
823
+			if (debug) 
824
+			{
825
+				System.out.println(" = Ports added from Environmental Properties");
826
+				System.out.println("RXTXCommDriver:registerSpecifiedPorts(True):Exit");
827
+			}
828
 			return true;
829
-		} else {
830
+		}
831
+		else 
832
+		{
833
+			if (debug) System.out.println("RXTXCommDriver:registerSpecifiedPorts(False):Exit");
834
 			return false;
835
 		}
836
 	}
837
 
838
-   /*
839
-    * Look for all entries in deviceDirectory, and if they look like they should
840
-    * be serial ports on this OS and they can be opened then register
841
-    * them.
842
-    *
843
-    */
844
-	private void registerScannedPorts(int PortType)
845
+	/**
846
+	*	Look for all entries in deviceDirectory, and if they look like they should
847
+	*	be serial ports on this OS and they can be opened then register
848
+	*	them.
849
+	**/
850
+
851
+	private void registerScannedPorts(
852
+		int PortType
853
+	)
854
 	{
855
-		String[] CandidateDeviceNames;
856
-		if (debug)
857
-			System.out.println("scanning device directory "+deviceDirectory+" for ports of type "+PortType);
858
+		if (debug) System.out.println("RXTXCommDriver:registerScannedPorts(" + PortType + ")");
859
+		
860
+		String[] 	CandidateDeviceNames;
861
+		int 		iFound;
862
+		
863
+		if (debug) System.out.println(" Scanning " + deviceDirectory + " for ports of type " + PortType);
864
+		
865
 		if(osName.equals("Windows CE"))
866
 		{
867
-			String[] temp =
868
-			{ "COM1:", "COM2:","COM3:","COM4:",
869
-			"COM5:", "COM6:", "COM7:", "COM8:" };
870
+			String[] temp = {
871
+				"COM1:",
872
+				"COM2:",
873
+				"COM3:",
874
+				"COM4:",
875
+				"COM5:",
876
+				"COM6:",
877
+				"COM7:",
878
+				"COM8:"
879
+			};
880
 			CandidateDeviceNames=temp;
881
 		}
882
 		else if(osName.toLowerCase().indexOf("windows") != -1 )
883
@@ -482,329 +734,338 @@
884
 				temp[i + 255] = "LPT" + i;
885
 			}
886
 			CandidateDeviceNames=temp;
887
-			}
888
-			else if ( osName.equals("Solaris") || osName.equals("SunOS"))
889
-			{
890
-			/* Solaris uses a few different ways to identify ports.
891
-			   They could be /dev/term/a /dev/term0 /dev/cua/a /dev/cuaa
892
-			   the /dev/???/a appears to be on more systems.
893
-
894
-			   The uucp lock files should not cause problems.
895
-			*/
896
-	/*
897
-				File dev = new File( "/dev/term" );
898
-				String deva[] = dev.list();
899
-				dev = new File( "/dev/cua" );
900
-				String devb[] = dev.list();
901
-				String[] temp = new String[ deva.length + devb.length ];
902
-				for(int j =0;j<deva.length;j++)
903
-					deva[j] = "term/" + deva[j];
904
-				for(int j =0;j<devb.length;j++)
905
-					devb[j] = "cua/" + devb[j];
906
-				System.arraycopy( deva, 0, temp, 0, deva.length );
907
-				System.arraycopy( devb, 0, temp,
908
-						deva.length, devb.length );
909
-				if( debug ) {
910
-					for( int j = 0; j< temp.length;j++)
911
-						System.out.println( temp[j] );
912
-				}
913
-				CandidateDeviceNames=temp;
914
-	*/
915
-
916
-			/*
917
-
918
-				ok..  Look the the dirctories representing the port
919
-				kernel driver interface.
920
-
921
-				If there are entries there are possibly ports we can
922
-				use and need to enumerate.
923
+		}
924
+		else if ( osName.equals("Solaris") || osName.equals("SunOS"))
925
+		{
926
+			/**
927
+			*	Solaris uses a few different ways to identify ports.
928
+			*	They could be /dev/term/a /dev/term0 /dev/cua/a /dev/cuaa
929
+			*	the /dev/???/a appears to be on more systems.
930
+			*
931
+			*	The uucp lock files should not cause problems.
932
 			*/
933
-
934
-				String term[] = new String[2];
935
-				int l = 0;
936
-				File dev = null;
937
-
938
-				dev = new File( "/dev/term" );
939
-				if( dev.list().length > 0 )
940
-					term[l++] ="term/";
941
-	/*
942
-				dev = new File( "/dev/cua0" );
943
-				if( dev.list().length > 0 )
944
-					term[l++] = "cua/";
945
-	*/
946
-				String[] temp = new String[l];
947
-				for(l--;l >= 0;l--)
948
-					temp[l] = term[l];
949
-				CandidateDeviceNames=temp;
950
-			}
951
-			else
952
-			{
953
-				File dev = new File( deviceDirectory );
954
-				String[] temp = dev.list();
955
-				CandidateDeviceNames=temp;
956
-			}
957
-			if (CandidateDeviceNames==null)
958
-			{
959
-				if (debug)
960
-					System.out.println("RXTXCommDriver:registerScannedPorts() no Device files to check ");
961
+			
962
+			/**
963
+			*	File dev = new File( "/dev/term" );
964
+			*	String deva[] = dev.list();
965
+			*	dev = new File( "/dev/cua" );
966
+			*	String devb[] = dev.list();
967
+			*	String[] temp = new String[ deva.length + devb.length ];
968
+			*	for(int j =0;j<deva.length;j++)
969
+			*		deva[j] = "term/" + deva[j];
970
+			*	for(int j =0;j<devb.length;j++)
971
+			*		devb[j] = "cua/" + devb[j];
972
+			*	System.arraycopy( deva, 0, temp, 0, deva.length );
973
+			*	System.arraycopy( devb, 0, temp,
974
+			*			deva.length, devb.length );
975
+			*	if( debug ) {
976
+			*		for( int j = 0; j< temp.length;j++)
977
+			*			System.out.println( temp[j] );
978
+			*	}
979
+			*	CandidateDeviceNames=temp;
980
+			**/
981
+
982
+			/**
983
+			*	ok..  Look the the dirctories representing the port
984
+			*	kernel driver interface.
985
+			*
986
+			*	If there are entries there are possibly ports we can
987
+			*	use and need to enumerate.
988
+			**/
989
+
990
+			String term[] = new String[2];
991
+			int l = 0;
992
+			File dev = null;
993
+			dev = new File( "/dev/term" );
994
+			if( dev.list().length > 0 ) term[l++] ="term/";
995
+			
996
+			/**
997
+			*	dev = new File( "/dev/cua0" );
998
+			*	if( dev.list().length > 0 ) term[l++] = "cua/";
999
+			**/
1000
+			
1001
+			String[] temp = new String[l];
1002
+			for(l--;l >= 0;l--) temp[l] = term[l];
1003
+			CandidateDeviceNames=temp;
1004
+		}
1005
+		else
1006
+		{
1007
+			File dev = new File( deviceDirectory );
1008
+			String[] temp = dev.list();
1009
+			CandidateDeviceNames=temp;
1010
+		}
1011
+		
1012
+		if (CandidateDeviceNames==null)
1013
+		{
1014
+				if (debug) System.out.println(" No device files to check ");
1015
 				return;
1016
-			}
1017
-
1018
-			String CandidatePortPrefixes[] = {};
1019
-			switch (PortType) {
1020
-				case CommPortIdentifier.PORT_SERIAL:
1021
-					if (debug)
1022
-						System.out.println("scanning for serial ports for os "+osName);
1023
-
1024
-
1025
-			/*  There are _many_ possible ports that can be used
1026
-			    on Linux.  See below in the fake Linux-all-ports  
1027
-			    case for a list.  You may add additional ports
1028
-			    here but be warned that too many will significantly
1029
-			    slow down port enumeration.  Linux 2.6 has udev
1030
-			    support which should be faster as only ports the
1031
-			    kernel finds should be exposed in /dev
1032
-
1033
-			    See also how to override port enumeration and
1034
-			    specifying port in INSTALL.
1035
-
1036
-			    taj
1037
-			*/
1038
-
1039
-					if(osName.equals("Linux"))
1040
-					{
1041
-						String[] Temp = {
1042
-						"ttyS", // linux Serial Ports
1043
-						"ttySA", // for the IPAQs
1044
-						"ttyUSB", // for USB frobs
1045
-						"rfcomm",       // bluetooth serial device
1046
-						"ttyircomm", // linux IrCommdevices (IrDA serial emu)
1047
-						};
1048
-						CandidatePortPrefixes=Temp;
1049
-					}
1050
-					else if(osName.equals("Linux-all-ports"))
1051
-					{
1052
-					/* if you want to enumerate all ports ~5000
1053
-					   possible, then replace the above with this
1054
-					*/
1055
-						String[] Temp = {
1056
-						"comx",      // linux COMMX synchronous serial card
1057
-						"holter",    // custom card for heart monitoring
1058
-						"modem",     // linux symbolic link to modem.
1059
-						"rfcomm",       // bluetooth serial device
1060
-						"ttyircomm", // linux IrCommdevices (IrDA serial emu)
1061
-						"ttycosa0c", // linux COSA/SRP synchronous serial card
1062
-						"ttycosa1c", // linux COSA/SRP synchronous serial card
1063
-						"ttyACM",// linux CDC ACM devices
1064
-						"ttyC", // linux cyclades cards
1065
-						"ttyCH",// linux Chase Research AT/PCI-Fast serial card
1066
-						"ttyD", // linux Digiboard serial card
1067
-						"ttyE", // linux Stallion serial card
1068
-						"ttyF", // linux Computone IntelliPort serial card
1069
-						"ttyH", // linux Chase serial card
1070
-						"ttyI", // linux virtual modems
1071
-						"ttyL", // linux SDL RISCom serial card
1072
-						"ttyM", // linux PAM Software's multimodem boards
1073
-							// linux ISI serial card
1074
-						"ttyMX",// linux Moxa Smart IO cards
1075
-						"ttyP", // linux Hayes ESP serial card
1076
-						"ttyR", // linux comtrol cards
1077
-							// linux Specialix RIO serial card
1078
-						"ttyS", // linux Serial Ports
1079
-						"ttySI",// linux SmartIO serial card
1080
-						"ttySR",// linux Specialix RIO serial card 257+
1081
-						"ttyT", // linux Technology Concepts serial card
1082
-						"ttyUSB",//linux USB serial converters
1083
-						"ttyV", // linux Comtrol VS-1000 serial controller
1084
-						"ttyW", // linux specialix cards
1085
-						"ttyX"  // linux SpecialX serial card
1086
-						};
1087
-						CandidatePortPrefixes=Temp;
1088
-					}
1089
-					else if(osName.toLowerCase().indexOf("qnx") != -1 )
1090
-					{
1091
-						String[] Temp = {
1092
-							"ser"
1093
-						};
1094
-						CandidatePortPrefixes=Temp;
1095
-					}
1096
-					else if(osName.equals("Irix"))
1097
-					{
1098
-						String[] Temp = {
1099
-							"ttyc", // irix raw character devices
1100
-							"ttyd", // irix basic serial ports
1101
-							"ttyf", // irix serial ports with hardware flow
1102
-							"ttym", // irix modems
1103
-							"ttyq", // irix pseudo ttys
1104
-							"tty4d",// irix RS422
1105
-							"tty4f",// irix RS422 with HSKo/HSki
1106
-							"midi", // irix serial midi
1107
-							"us"    // irix mapped interface
1108
-						};
1109
-						CandidatePortPrefixes=Temp;
1110
-					}
1111
-					else if(osName.equals("FreeBSD")) //FIXME this is probably wrong
1112
-					{
1113
-						String[] Temp = {
1114
-							"ttyd",    //general purpose serial ports
1115
-							"cuaa",    //dialout serial ports
1116
-							"ttyA",    //Specialix SI/XIO dialin ports
1117
-							"cuaA",    //Specialix SI/XIO dialout ports
1118
-							"ttyD",    //Digiboard - 16 dialin ports
1119
-							"cuaD",    //Digiboard - 16 dialout ports
1120
-							"ttyE",    //Stallion EasyIO (stl) dialin ports
1121
-							"cuaE",    //Stallion EasyIO (stl) dialout ports
1122
-							"ttyF",    //Stallion Brumby (stli) dialin ports
1123
-							"cuaF",    //Stallion Brumby (stli) dialout ports
1124
-							"ttyR",    //Rocketport dialin ports
1125
-							"cuaR",    //Rocketport dialout ports
1126
-							"stl"      //Stallion EasyIO board or Brumby N 
1127
-						};
1128
-						CandidatePortPrefixes=Temp;
1129
-					}
1130
-					else if(osName.equals("NetBSD")) // FIXME this is probably wrong
1131
-					{
1132
-						String[] Temp = {
1133
-							"tty0"  // netbsd serial ports
1134
-						};
1135
-						CandidatePortPrefixes=Temp;
1136
-					}
1137
-					else if ( osName.equals("Solaris")
1138
-							|| osName.equals("SunOS"))
1139
-					{
1140
-						String[] Temp = {
1141
-							"term/",
1142
-							"cua/"
1143
-						};
1144
-						CandidatePortPrefixes=Temp;
1145
-					}
1146
-					else if(osName.equals("HP-UX"))
1147
-					{
1148
-						String[] Temp = {
1149
-							"tty0p",// HP-UX serial ports
1150
-							"tty1p" // HP-UX serial ports
1151
-						};
1152
-						CandidatePortPrefixes=Temp;
1153
-					}
1154
+		}
1155
+		else
1156
+		{
1157
+			int found = CandidateDeviceNames.length;
1158
+			if (debug) System.out.println(" Found " + found + " devices files to check");
1159
+		}
1160
 
1161
-					else if(osName.equals("UnixWare") ||
1162
-							osName.equals("OpenUNIX"))
1163
-					{
1164
-						String[] Temp = {
1165
-							"tty00s", // UW7/OU8 serial ports
1166
-							"tty01s",
1167
-							"tty02s",
1168
-							"tty03s"
1169
-						};
1170
-						CandidatePortPrefixes=Temp;
1171
-					}
1172
+		String CandidatePortPrefixes[] = {};
1173
+		
1174
+		switch (PortType) {
1175
+			case CommPortIdentifier.PORT_SERIAL:
1176
+				if (debug) System.out.println(" scanning for serial ports for os " + osName);
1177
+				
1178
+				/**
1179
+				*	There are _many_ possible ports that can be used
1180
+				*	on Linux.  See below in the fake Linux-all-ports  
1181
+				*	case for a list.  You may add additional ports
1182
+				*	here but be warned that too many will significantly
1183
+				*	slow down port enumeration.  Linux 2.6 has udev
1184
+				*	support which should be faster as only ports the
1185
+				*	kernel finds should be exposed in /dev
1186
+				*	
1187
+				*	See also how to override port enumeration and
1188
+				*	specifying port in INSTALL.
1189
+				*	
1190
+				*	taj
1191
+				**/
1192
 
1193
+				if(osName.equals("Linux"))
1194
+				{
1195
+					String[] Temp = {
1196
+					"ttyS",		// linux Serial Ports
1197
+					"ttySA",	// for the IPAQs
1198
+					"ttyUSB",	// for USB frobs
1199
+					"rfcomm",   // bluetooth serial device
1200
+					"ttyircomm"	// linux IrCommdevices (IrDA serial emu)
1201
+					};
1202
+					CandidatePortPrefixes=Temp;
1203
+				}
1204
+				else if(osName.equals("Linux-all-ports"))
1205
+				{
1206
+					/**
1207
+					*	If you want to enumerate all ports ~5000
1208
+					*	possible, then replace the above with this
1209
+					**/
1210
+					
1211
+					String[] Temp = {
1212
+						"comx",  // linux COMMX synchronous serial card
1213
+						"holter",// custom card for heart monitoring
1214
+						"modem", // linux symbolic link to modem.
1215
+						"rfcomm",   // bluetooth serial device
1216
+						"ttyircomm",	// linux IrCommdevices (IrDA serial emu)
1217
+						"ttycosa0c",	// linux COSA/SRP synchronous serial card
1218
+						"ttycosa1c",	// linux COSA/SRP synchronous serial card
1219
+						"ttyACM",		// linux CDC ACM devices
1220
+						"ttyC",			// linux cyclades cards
1221
+						"ttyCH",		// linux Chase Research AT/PCI-Fast serial card
1222
+						"ttyD",			// linux Digiboard serial card
1223
+						"ttyE",			// linux Stallion serial card
1224
+						"ttyF",			// linux Computone IntelliPort serial card
1225
+						"ttyH",			// linux Chase serial card
1226
+						"ttyI",			// linux virtual modems
1227
+						"ttyL",			// linux SDL RISCom serial card
1228
+						"ttyM",			// linux PAM Software's multimodem boards
1229
+						"ttyMX",		// linux Moxa Smart IO cards
1230
+						"ttyP",			// linux Hayes ESP serial card
1231
+						"ttyR",			// linux comtrol cards
1232
+						"ttyS",			// linux Serial Ports
1233
+						"ttySI",		// linux SmartIO serial card
1234
+						"ttySR",		// linux Specialix RIO serial card 257+
1235
+						"ttyT",			// linux Technology Concepts serial card
1236
+						"ttyUSB",		//linux USB serial converters
1237
+						"ttyV",			// linux Comtrol VS-1000 serial controller
1238
+						"ttyW",			// linux specialix cards
1239
+						"ttyX"			// linux SpecialX serial card
1240
+					};
1241
+					
1242
+					CandidatePortPrefixes=Temp;
1243
+				}
1244
+				else if(osName.toLowerCase().indexOf("qnx") != -1 )
1245
+				{
1246
+					String[] Temp = {
1247
+						"ser"
1248
+					};
1249
+					CandidatePortPrefixes=Temp;
1250
+				}
1251
+				else if(osName.equals("Irix"))
1252
+				{
1253
+					String[] Temp = {
1254
+						"ttyc",	// irix raw character devices
1255
+						"ttyd", // irix basic serial ports
1256
+						"ttyf", // irix serial ports with hardware flow
1257
+						"ttym", // irix modems
1258
+						"ttyq", // irix pseudo ttys
1259
+						"tty4d",// irix RS422
1260
+						"tty4f",// irix RS422 with HSKo/HSki
1261
+						"midi", // irix serial midi
1262
+						"us"	// irix mapped interface
1263
+					};
1264
+					CandidatePortPrefixes=Temp;
1265
+				}
1266
+				else if(osName.equals("FreeBSD")) 
1267
+				//See here: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/serial.html
1268
+				{
1269
+					String[] Temp = {
1270
+						"ttyu",	//general purpose serial ports
1271
+						"ttyU",	//general purpose serial ports (UArduino Drv)
1272
+						"cuau",	//general purpose serial ports (post v10)
1273
+						"cuaU",	//general purpose serial ports (UARduino Drv)
1274
+						"cuad",	//general purpose serial ports (pre v10)
1275
+						"ttyd",	//general purpose serial ports
1276
+						
1277
+						//Historic <v8 - Not sure if drvs still work?
1278
+						"cuaa",	//dialout serial ports
1279
+						"ttyA",	//Specialix SI/XIO dialin ports
1280
+						"cuaA",	//Specialix SI/XIO dialout ports
1281
+						"ttyD",	//Digiboard - 16 dialin ports
1282
+						"cuaD",	//Digiboard - 16 dialout ports
1283
+						"ttyE",	//Stallion EasyIO (stl) dialin ports
1284
+						"cuaE",	//Stallion EasyIO (stl) dialout ports
1285
+						"ttyF",	//Stallion Brumby (stli) dialin ports
1286
+						"cuaF",	//Stallion Brumby (stli) dialout ports
1287
+						"ttyR",	//Rocketport dialin ports
1288
+						"cuaR",	//Rocketport dialout ports
1289
+						"stl"	//Stallion EasyIO board or Brumby N
1290
+					};
1291
+					CandidatePortPrefixes=Temp;
1292
+				}
1293
+				else if(osName.equals("NetBSD")) // FIXME this is probably wrong
1294
+				{
1295
+					String[] Temp = {
1296
+						"tty0"	// netbsd serial ports
1297
+					};
1298
+					CandidatePortPrefixes=Temp;
1299
+				}
1300
+				else if ( osName.equals("Solaris") || osName.equals("SunOS"))
1301
+				{
1302
+					String[] Temp = {
1303
+						"term/",
1304
+						"cua/"
1305
+					};
1306
+					CandidatePortPrefixes=Temp;
1307
+				}
1308
+				else if(osName.equals("HP-UX"))
1309
+				{
1310
+					String[] Temp = {
1311
+						"tty0p",	// HP-UX serial ports
1312
+						"tty1p"		// HP-UX serial ports
1313
+					};
1314
+					CandidatePortPrefixes=Temp;
1315
+				}
1316
+				else if(osName.equals("UnixWare") || osName.equals("OpenUNIX"))
1317
+				{
1318
+					String[] Temp = {
1319
+						"tty00s",	// UW7/OU8 serial ports
1320
+						"tty01s",
1321
+						"tty02s",
1322
+						"tty03s"
1323
+					};
1324
+					CandidatePortPrefixes=Temp;
1325
+				}
1326
 				else if	(osName.equals("OpenServer"))
1327
-					{
1328
-						String[] Temp = {
1329
-							"tty1A",  // OSR5 serial ports
1330
-							"tty2A",
1331
-							"tty3A",
1332
-							"tty4A",
1333
-							"tty5A",
1334
-							"tty6A",
1335
-							"tty7A",
1336
-							"tty8A",
1337
-							"tty9A",
1338
-							"tty10A",
1339
-							"tty11A",
1340
-							"tty12A",
1341
-							"tty13A",
1342
-							"tty14A",
1343
-							"tty15A",
1344
-							"tty16A",
1345
-							"ttyu1A", // OSR5 USB-serial ports
1346
-							"ttyu2A",
1347
-							"ttyu3A",
1348
-							"ttyu4A",
1349
-							"ttyu5A",
1350
-							"ttyu6A",
1351
-							"ttyu7A",
1352
-							"ttyu8A",
1353
-							"ttyu9A",
1354
-							"ttyu10A",
1355
-							"ttyu11A",
1356
-							"ttyu12A",
1357
-							"ttyu13A",
1358
-							"ttyu14A",
1359
-							"ttyu15A",
1360
-							"ttyu16A"
1361
-						};
1362
-						CandidatePortPrefixes=Temp;
1363
-					}
1364
-					else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
1365
-					{
1366
-						String[] Temp = {
1367
-							"tty0"  //  Digital Unix serial ports
1368
-						};
1369
-						CandidatePortPrefixes=Temp;
1370
-					}
1371
-
1372
+				{
1373
+					String[] Temp = {
1374
+						"tty1A",	// OSR5 serial ports
1375
+						"tty2A",
1376
+						"tty3A",
1377
+						"tty4A",
1378
+						"tty5A",
1379
+						"tty6A",
1380
+						"tty7A",
1381
+						"tty8A",
1382
+						"tty9A",
1383
+						"tty10A",
1384
+						"tty11A",
1385
+						"tty12A",
1386
+						"tty13A",
1387
+						"tty14A",
1388
+						"tty15A",
1389
+						"tty16A",
1390
+						"ttyu1A",	// OSR5 USB-serial ports
1391
+						"ttyu2A",
1392
+						"ttyu3A",
1393
+						"ttyu4A",
1394
+						"ttyu5A",
1395
+						"ttyu6A",
1396
+						"ttyu7A",
1397
+						"ttyu8A",
1398
+						"ttyu9A",
1399
+						"ttyu10A",
1400
+						"ttyu11A",
1401
+						"ttyu12A",
1402
+						"ttyu13A",
1403
+						"ttyu14A",
1404
+						"ttyu15A",
1405
+						"ttyu16A"
1406
+					};
1407
+					CandidatePortPrefixes=Temp;
1408
+				}
1409
+				else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
1410
+				{
1411
+					String[] Temp = {
1412
+						"tty0"	// Digital Unix serial ports
1413
+					};
1414
+					CandidatePortPrefixes=Temp;
1415
+				}
1416
 					else if(osName.equals("BeOS"))
1417
-					{
1418
-						String[] Temp = {
1419
-							"serial" // BeOS serial ports
1420
-						};
1421
-						CandidatePortPrefixes=Temp;
1422
-					}
1423
-					else if(osName.equals("Mac OS X"))
1424
-					{
1425
-						String[] Temp = {
1426
-						// Keyspan USA-28X adapter, USB port 1
1427
-							"cu.KeyUSA28X191.",
1428
-						// Keyspan USA-28X adapter, USB port 1
1429
-							"tty.KeyUSA28X191.",
1430
-						// Keyspan USA-28X adapter, USB port 2
1431
-							"cu.KeyUSA28X181.",
1432
-						// Keyspan USA-28X adapter, USB port 2
1433
-							"tty.KeyUSA28X181.",
1434
-						// Keyspan USA-19 adapter
1435
-							"cu.KeyUSA19181.",
1436
-						// Keyspan USA-19 adapter
1437
-							"tty.KeyUSA19181."
1438
-						};
1439
-						CandidatePortPrefixes=Temp;
1440
-					}
1441
-					else if(osName.toLowerCase().indexOf("windows") != -1 )
1442
-					{
1443
-						String[] Temp = {
1444
-							"COM"     // win32 serial ports
1445
-							//"//./COM"    // win32 serial ports
1446
+				{
1447
+					String[] Temp = {
1448
+						"serial"	// BeOS serial ports
1449
+					};
1450
+					CandidatePortPrefixes=Temp;
1451
+				}
1452
+				else if(osName.equals("Mac OS X"))
1453
+				{
1454
+					String[] Temp = {
1455
+						"cu.KeyUSA28X191.",		// Keyspan USA-28X adapter, USB port 1
1456
+						"tty.KeyUSA28X191.",	// Keyspan USA-28X adapter, USB port 1
1457
+						"cu.KeyUSA28X181.", 	// Keyspan USA-28X adapter, USB port 2
1458
+						"tty.KeyUSA28X181.", 	// Keyspan USA-28X adapter, USB port 2
1459
+						"cu.KeyUSA19181.", 		// Keyspan USA-19 adapter
1460
+						"tty.KeyUSA19181." 		// Keyspan USA-19 adapter
1461
+					};
1462
+					CandidatePortPrefixes=Temp;
1463
+				}
1464
+				else if(osName.toLowerCase().indexOf("windows") != -1 )
1465
+				{
1466
+					String[] Temp = {
1467
+						"COM"		// win32 serial ports
1468
+						//"//./COM"	// win32 serial ports (piped)
1469
 					};
1470
 					CandidatePortPrefixes=Temp;
1471
 				}
1472
 				else
1473
 				{
1474
-					if (debug)
1475
-						System.out.println("No valid prefixes for serial ports have been entered for "+osName + " in RXTXCommDriver.java.  This may just be a typo in the method registerScanPorts().");
1476
+					if (debug) System.out.println("No valid prefixes for serial ports have been entered for "+osName + " in RXTXCommDriver.java.  This may just be a typo in the method registerScanPorts().");
1477
 				}
1478
+				
1479
+				iFound = CandidateDeviceNames.length;
1480
+				if (debug) System.out.println("Found " + iFound + " port prefixes on " + osName + " for port type " + PortType);
1481
 				break;
1482
 
1483
 			case CommPortIdentifier.PORT_PARALLEL:
1484
-				if (debug)
1485
-					System.out.println("scanning for parallel ports for os "+osName);
1486
-			/** Get the Parallel port prefixes for the running os
1487
-			* Holger Lehmann
1488
-			* July 12, 1999
1489
-			* IBM
1490
-			*/
1491
+			
1492
+				if (debug) System.out.println("scanning for parallel ports for os "+osName);
1493
+				
1494
+				/** 
1495
+				*	Get the Parallel port prefixes for the running os
1496
+				*	Holger Lehmann
1497
+				*	July 12, 1999
1498
+				*	IBM
1499
+				**/
1500
+				
1501
 				if(osName.equals("Linux")
1502
-			/*
1503
-				|| osName.equals("NetBSD") FIXME
1504
-				|| osName.equals("HP-UX")  FIXME
1505
-				|| osName.equals("Irix")   FIXME
1506
-				|| osName.equals("BeOS")   FIXME
1507
-				|| osName.equals("Compaq's Digital UNIX")   FIXME
1508
-			*/
1509
+				
1510
+				/**
1511
+				*	|| osName.equals("NetBSD") FIXME
1512
+				*	|| osName.equals("HP-UX")  FIXME
1513
+				*	|| osName.equals("Irix")   FIXME
1514
+				*	|| osName.equals("BeOS")   FIXME
1515
+				*	|| osName.equals("Compaq's Digital UNIX")   FIXME
1516
+				**/
1517
+				
1518
 				)
1519
 				{
1520
 					String[] temp={
1521
-						"lp"    // linux printer port
1522
+						"lp"	// linux printer port
1523
 					};
1524
 					CandidatePortPrefixes=temp;
1525
 				}
1526
@@ -827,37 +1088,51 @@
1527
 					String [] temp={};
1528
 					CandidatePortPrefixes=temp;
1529
 				}
1530
+				
1531
+				iFound = CandidateDeviceNames.length;
1532
+				if (debug) System.out.println("Found " + iFound + " port prefixes on " + osName + " for port type " + PortType);
1533
+				
1534
 				break;
1535
+				
1536
 			default:
1537
-				if (debug)
1538
-					System.out.println("Unknown PortType "+PortType+" passed to RXTXCommDriver.registerScannedPorts()");
1539
+				if (debug) System.out.println(" Unknown PortType " + PortType + " passed to RXTXCommDriver.registerScannedPorts()");
1540
 		}
1541
-		registerValidPorts(CandidateDeviceNames, CandidatePortPrefixes, PortType);
1542
+		
1543
+		registerValidPorts(
1544
+			CandidateDeviceNames,
1545
+			CandidatePortPrefixes,
1546
+			PortType
1547
+		);
1548
+		
1549
+		if (debug) System.out.println("RXTXCommDriver:registerScannedPorts:Exit");
1550
+		
1551
 	}
1552
 
1553
 
1554
-	/*
1555
-	 * <p>From the NullDriver.java CommAPI sample.
1556
-	 */
1557
 	/**
1558
-	*  @param PortName The name of the port the OS recognizes
1559
-	*  @param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
1560
-	*  @return CommPort
1561
-	*  getCommPort() will be called by CommPortIdentifier from its
1562
-	*  openPort() method. PortName is a string that was registered earlier
1563
-	*  using the CommPortIdentifier.addPortName() method. getCommPort()
1564
-	*  returns an object that extends either SerialPort or ParallelPort.
1565
-	*/
1566
-	public CommPort getCommPort( String PortName, int PortType )
1567
+	* <p>From the NullDriver.java CommAPI sample.
1568
+	*	
1569
+	*	@param PortName The name of the port the OS recognizes
1570
+	*	@param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
1571
+	*	@return CommPort
1572
+	*	getCommPort() will be called by CommPortIdentifier from its
1573
+	*	openPort() method. PortName is a string that was registered earlier
1574
+	*	using the CommPortIdentifier.addPortName() method. getCommPort()
1575
+	*	returns an object that extends either SerialPort or ParallelPort.
1576
+	**/
1577
+	
1578
+	public CommPort getCommPort(
1579
+		String PortName, 
1580
+		int PortType
1581
+	)
1582
 	{
1583
-		if (debug) System.out.println("RXTXCommDriver:getCommPort("
1584
-			+PortName+","+PortType+")");
1585
-		try {
1586
+		if (debug) System.out.println("RXTXCommDriver:getCommPort(" + PortName + "," + PortType + ")");
1587
+		try
1588
+		{
1589
 			switch (PortType) {
1590
 				case CommPortIdentifier.PORT_SERIAL:
1591
 					if(osName.toLowerCase().indexOf("windows") == -1 )
1592
-					{
1593
-					
1594
+					{		
1595
 						return new RXTXPort( PortName );
1596
 					}
1597
 					else
1598
@@ -868,18 +1143,30 @@
1599
 					return new LPRPort( PortName );
1600
 				default:
1601
 					if (debug)
1602
-						System.out.println("unknown PortType  "+PortType+" passed to RXTXCommDriver.getCommPort()");
1603
+						System.out.println(" Unknown PortType  "+PortType+" passed to RXTXCommDriver.getCommPort()");
1604
 			}
1605
-		} catch( PortInUseException e ) {
1606
-			if (debug)
1607
-				System.out.println(
1608
-					"Port "+PortName+" in use by another application");
1609
 		}
1610
+		catch( PortInUseException e )
1611
+		{
1612
+			if (debug) System.out.println(" Port "+PortName+" in use by another application");
1613
+		}
1614
+		
1615
+		if (debug) System.out.println("RXTXCommDriver:getCommPort:Exit");
1616
+		
1617
 		return null;
1618
+		
1619
+		
1620
+		
1621
 	}
1622
 
1623
-	/*  Yikes.  Trying to call println from C for odd reasons */
1624
-	public void Report( String arg )
1625
+	/**
1626
+	*	Yikes.
1627
+	*	Trying to call println from C for odd reasons
1628
+	**/
1629
+	
1630
+	public void Report(
1631
+		String arg
1632
+	)
1633
 	{
1634
 		System.out.println(arg);
1635
 	}
(-)files/patch-src-gnu-io-RXTXPort.java (+2840 lines)
Line 0 Link Here
1
--- src/gnu/io/RXTXPort.java.orig	2008-11-13 23:37:45.000000000 +0000
2
+++ src/gnu/io/RXTXPort.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -56,6 +56,7 @@
4
 |   All trademarks belong to their respective owners.
5
 --------------------------------------------------------------------------*/
6
 package gnu.io;
7
+
8
 import java.io.InputStream;
9
 import java.io.OutputStream;
10
 import java.io.IOException;
11
@@ -65,93 +66,133 @@
12
 /**
13
 * An extension of gnu.io.SerialPort
14
 * @see gnu.io.SerialPort
15
-*/
16
+**/
17
 
18
 final public class RXTXPort extends SerialPort
19
 {
20
-	/* I had a report that some JRE's complain when MonitorThread
21
-	   tries to access private variables
22
-	*/
23
+	/** 
24
+	*	I had a report that some JRE's complain when MonitorThread
25
+	*	 tries to access private variables
26
+	**/
27
 
28
-	protected final static boolean debug = false;
29
+	protected final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
30
 	protected final static boolean debug_read = false;
31
 	protected final static boolean debug_read_results = false;
32
 	protected final static boolean debug_write = false;
33
-	protected final static boolean debug_events = false;
34
+	protected final static boolean debug_events = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );;
35
 	protected final static boolean debug_verbose = false;
36
 
37
 	private static Zystem z;
38
 
39
 	static
40
 	{
41
-		try {
42
+		if (debug) System.out.println("RXTXPort:Static()");
43
+		
44
+		try 
45
+		{
46
 			z = new Zystem();
47
-		} catch ( Exception e ) {}
48
+		} 
49
+		catch (Exception e) 
50
+		{
51
+			if (debug) System.out.println("RXTXPort:Static:Exception Thrown");	
52
+		}
53
 
54
-		if(debug ) 
55
-			z.reportln( "RXTXPort {}");
56
-		System.loadLibrary( "rxtxSerial" );
57
+		if(debug) System.out.println(" Loading Library...");
58
+		
59
+		System.loadLibrary("rxtxSerial" );
60
+		
61
+		if(debug) System.out.println(" Initializing...");
62
+		
63
 		Initialize();
64
+		
65
+		if(debug) System.out.println("RXTXPort:Static:Exit");
66
+		
67
 	}
68
 
69
-	/** Initialize the native library */
70
+	/**
71
+	*	Initialize the native library
72
+	**/
73
+	
74
 	private native static void Initialize();
75
+	
76
 	boolean MonitorThreadAlive=false;
77
 
78
 	/** 
79
-	*  Open the named port
80
-	*  @param name the name of the device to open
81
-	*  @throws  PortInUseException
82
-	*  @see gnu.io.SerialPort
83
-	*/
84
-	public RXTXPort( String name ) throws PortInUseException
85
-	{
86
-		if (debug)
87
-			z.reportln( "RXTXPort:RXTXPort("+name+") called");
88
-	/* 
89
-	   commapi/javadocs/API_users_guide.html specifies that whenever
90
-	   an application tries to open a port in use by another application
91
-	   the PortInUseException will be thrown
92
-
93
-	   I know some didnt like it this way but I'm not sure how to avoid
94
-	   it.  We will just be writing to a bogus fd if we catch the 
95
-	   exeption
96
-
97
-	   Trent
98
-	*/
99
-	//	try {
100
-			fd = open( name );
101
-			this.name = name;
102
-
103
-			MonitorThreadLock = true;
104
-			monThread = new MonitorThread();
105
-			monThread.start();
106
-			waitForTheNativeCodeSilly();
107
-			MonitorThreadAlive=true;
108
-	//	} catch ( PortInUseException e ){}
109
-		timeout = -1;	/* default disabled timeout */
110
-		if (debug)
111
-			z.reportln( "RXTXPort:RXTXPort("+name+") returns with fd = " +
112
-				fd);
113
+	*	Open the named port
114
+	*	@param	name the name of the device to open
115
+	*	@throws	PortInUseException
116
+	*	@see	gnu.io.SerialPort
117
+	**/
118
+	
119
+	public RXTXPort( String name )
120
+	throws PortInUseException
121
+	{
122
+		if (debug) System.out.println("RXTXPort:RXTXPort(" + name + ")");
123
+		
124
+		/**
125
+		*	commapi/javadocs/API_users_guide.html specifies that whenever
126
+		*	an application tries to open a port in use by another application
127
+		*	the PortInUseException will be thrown
128
+		*	
129
+		*	I know some didnt like it this way but I'm not sure how to avoid
130
+		*	it.  We will just be writing to a bogus fd if we catch the 
131
+		*	exeption
132
+		*	
133
+		*	Trent
134
+		**/
135
+	
136
+		/**
137
+		*	try {
138
+		**/
139
+		
140
+		fd = open( name );
141
+		this.name = name;
142
+		
143
+		MonitorThreadLock = true;
144
+		monThread = new MonitorThread();
145
+		monThread.start();
146
+		waitForTheNativeCodeSilly();
147
+		MonitorThreadAlive=true;
148
+		
149
+		/**
150
+		*	} catch ( PortInUseException e ){}
151
+		**/
152
+		
153
+		/**
154
+		*	default disabled timeout
155
+		**/
156
+		
157
+		timeout = -1;	
158
+		
159
+		if (debug) System.out.println(
160
+			"RXTXPort:RXTXPort(" + name + ") returns with fd = " + fd
161
+		);
162
 	}
163
+	
164
 	private native synchronized int open( String name )
165
-		throws PortInUseException;
166
+	throws PortInUseException;
167
 
168
 
169
-	/* dont close the file while accessing the fd */
170
+	/**
171
+	*	dont close the file while accessing the fd
172
+	**/
173
+	
174
 	int IOLocked = 0;
175
+	
176
 	Object IOLockedMutex = new Object();
177
 
178
 	/** File descriptor */
179
 	private int fd = 0;
180
 
181
-	/** a pointer to the event info structure used to share information
182
-	    between threads so write threads can send output buffer empty
183
-	    from a pthread if need be.
184
-
185
-	    long for 64 bit pointers.
186
-	*/
187
+	/**
188
+	*	a pointer to the event info structure used to share information
189
+	*	between threads so write threads can send output buffer empty
190
+	*	from a pthread if need be.
191
+	*	
192
+	*	long for 64 bit pointers.
193
+	**/
194
 	long eis = 0;
195
+	
196
 	/** pid for lock files */
197
 	int pid = 0;
198
 
199
@@ -160,142 +201,202 @@
200
 
201
 	/** Output stream */
202
 	private final SerialOutputStream out = new SerialOutputStream();
203
+	
204
 	/** 
205
-	*  get the OutputStream
206
-	*  @return OutputStream
207
-	*/
208
+	*	get the OutputStream
209
+	*	@return	OutputStream
210
+	**/
211
 	public OutputStream getOutputStream()
212
 	{
213
 		if (debug)
214
-			z.reportln( "RXTXPort:getOutputStream() called and returning");
215
+		{
216
+			System.out.println(
217
+				"RXTXPort:getOutputStream()"
218
+			);
219
+		}
220
+		
221
 		return out;
222
+		
223
 	}
224
 
225
 	/** Input stream */
226
 	private final SerialInputStream in = new SerialInputStream();
227
+	
228
 	/** 
229
-	*  get the InputStream
230
-	*  @return InputStream
231
-	*  @see java.io.InputStream
232
-	*/
233
+	*	get the InputStream
234
+	*	@return	InputStream
235
+	*	@see	java.io.InputStream
236
+	**/
237
+	
238
 	public InputStream getInputStream()
239
 	{
240
 		if (debug)
241
-			z.reportln( "RXTXPort:getInputStream() called and returning");
242
+		{
243
+			System.out.println(
244
+				"RXTXPort:getInputStream:Exit"
245
+			);
246
+		}
247
 		return in;
248
 	}
249
 
250
-	/** 
251
-	*  Set the SerialPort parameters
252
-	*  1.5 stop bits requires 5 databits
253
-	*  @param  b baudrate
254
-	*  @param  d databits
255
-	*  @param  s stopbits
256
-	*  @param  p parity
257
-	*  @throws UnsupportedCommOperationException
258
-	*  @see gnu.io.UnsupportedCommOperationException
259
-
260
-	*  If speed is not a predifined speed it is assumed to be
261
-	*  the actual speed desired.
262
-	*/
263
 	private native int nativeGetParity( int fd );
264
 	private native int nativeGetFlowControlMode( int fd );
265
-	public synchronized void setSerialPortParams( int b, int d, int s,
266
-		int p )
267
-		throws UnsupportedCommOperationException
268
-	{
269
-		if (debug)
270
-			z.reportln( "RXTXPort:setSerialPortParams(" +
271
-				b + " " + d + " " + s + " " + p + ") called");
272
+	
273
+	/** 
274
+	*	Set the SerialPort parameters
275
+	*	1.5 stop bits requires 5 databits
276
+	*	@param  b baudrate
277
+	*	@param  d databits
278
+	*	@param  s stopbits
279
+	*	@param  p parity
280
+	*	@throws UnsupportedCommOperationException
281
+	*	@see gnu.io.UnsupportedCommOperationException
282
+	*	
283
+	*	If speed is not a predifined speed it is assumed to be
284
+	*	the actual speed desired.
285
+	**/
286
+	
287
+	public synchronized void setSerialPortParams(
288
+		int b, 
289
+		int d,
290
+		int s,
291
+		int p
292
+	)
293
+	throws UnsupportedCommOperationException
294
+	{
295
+		if (debug) System.out.println(
296
+			"RXTXPort:setSerialPortParams(b:" + b + " d:" + d + " s:" + s + " p:" + p + ")"
297
+		);
298
 		if ( nativeSetSerialPortParams( b, d, s, p ) )
299
-			throw new UnsupportedCommOperationException(
300
-				"Invalid Parameter" );
301
+		{
302
+			throw new UnsupportedCommOperationException
303
+			(
304
+				"Invalid Parameter" 
305
+			);
306
+		}
307
+		
308
 		speed = b;
309
-		if( s== STOPBITS_1_5 ) dataBits = DATABITS_5;
310
-		else dataBits = d;
311
+		
312
+		if( s== STOPBITS_1_5 )
313
+		{
314
+			dataBits = DATABITS_5;
315
+		}
316
+		else
317
+		{
318
+			dataBits = d;
319
+		}
320
+		
321
 		stopBits = s;
322
 		parity = p;
323
-			z.reportln( "RXTXPort:setSerialPortParams(" +
324
-				b + " " + d + " " + s + " " + p +
325
-				") returning");
326
+		
327
+		if (debug) System.out.println(
328
+			"RXTXPort:setSerialPortParams(b:" + b + " d:" + d + " s:" + s + " p:" + p + "):Exit"
329
+		);
330
+		
331
 	}
332
 
333
 	/**
334
-	*  Set the native serial port parameters
335
-	*  If speed is not a predifined speed it is assumed to be
336
-	*  the actual speed desired.
337
-	*/
338
-	private native boolean nativeSetSerialPortParams( int speed,
339
-		int dataBits, int stopBits, int parity )
340
-		throws UnsupportedCommOperationException;
341
+	*	Set the native serial port parameters
342
+	*	If speed is not a predifined speed it is assumed to be
343
+	*	the actual speed desired.
344
+	**/
345
+	private native boolean nativeSetSerialPortParams(
346
+		int speed,
347
+		int dataBits,
348
+		int stopBits,
349
+		int parity
350
+	)
351
+	throws UnsupportedCommOperationException;
352
 
353
 	/** Line speed in bits-per-second */
354
 	private int speed=9600;
355
+	
356
 	/** 
357
-	*  @return  int representing the baudrate
358
-	*  This will not behave as expected with custom speeds
359
-	*/
360
+	*	@return  int representing the baudrate
361
+	*	This will not behave as expected with custom speeds
362
+	**/
363
+	
364
 	public int getBaudRate()
365
 	{
366
 		if (debug)
367
-			z.reportln( "RXTXPort:getBaudRate() called and returning " + speed);
368
+		{
369
+			System.out.println(
370
+				"RXTXPort:getBaudRate:Exit" + speed
371
+			);
372
+		}
373
 		return speed;
374
 	}
375
 
376
-	/** Data bits port parameter */
377
+	/**
378
+	* Data bits port parameter 
379
+	**/
380
+	
381
 	private int dataBits=DATABITS_8;
382
+	
383
 	/** 
384
-	*  @return int representing the databits
385
-	*/
386
+	*	@return int representing the databits
387
+	**/
388
 	public int getDataBits()
389
 	{
390
 		if (debug)
391
-			z.reportln( "RXTXPort:getDataBits() called and returning " + dataBits);
392
+			System.out.println("RXTXPort:getDataBits(" + dataBits + ")");
393
 		return dataBits;
394
 	}
395
 
396
 	/** Stop bits port parameter */
397
 	private int stopBits=SerialPort.STOPBITS_1;
398
+	
399
 	/** 
400
-	*  @return int representing the stopbits
401
-	*/
402
+	*	@return int representing the stopbits
403
+	**/
404
 	public int getStopBits()
405
 	{
406
-		if (debug)
407
-			z.reportln( "RXTXPort:getStopBits() called and returning " + stopBits);
408
+		if (debug) System.out.println( 
409
+			"RXTXPort:getStopBits(" + stopBits + ")"
410
+		);
411
 		return stopBits;
412
 	}
413
 
414
 	/** Parity port parameter */
415
 	private int parity= SerialPort.PARITY_NONE;
416
+	
417
 	/** 
418
-	*  @return int representing the parity
419
-	*/
420
+	*	@return int representing the parity
421
+	**/
422
 	public int getParity()
423
 	{
424
-		if (debug)
425
-			z.reportln( "RXTXPort:getParity() called and returning " + parity );
426
+		if (debug) System.out.println(
427
+			"RXTXPort:getParity(" + parity +")"
428
+		);
429
+		
430
 		return parity;
431
 	}
432
 
433
 
434
 	/** Flow control */
435
 	private int flowmode = SerialPort.FLOWCONTROL_NONE;
436
+	
437
 	/** 
438
-	*  @param  flowcontrol FLOWCONTROL_NONE is default
439
-	*  @see gnu.io.SerialPort#FLOWCONTROL_NONE
440
-	*/
441
+	*	@param  flowcontrol FLOWCONTROL_NONE is default
442
+	*	@see gnu.io.SerialPort#FLOWCONTROL_NONE
443
+	**/
444
 	public void setFlowControlMode( int flowcontrol )
445
 	{
446
-		if (debug)
447
-			z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) called");
448
+		if (debug) System.out.println(
449
+			"RXTXPort:setFlowControlMode(" + flowcontrol + ")"
450
+		);
451
+		
452
 		if(monThreadisInterrupted) 
453
 		{
454
-			if( debug_events )
455
-				z.reportln(  "RXTXPort:setFlowControlMode MonThread is Interrupeted returning" );
456
+			if (debug_events) System.out.println(
457
+				"RXTXPort:setFlowControlMode:MonThread Interrupted"
458
+			);
459
+			
460
 			return;
461
 		}
462
-		try {
463
+		
464
+		try 
465
+		{
466
 			setflowcontrol( flowcontrol );
467
 		}
468
 		catch( IOException e )
469
@@ -303,61 +404,75 @@
470
 			e.printStackTrace();
471
 			return;
472
 		}
473
+		
474
 		flowmode=flowcontrol;
475
-		if (debug)
476
-			z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) returning");
477
+		
478
+		if (debug) System.out.println(
479
+			"RXTXPort:setFlowControlMode(" + flowcontrol + " ):Exit"
480
+		);
481
 	}
482
+	
483
 	/** 
484
-	*  @return  int representing the flowmode
485
-	*/
486
+	*	@return  int representing the flowmode
487
+	**/
488
 	public int getFlowControlMode()
489
 	{
490
-		if (debug)
491
-			z.reportln( "RXTXPort:getFlowControlMode() returning " + flowmode );
492
+		if (debug) System.out.println(
493
+			"RXTXPort:getFlowControlMode(" + flowmode + ")"
494
+		);
495
+		
496
 		return flowmode;
497
 	}
498
+	
499
 	native void setflowcontrol( int flowcontrol ) throws IOException;
500
 
501
 
502
-	/*
503
-	linux/drivers/char/n_hdlc.c? FIXME
504
-		taj@www.linux.org.uk
505
-	*/
506
 	/**
507
-	*  Receive framing control
508
-	*  @param  f framming
509
-	*  @throws UnsupportedCommOperationException
510
-	*/
511
+	*	linux/drivers/char/n_hdlc.c? FIXME
512
+	*	taj@www.linux.org.uk
513
+	**/
514
+	
515
+	/**
516
+	*	Receive framing control
517
+	*	@param	f framming
518
+	*	@throws	UnsupportedCommOperationException
519
+	**/
520
 	public void enableReceiveFraming( int f )
521
-		throws UnsupportedCommOperationException
522
+	throws UnsupportedCommOperationException
523
 	{
524
-		if (debug)
525
-			z.reportln( "RXTXPort:enableReceiveFramming() throwing exception");
526
-		throw new UnsupportedCommOperationException( "Not supported" );
527
+		if (debug) System.out.println(
528
+			"RXTXPort:enableReceiveFramming() throwing exception"
529
+		);
530
+		
531
+		throw new UnsupportedCommOperationException("Not supported" );
532
 	}
533
-	/** 
534
-	*/
535
+	
536
 	public void disableReceiveFraming()
537
 	{
538
-		if (debug)
539
-			z.reportln( "RXTXPort:disableReceiveFramming() called and returning (noop)");
540
+		if (debug) System.out.println(
541
+			"RXTXPort:disableReceiveFramming()"
542
+		);
543
 	}
544
+	
545
 	/** 
546
-	*  @return true if framing is enabled
547
-	*/
548
+	*	@return true if framing is enabled
549
+	**/
550
 	public boolean isReceiveFramingEnabled()
551
 	{
552
-		if (debug)
553
-			z.reportln( "RXTXPort:isReceiveFrammingEnabled() called and returning " + false );
554
+		if (debug) System.out.println(
555
+			"RXTXPort:isReceiveFrammingEnabled(" + false +")"
556
+		);
557
 		return false;
558
 	}
559
 	/** 
560
-	*  @return  int representing the framing byte
561
-	*/
562
+	*	@return  int representing the framing byte
563
+	**/
564
 	public int getReceiveFramingByte()
565
 	{
566
-		if (debug)
567
-			z.reportln( "RXTXPort:getReceiveFrammingByte() called and returning " + 0 );
568
+		if (debug) System.out.println(
569
+			"RXTXPort:getReceiveFrammingByte(0)" 
570
+		);
571
+		
572
 		return 0;
573
 	}
574
 
575
@@ -366,38 +481,49 @@
576
 	private int timeout;
577
 
578
 	/** 
579
-	*  @return  int the timeout
580
-	*/
581
+	*	@return  int the timeout
582
+	**/
583
 	public native int NativegetReceiveTimeout();
584
+	
585
 	/** 
586
-	*  @return  bloolean true if recieve timeout is enabled
587
-	*/
588
+	*	@return  bloolean true if recieve timeout is enabled
589
+	**/
590
 	private native boolean NativeisReceiveTimeoutEnabled();
591
+	
592
 	/** 
593
-	*  @param  time
594
-	*  @param  threshold
595
-	*  @param  InputBuffer
596
-	*/
597
-	private native void NativeEnableReceiveTimeoutThreshold(int time,
598
-		int threshold,int InputBuffer);
599
-	/** 
600
-	*/
601
+	*	@param  time
602
+	*	@param  threshold
603
+	*	@param  InputBuffer
604
+	**/
605
+	private native void NativeEnableReceiveTimeoutThreshold(
606
+		int time,
607
+		int threshold,
608
+		int InputBuffer
609
+	);
610
+	
611
 	public void disableReceiveTimeout()
612
 	{
613
-		if (debug)
614
-			z.reportln( "RXTXPort:disableReceiveTimeout() called");
615
+		if (debug) System.out.println(
616
+			"RXTXPort:disableReceiveTimeout()"
617
+		);
618
+		
619
 		timeout = -1;
620
+		
621
 		NativeEnableReceiveTimeoutThreshold( timeout , threshold, InputBuffer );
622
-		if (debug)
623
-			z.reportln( "RXTXPort:disableReceiveTimeout() returning");
624
+		
625
+		if (debug) System.out.println(
626
+			"RXTXPort:disableReceiveTimeout:Exit"
627
+		);
628
 	}
629
+	
630
 	/** 
631
-	*  @param time
632
-	*/
633
+	*	@param time
634
+	**/
635
 	public void enableReceiveTimeout( int time )
636
 	{
637
 		if (debug)
638
-			z.reportln( "RXTXPort:enableReceiveTimeout() called");
639
+			System.out.println("RXTXPort:enableReceiveTimeout(" + time + ")");
640
+			
641
 		if( time >= 0 )
642
 		{
643
 			timeout = time;
644
@@ -411,25 +537,26 @@
645
 				"Unexpected negative timeout value"
646
 			);
647
 		}
648
+		
649
 		if (debug)
650
-			z.reportln( "RXTXPort:enableReceiveTimeout() returning");
651
+			System.out.println("RXTXPort:enableReceiveTimeout:Exit");
652
 	}
653
 	/** 
654
-	*  @return  boolean true if recieve timeout is enabled
655
-	*/
656
+	*	@return  boolean true if recieve timeout is enabled
657
+	**/
658
 	public boolean isReceiveTimeoutEnabled()
659
 	{
660
 		if (debug)
661
-			z.reportln( "RXTXPort:isReceiveTimeoutEnabled() called and returning " + NativeisReceiveTimeoutEnabled() );
662
+			System.out.println("RXTXPort:isReceiveTimeoutEnabled:Exit" + NativeisReceiveTimeoutEnabled() );
663
 		return( NativeisReceiveTimeoutEnabled() );
664
 	}
665
 	/** 
666
-	*  @return  int the timeout
667
-	*/
668
+	*	@return  int the timeout
669
+	**/
670
 	public int getReceiveTimeout()
671
 	{
672
 		if (debug)
673
-			z.reportln( "RXTXPort:getReceiveTimeout() called and returning " + NativegetReceiveTimeout() );
674
+			System.out.println("RXTXPort:getReceiveTimeout:Exit" + NativegetReceiveTimeout() );
675
 		return(NativegetReceiveTimeout( ));
676
 	}
677
 
678
@@ -438,12 +565,12 @@
679
 	private int threshold = 0;
680
 
681
 	/** 
682
-	*  @param thresh threshold
683
-	*/
684
+	*	@param thresh threshold
685
+	**/
686
 	public void enableReceiveThreshold( int thresh )
687
 	{
688
 		if (debug)
689
-			z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) called");
690
+			System.out.println("RXTXPort:enableReceiveThreshold(" + thresh + " ) called");
691
 		if(thresh >=0)
692
 		{
693
 			threshold=thresh;
694
@@ -458,32 +585,32 @@
695
 			);
696
 		}
697
 		if (debug)
698
-			z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) returned");
699
+			System.out.println("RXTXPort:enableReceiveThreshold(" + thresh + " ) returned");
700
 	}
701
 	/** 
702
-	*/
703
+	**/
704
 	public void disableReceiveThreshold()
705
 	{
706
 		if (debug)
707
-			z.reportln( "RXTXPort:disableReceiveThreshold() called and returning");
708
+			System.out.println("RXTXPort:disableReceiveThreshold:Exit");
709
 		enableReceiveThreshold(0);
710
 	}
711
 	/** 
712
-	*  @return  int the recieve threshold
713
-	*/
714
+	*	@return  int the recieve threshold
715
+	**/
716
 	public int getReceiveThreshold()
717
 	{
718
 		if (debug)
719
-			z.reportln( "RXTXPort:getReceiveThreshold() called and returning " + threshold);
720
+			System.out.println("RXTXPort:getReceiveThreshold:Exit" + threshold);
721
 		return threshold;
722
 	}
723
 	/** 
724
-	*  @return  boolean true if receive threshold is enabled
725
-	*/
726
+	*	@return  boolean true if receive threshold is enabled
727
+	**/
728
 	public boolean isReceiveThresholdEnabled()
729
 	{
730
 		if (debug)
731
-			z.reportln( "RXTXPort:isReceiveThresholdEnable() called and returning" + (threshold > 0) );
732
+			System.out.println("RXTXPort:isReceiveThresholdEnable:Exit" + (threshold > 0) );
733
 		return(threshold>0);
734
 	}
735
 
736
@@ -493,16 +620,17 @@
737
 		taj@www.linux.org.uk
738
 
739
 		These are native stubs...
740
-	*/
741
+	**/
742
 	private int InputBuffer=0;
743
 	private int OutputBuffer=0;
744
+	
745
 	/** 
746
-	*  @param size
747
-	*/
748
+	*	@param size
749
+	**/
750
 	public void setInputBufferSize( int size )
751
 	{
752
 		if (debug)
753
-			z.reportln( "RXTXPort:setInputBufferSize( " +
754
+			System.out.println("RXTXPort:setInputBufferSize(" +
755
 					size + ") called");
756
 		if( size < 0 )
757
 			throw new IllegalArgumentException
758
@@ -511,103 +639,139 @@
759
 			);
760
 		else InputBuffer=size;
761
 		if (debug)
762
-			z.reportln( "RXTXPort:setInputBufferSize( " +
763
+			System.out.println("RXTXPort:setInputBufferSize(" +
764
 					size + ") returning");
765
 	}
766
-	/** 
767
-	*/
768
+
769
 	public int getInputBufferSize()
770
 	{
771
-		if (debug)
772
-			z.reportln( "RXTXPort:getInputBufferSize() called and returning " + InputBuffer );
773
+		if (debug) System.out.println(
774
+			"RXTXPort:getInputBufferSize(" + InputBuffer +")"
775
+		);
776
 		return(InputBuffer);
777
 	}
778
+	
779
 	/** 
780
-	*  @param size
781
-	*/
782
+	*	@param size
783
+	**/
784
 	public void setOutputBufferSize( int size )
785
 	{
786
-		if (debug)
787
-			z.reportln( "RXTXPort:setOutputBufferSize( " +
788
-					size + ") called");
789
+		if (debug) System.out.println(
790
+			"RXTXPort:setOutputBufferSize(" + size + ") called"
791
+		);
792
+		
793
 		if( size < 0 )
794
-			throw new IllegalArgumentException
795
-			(
796
-				"Unexpected negative buffer size value"
797
-			);
798
-		else OutputBuffer=size;
799
-		if (debug)
800
-			z.reportln( "RXTXPort:setOutputBufferSize( " +
801
-					size + ") returned");
802
+		{
803
+		throw new IllegalArgumentException
804
+		(
805
+			"Unexpected negative buffer size value"
806
+		);
807
+		}
808
+		else
809
+		{
810
+			OutputBuffer=size;
811
+		}
812
+		
813
+		if (debug) System.out.println(
814
+			"RXTXPort:setOutputBufferSize(" + size + "):Exit"
815
+		);
816
 		
817
 	}
818
+
819
 	/** 
820
-	*  @return  in the output buffer size
821
-	*/
822
+	*	@return  in the output buffer size
823
+	**/
824
 	public int getOutputBufferSize()
825
 	{
826
-		if (debug)
827
-			z.reportln( "RXTXPort:getOutputBufferSize() called and returning " + OutputBuffer );
828
+		if (debug) System.out.println(
829
+			"RXTXPort:getOutputBufferSize(" + OutputBuffer + ")"
830
+		);
831
 		return(OutputBuffer);
832
 	}
833
 
834
-	/* =================== cleaned messages to here */
835
+	/**
836
+	*	=================== cleaned messages to here
837
+	**/
838
 
839
 	/**
840
-	*  Line status methods
841
-	*/
842
+	*	Line status methods
843
+	**/
844
 	/**
845
-	*  @return true if DTR is set
846
-	*/
847
+	*	@return true if DTR is set
848
+	**/
849
 	public native boolean isDTR();
850
+	
851
 	/** 
852
-	*  @param state
853
-	*/
854
+	*	@param state
855
+	**/
856
 	public native void setDTR( boolean state );
857
+	
858
 	/** 
859
-	*  @param state
860
-	*/
861
+	*	@param state
862
+	**/
863
 	public native void setRTS( boolean state );
864
 	private native void setDSR( boolean state );
865
+	
866
 	/** 
867
-	*  @return boolean true if CTS is set
868
-	*/
869
+	*	@return boolean true if CTS is set
870
+	**/
871
 	public native boolean isCTS();
872
 	/** 
873
-	*  @return boolean true if DSR is set
874
-	*/
875
+	*	@return boolean true if DSR is set
876
+	**/
877
 	public native boolean isDSR();
878
 	/** 
879
-	*  @return boolean true if CD is set
880
-	*/
881
+	*	@return boolean true if CD is set
882
+	**/
883
 	public native boolean isCD();
884
 	/** 
885
-	*  @return boolean true if RI is set
886
-	*/
887
+	*	@return boolean true if RI is set
888
+	**/
889
 	public native boolean isRI();
890
 	/** 
891
-	*  @return boolean true if RTS is set
892
-	*/
893
+	*	@return boolean true if RTS is set
894
+	**/
895
 	public native boolean isRTS();
896
 
897
 
898
 	/**
899
-	*  Write to the port
900
-	*  @param duration
901
-	*/
902
+	*	Write to the port
903
+	*	@param duration
904
+	**/
905
 	public native void sendBreak( int duration );
906
-	protected native void writeByte( int b, boolean i ) throws IOException;
907
-	protected native void writeArray( byte b[], int off, int len, boolean i )
908
-		throws IOException;
909
-	protected native boolean nativeDrain( boolean i ) throws IOException;
910
+	
911
+	protected native void writeByte(
912
+		int b,
913
+		boolean i
914
+	) throws IOException;
915
+	
916
+	protected native void writeArray(
917
+		byte b[],
918
+		int off,
919
+		int len,
920
+		boolean i
921
+	) throws IOException;
922
+	
923
+	protected native boolean nativeDrain(
924
+		boolean i
925
+	) throws IOException;
926
 
927
 	/** RXTXPort read methods */
928
 	protected native int nativeavailable() throws IOException;
929
 	protected native int readByte() throws IOException;
930
-	protected native int readArray( byte b[], int off, int len )
931
-		throws IOException;
932
-	protected native int readTerminatedArray( byte b[], int off, int len, byte t[] )
933
-		throws IOException;
934
+	
935
+	protected native int readArray(
936
+		byte b[],
937
+		int off,
938
+		int len
939
+	) throws IOException;
940
+		
941
+	protected native int readTerminatedArray(
942
+		byte b[],
943
+		int off,
944
+		int len,
945
+		byte t[]
946
+	) throws IOException;
947
 
948
 
949
 	/** Serial Port Event listener */
950
@@ -620,37 +784,43 @@
951
 	native void eventLoop();
952
 
953
 	/** 
954
-	*  @return boolean  true if monitor thread is interrupted
955
-	*/
956
+	*	@return boolean  true if monitor thread is interrupted
957
+	**/
958
 	boolean monThreadisInterrupted=true;
959
-	private native void interruptEventLoop( );
960
+	
961
+	private native void interruptEventLoop();
962
+	
963
 	public boolean checkMonitorThread()
964
 	{
965
-		if (debug)
966
-			z.reportln( "RXTXPort:checkMonitorThread()");
967
+		if (debug) System.out.println("RXTXPort:checkMonitorThread()");
968
 		if(monThread != null)
969
 		{
970
-			if ( debug )
971
-				z.reportln( 
972
-					"monThreadisInterrupted = " +
973
-					monThreadisInterrupted );
974
+			if (debug) System.out.println( 
975
+				" monThreadisInterrupted = " + monThreadisInterrupted
976
+			);
977
+			
978
 			return monThreadisInterrupted;
979
 		}
980
-		if ( debug )
981
-			z.reportln(  "monThread is null " );
982
+		
983
+		if ( debug ) System.out.println(
984
+			"RXTXPort:checkMonitorThread(null):Exit"
985
+		);
986
+			
987
 		return(true);
988
 	}
989
 
990
 	/** 
991
-	*  @param event
992
-	*  @param state
993
-	*  @return boolean true if the port is closing
994
-	*/
995
+	*	@param event
996
+	*	@param state
997
+	*	@return boolean true if the port is closing
998
+	**/
999
 	public boolean sendEvent( int event, boolean state )
1000
 	{
1001
 		if (debug_events)
1002
-			z.report( "RXTXPort:sendEvent(");
1003
-		/* Let the native side know its time to die */
1004
+			z.report("RXTXPort:sendEvent(");
1005
+		/**
1006
+		*	Let the native side know its time to die
1007
+		**/
1008
 
1009
 		if ( fd == 0 || SPEventListener == null || monThread == null)
1010
 		{
1011
@@ -661,63 +831,63 @@
1012
 		{
1013
 			case SerialPortEvent.DATA_AVAILABLE:
1014
 				if( debug_events )
1015
-					z.reportln( "DATA_AVAILABLE " +
1016
+					System.out.println(" DATA_AVAILABLE " +
1017
 						monThread.Data + ")" );
1018
 				break;
1019
 			case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
1020
 				if( debug_events )
1021
-					z.reportln( 
1022
-						"OUTPUT_BUFFER_EMPTY " +
1023
+					System.out.println( 
1024
+						" OUTPUT_BUFFER_EMPTY " +
1025
 						monThread.Output + ")" );
1026
 				break;
1027
 			case SerialPortEvent.CTS:
1028
 				if( debug_events )
1029
-					z.reportln( "CTS " +
1030
+					System.out.println(" CTS " +
1031
 						monThread.CTS + ")" );
1032
 				break;
1033
 			case SerialPortEvent.DSR:
1034
 				if( debug_events )
1035
-					z.reportln( "DSR " +
1036
+					System.out.println(" DSR " +
1037
 						monThread.Output + ")" );
1038
 				break;
1039
 			case SerialPortEvent.RI:
1040
 				if( debug_events )
1041
-					z.reportln( "RI " +
1042
+					System.out.println(" RI " +
1043
 						monThread.RI + ")" );
1044
 				break;
1045
 			case SerialPortEvent.CD:
1046
 				if( debug_events )
1047
-					z.reportln( "CD " +
1048
+					System.out.println(" CD " +
1049
 						monThread.CD + ")" );
1050
 				break;
1051
 			case SerialPortEvent.OE:
1052
 				if( debug_events )
1053
-					z.reportln( "OE " +
1054
+					System.out.println(" OE " +
1055
 						monThread.OE + ")" );
1056
 				break;
1057
 			case SerialPortEvent.PE:
1058
 				if( debug_events )
1059
-					z.reportln( "PE " +
1060
+					System.out.println(" PE " +
1061
 						monThread.PE + ")" );
1062
 				break;
1063
 			case SerialPortEvent.FE:
1064
 				if( debug_events )
1065
-					z.reportln( "FE " +
1066
+					System.out.println(" FE " +
1067
 						monThread.FE + ")" );
1068
 				break;
1069
 			case SerialPortEvent.BI:
1070
 				if( debug_events )
1071
-					z.reportln( "BI " +
1072
+					System.out.println(" BI " +
1073
 						monThread.BI + ")" );
1074
 				break;
1075
 			default:
1076
 				if( debug_events )
1077
-					z.reportln( "XXXXXXXXXXXXXX " +
1078
+					System.out.println(" XXXXXXXXXXXXXX (" +
1079
 						event + ")" );
1080
 				break;
1081
 		}
1082
 		if( debug_events && debug_verbose )
1083
-			z.reportln(  "	checking flags " );
1084
+			System.out.println(  "	checking flags " );
1085
 
1086
 		switch( event )
1087
 		{
1088
@@ -752,19 +922,19 @@
1089
 				if( monThread.BI ) break;
1090
 				return(false);
1091
 			default:
1092
-				System.err.println( "unknown event: " + event);
1093
+				System.err.println(" unknown event: " + event);
1094
 				return(false);
1095
 		}
1096
 		if( debug_events && debug_verbose )
1097
-			z.reportln(  "	getting event" );
1098
+			System.out.println(  " getting event" );
1099
 		SerialPortEvent e = new SerialPortEvent(this, event, !state,
1100
 			state );
1101
 		if( debug_events && debug_verbose )
1102
-			z.reportln(  "	sending event" );
1103
+			System.out.println(  " sending event" );
1104
 		if(monThreadisInterrupted) 
1105
 		{
1106
 			if( debug_events )
1107
-				z.reportln(  "	sendEvent return" );
1108
+				System.out.println(  " sendEvent return" );
1109
 			return(true);
1110
 		}
1111
 		if( SPEventListener != null )
1112
@@ -773,7 +943,7 @@
1113
 		}
1114
 
1115
 		if( debug_events && debug_verbose )
1116
-			z.reportln(  "	sendEvent return" );
1117
+			System.out.println(  " sendEvent return" );
1118
 
1119
 		if (fd == 0 ||  SPEventListener == null || monThread == null) 
1120
 		{
1121
@@ -786,22 +956,22 @@
1122
 	}
1123
 
1124
 	/**
1125
-	*  Add an event listener
1126
-	*  @param lsnr SerialPortEventListener
1127
-	*  @throws TooManyListenersException
1128
-	*/
1129
+	*	Add an event listener
1130
+	*	@param lsnr SerialPortEventListener
1131
+	*	@throws TooManyListenersException
1132
+	**/
1133
 
1134
 	boolean MonitorThreadLock = true;
1135
 
1136
 	public void addEventListener(
1137
 		SerialPortEventListener lsnr ) throws TooManyListenersException
1138
 	{
1139
-		/*  Don't let and notification requests happen until the
1140
+		/*	Don't let and notification requests happen until the
1141
 		    Eventloop is ready
1142
-		*/
1143
+		**/
1144
 
1145
 		if (debug)
1146
-			z.reportln( "RXTXPort:addEventListener()");
1147
+			System.out.println("RXTXPort:addEventListener()");
1148
 		if( SPEventListener != null )
1149
 		{
1150
 			throw new TooManyListenersException();
1151
@@ -816,54 +986,66 @@
1152
 			MonitorThreadAlive=true;
1153
 		}
1154
 		if (debug)
1155
-			z.reportln( "RXTXPort:Interrupt=false");
1156
+			System.out.println("RXTXPort:addEventListener:Exit");
1157
 	}
1158
+	
1159
 	/**
1160
-	*  Remove the serial port event listener
1161
-	*/
1162
+	*	Remove the serial port event listener
1163
+	**/
1164
 	public void removeEventListener()
1165
 	{
1166
 		if (debug)
1167
-			z.reportln( "RXTXPort:removeEventListener() called");
1168
+			System.out.println("RXTXPort:removeEventListener()");
1169
+		
1170
 		waitForTheNativeCodeSilly();
1171
 		//if( monThread != null && monThread.isAlive() )
1172
+		
1173
 		if( monThreadisInterrupted == true )
1174
 		{
1175
-			z.reportln( "	RXTXPort:removeEventListener() already interrupted");
1176
+			System.out.println(" already interrupted");
1177
 			monThread = null;
1178
 			SPEventListener = null;
1179
 			return;
1180
 		}
1181
 		else if( monThread != null && monThread.isAlive() )
1182
 		{
1183
-			if (debug)
1184
-				z.reportln( "	RXTXPort:Interrupt=true");
1185
+			if (debug) System.out.println(" Interrupt=true");
1186
 			monThreadisInterrupted=true;
1187
-			/*
1188
-			   Notify all threads in this PID that something is up
1189
-			   They will call back to see if its their thread
1190
-			   using isInterrupted().
1191
-			*/
1192
-			if (debug)
1193
-				z.reportln( "	RXTXPort:calling interruptEventLoop");
1194
-			interruptEventLoop( );
1195
 			
1196
-			if (debug)
1197
-				z.reportln( "	RXTXPort:calling monThread.join()");
1198
+			/**
1199
+			*	Notify all threads in this PID that something is up
1200
+			*	They will call back to see if its their thread
1201
+			*	using isInterrupted().
1202
+			**/
1203
+			
1204
+			if (debug) System.out.println(" RXTXPort:removeEventListener - interruptEventLoop");
1205
+			/** 
1206
+			* JCE - On FreeBSD 10.1-p9 this causes a Java Core Dump if port is closed before init sleep has completed
1207
+			**/
1208
+			interruptEventLoop();
1209
+			
1210
+			if (debug) System.out.println(" RXTXPort:removeEventListener - monThread.join()");
1211
+			
1212
 			try {
1213
 
1214
 				// wait a reasonable moment for the death of the monitor thread
1215
 				monThread.join(3000);
1216
-			} catch (InterruptedException ex) {
1217
+				if (debug) System.out.println(" RXTXPort:removeEventListener - Post monThread.join()");	
1218
+			} 
1219
+			catch (InterruptedException ex) 
1220
+			{
1221
 				// somebody called interrupt() on us (ie wants us to abort)
1222
 				// we dont propagate InterruptedExceptions so lets re-set the flag 
1223
+				if (debug) System.out.println(" RXTXPort:removeEventListener - InterruptedException");	
1224
 				Thread.currentThread().interrupt();
1225
 				return;
1226
  			}
1227
+ 			
1228
+			if (debug) System.out.println(" RXTXPort:removeEventListener - Waited!");	
1229
 				
1230
 			if ( debug && monThread.isAlive() )
1231
 			{
1232
-				z.reportln( "	MonThread is still alive!");
1233
+				System.out.println(" MonThread is still alive!");
1234
 
1235
 			}
1236
 			
1237
@@ -873,7 +1055,7 @@
1238
 		MonitorThreadLock = false;
1239
 		MonitorThreadAlive=false;
1240
 		monThreadisInterrupted=true;
1241
-		z.reportln( "RXTXPort:removeEventListener() returning");
1242
+		System.out.println("RXTXPort:removeEventListener:Exit");
1243
 	}
1244
 	/**
1245
 	 *	Give the native code a chance to start listening to the hardware
1246
@@ -894,15 +1076,15 @@
1247
 		}
1248
 	}
1249
 	/**
1250
-	*  @param enable
1251
-	*/
1252
+	*	@param enable
1253
+	**/
1254
 	private native void nativeSetEventFlag( int fd, int event,
1255
 						boolean flag );
1256
 	public void notifyOnDataAvailable( boolean enable )
1257
 	{
1258
 		if (debug)
1259
-			z.reportln( "RXTXPort:notifyOnDataAvailable( " +
1260
-				enable+" )");
1261
+			System.out.println("RXTXPort:notifyOnDataAvailable(" +
1262
+				enable+")");
1263
 		
1264
 		waitForTheNativeCodeSilly();
1265
 
1266
@@ -911,155 +1093,172 @@
1267
 					enable );
1268
 		monThread.Data = enable;
1269
 		MonitorThreadLock = false;
1270
+		if (debug)
1271
+			System.out.println("RXTXPort:notifyOnDataAvailable:Exit");
1272
+		
1273
 	}
1274
 
1275
 	/**
1276
-	*  @param enable
1277
-	*/
1278
+	*	@param enable
1279
+	**/
1280
 	public void notifyOnOutputEmpty( boolean enable )
1281
 	{
1282
 		if (debug)
1283
-			z.reportln( "RXTXPort:notifyOnOutputEmpty( " +
1284
-				enable+" )");
1285
+			System.out.println("RXTXPort:notifyOnOutputEmpty(" +
1286
+				enable+")");
1287
 		waitForTheNativeCodeSilly();
1288
 		MonitorThreadLock = true;
1289
 		nativeSetEventFlag( fd, SerialPortEvent.OUTPUT_BUFFER_EMPTY,
1290
 					enable );
1291
 		monThread.Output = enable;
1292
 		MonitorThreadLock = false;
1293
+		if (debug)
1294
+			System.out.println("RXTXPort:notifyOnOutputEmpty:Exit");
1295
+
1296
 	}
1297
 
1298
 	/**
1299
-	*  @param enable
1300
-	*/
1301
+	*	@param enable
1302
+	**/
1303
 	public void notifyOnCTS( boolean enable )
1304
 	{
1305
-		if (debug)
1306
-			z.reportln( "RXTXPort:notifyOnCTS( " +
1307
-				enable+" )");
1308
+		if (debug) System.out.println("RXTXPort:notifyOnCTS(" + enable+")");
1309
 		waitForTheNativeCodeSilly();
1310
 		MonitorThreadLock = true;
1311
 		nativeSetEventFlag( fd, SerialPortEvent.CTS, enable );
1312
 		monThread.CTS = enable;
1313
 		MonitorThreadLock = false;
1314
+		if (debug) System.out.println("RXTXPort:notifyOnCTS:Exit");
1315
 	}
1316
 	/**
1317
-	*  @param enable
1318
-	*/
1319
+	*	@param enable
1320
+	**/
1321
 	public void notifyOnDSR( boolean enable )
1322
 	{
1323
-		if (debug)
1324
-			z.reportln( "RXTXPort:notifyOnDSR( " +
1325
-				enable+" )");
1326
+		if (debug) System.out.println("RXTXPort:notifyOnDSR(" + enable+")");
1327
 		waitForTheNativeCodeSilly();
1328
 		MonitorThreadLock = true;
1329
 		nativeSetEventFlag( fd, SerialPortEvent.DSR, enable );
1330
 		monThread.DSR = enable;
1331
 		MonitorThreadLock = false;
1332
+		if (debug) System.out.println("RXTXPort:notifyOnDSR:Exit");
1333
 	}
1334
 	/**
1335
-	*  @param enable
1336
-	*/
1337
+	*	@param enable
1338
+	**/
1339
 	public void notifyOnRingIndicator( boolean enable )
1340
 	{
1341
-		if (debug)
1342
-			z.reportln( "RXTXPort:notifyOnRingIndicator( " +
1343
-				enable+" )");
1344
+		if (debug) System.out.println("RXTXPort:notifyOnRingIndicator(" +
1345
+			enable+")");
1346
+				
1347
 		waitForTheNativeCodeSilly();
1348
 		MonitorThreadLock = true;
1349
 		nativeSetEventFlag( fd, SerialPortEvent.RI, enable );
1350
 		monThread.RI = enable;
1351
 		MonitorThreadLock = false;
1352
+		if (debug) System.out.println("RXTXPort:notifyOnRingIndicator:Exit");
1353
 	}
1354
 	/**
1355
-	*  @param enable
1356
-	*/
1357
+	*	@param enable
1358
+	**/
1359
 	public void notifyOnCarrierDetect( boolean enable )
1360
 	{
1361
 		if (debug)
1362
-			z.reportln( "RXTXPort:notifyOnCarrierDetect( " +
1363
-				enable+" )");
1364
+			System.out.println("RXTXPort:notifyOnCarrierDetect(" +
1365
+				enable+")");
1366
 		waitForTheNativeCodeSilly();
1367
 		MonitorThreadLock = true;
1368
 		nativeSetEventFlag( fd, SerialPortEvent.CD, enable );
1369
 		monThread.CD = enable;
1370
 		MonitorThreadLock = false;
1371
+		if (debug)
1372
+			System.out.println("RXTXPort:notifyOnCarrierDetect:Exit");
1373
 	}
1374
 	/**
1375
-	*  @param enable
1376
-	*/
1377
+	*	@param enable
1378
+	**/
1379
 	public void notifyOnOverrunError( boolean enable )
1380
 	{
1381
 		if (debug)
1382
-			z.reportln( "RXTXPort:notifyOnOverrunError( " +
1383
-				enable+" )");
1384
+			System.out.println("RXTXPort:notifyOnOverrunError(" +
1385
+				enable+")");
1386
 		waitForTheNativeCodeSilly();
1387
 		MonitorThreadLock = true;
1388
 		nativeSetEventFlag( fd, SerialPortEvent.OE, enable );
1389
 		monThread.OE = enable;
1390
 		MonitorThreadLock = false;
1391
+		if (debug)
1392
+			System.out.println("RXTXPort:notifyOnOverrunError:Exit");
1393
 	}
1394
+	
1395
 	/**
1396
-	*  @param enable
1397
-	*/
1398
+	*	@param enable
1399
+	**/
1400
 	public void notifyOnParityError( boolean enable )
1401
 	{
1402
 		if (debug)
1403
-			z.reportln( "RXTXPort:notifyOnParityError( " +
1404
-				enable+" )");
1405
+			System.out.println("RXTXPort:notifyOnParityError(" +
1406
+				enable+")");
1407
 		waitForTheNativeCodeSilly();
1408
 		MonitorThreadLock = true;
1409
 		nativeSetEventFlag( fd, SerialPortEvent.PE, enable );
1410
 		monThread.PE = enable;
1411
 		MonitorThreadLock = false;
1412
+		if (debug)
1413
+			System.out.println("RXTXPort:notifyOnParityError:Exit");
1414
 	}
1415
 	/**
1416
-	*  @param enable
1417
-	*/
1418
+	*	@param enable
1419
+	**/
1420
 	public void notifyOnFramingError( boolean enable )
1421
 	{
1422
-		if (debug)
1423
-			z.reportln( "RXTXPort:notifyOnFramingError( " +
1424
-				enable+" )");
1425
+		if (debug) System.out.println("RXTXPort:notifyOnFramingError(" +
1426
+			enable+")");
1427
 		waitForTheNativeCodeSilly();
1428
 		MonitorThreadLock = true;
1429
 		nativeSetEventFlag( fd, SerialPortEvent.FE, enable );
1430
 		monThread.FE = enable;
1431
 		MonitorThreadLock = false;
1432
+		if (debug) System.out.println("RXTXPort:notifyOnFramingError:Exit");
1433
 	}
1434
 	/**
1435
-	*  @param enable
1436
-	*/
1437
+	*	@param enable
1438
+	**/
1439
 	public void notifyOnBreakInterrupt( boolean enable )
1440
 	{
1441
 		if (debug)
1442
-			z.reportln( "RXTXPort:notifyOnBreakInterrupt( " +
1443
-				enable+" )");
1444
+			System.out.println("RXTXPort:notifyOnBreakInterrupt(" +
1445
+				enable+")");
1446
 		waitForTheNativeCodeSilly();
1447
 		MonitorThreadLock = true;
1448
 		nativeSetEventFlag( fd, SerialPortEvent.BI, enable );
1449
 		monThread.BI = enable;
1450
 		MonitorThreadLock = false;
1451
+		System.out.println("RXTXPort:notifyOnBreakInterrupt:Exit");
1452
 	}
1453
 
1454
 	/** Close the port */
1455
 	private native void nativeClose( String name );
1456
 	/**
1457
-	*/
1458
+	**/
1459
 	boolean closeLock = false;
1460
 	public void close()
1461
 	{
1462
-		synchronized (this) {
1463
-			if (debug)
1464
-				z.reportln( "RXTXPort:close( " + this.name + " )"); 
1465
-
1466
+		if (debug) System.out.println("RXTXPort:close(" + this.name + ")");
1467
+		
1468
+		synchronized (this) 
1469
+		{
1470
+		
1471
 			while( IOLocked > 0 )
1472
 			{
1473
-				if( debug )
1474
-					z.reportln("IO is locked " + IOLocked);
1475
-				try {
1476
+				if (debug) System.out.println("IO is locked " + IOLocked);
1477
+				
1478
+				try 
1479
+				{
1480
 					this.wait(500);
1481
-				} catch( InterruptedException ie ) {
1482
+				}
1483
+				catch( InterruptedException ie )
1484
+				{
1485
 					// somebody called interrupt() on us
1486
 					// we obbey and return without without closing the socket
1487
 					Thread.currentThread().interrupt();
1488
@@ -1075,55 +1274,62 @@
1489
 
1490
 		if ( fd <= 0 )
1491
 		{
1492
-			z.reportln(  "RXTXPort:close detected bad File Descriptor" );
1493
+			System.out.println(  "RXTXPort:close detected bad File Descriptor" );
1494
 			return;
1495
 		}
1496
+		
1497
 		setDTR(false);
1498
 		setDSR(false);
1499
+		
1500
 		if (debug)
1501
-			z.reportln( "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
1502
+			System.out.println("RXTXPort:close(" + this.name + ") setting monThreadisInterrupted"); 
1503
+			
1504
 		if ( ! monThreadisInterrupted )
1505
 		{
1506
 			removeEventListener();
1507
 		}
1508
+		
1509
 		if (debug)
1510
-			z.reportln( "RXTXPort:close( " + this.name + " ) calling nativeClose"); 
1511
+			System.out.println("RXTXPort:close(" + this.name + ") calling nativeClose"); 
1512
 		nativeClose( this.name );
1513
+		
1514
 		if (debug)
1515
-			z.reportln( "RXTXPort:close( " + this.name + " ) calling super.close"); 
1516
+			System.out.println("RXTXPort:close(" + this.name + ") calling super.close"); 
1517
 		super.close();
1518
+		
1519
 		fd = 0;
1520
 		closeLock = false;
1521
 		if (debug)
1522
-			z.reportln( "RXTXPort:close( " + this.name + " ) leaving"); 
1523
+			System.out.println("RXTXPort:close(" + this.name + "):Exit"); 
1524
 	}
1525
 
1526
 
1527
 	/** Finalize the port */
1528
 	protected void finalize()
1529
 	{
1530
-		if (debug)
1531
-			z.reportln( "RXTXPort:finalize()");
1532
+		if (debug) System.out.println("RXTXPort:finalize()");
1533
 		if( fd > 0 )
1534
 		{
1535
 			if (debug)
1536
-				z.reportln( "RXTXPort:calling close()");
1537
+				System.out.println("RXTXPort:calling close()");
1538
 			close();
1539
 		}
1540
 		z.finalize();
1541
+		
1542
+		if (debug) System.out.println("RXTXPort:finalize()");
1543
 	}
1544
 
1545
 	/** Inner class for SerialOutputStream */
1546
 	class SerialOutputStream extends OutputStream
1547
 	{
1548
 	/**
1549
-	*  @param b
1550
-	*  @throws IOException
1551
-	*/
1552
+	*	@param b
1553
+	*	@throws IOException
1554
+	**/
1555
 		public void write( int b ) throws IOException
1556
 		{
1557
 			if (debug_write)
1558
-				z.reportln( "RXTXPort:SerialOutputStream:write(int)");
1559
+				System.out.println("RXTXPort:SerialOutputStream:write("+ b +")");
1560
 			if( speed == 0 ) return;
1561
 			if ( monThreadisInterrupted == true )
1562
 			{
1563
@@ -1140,7 +1346,7 @@
1564
 				}
1565
 				writeByte( b, monThreadisInterrupted );
1566
 				if (debug_write)
1567
-					z.reportln( "Leaving RXTXPort:SerialOutputStream:write( int )");
1568
+					System.out.println("RXTXPort:SerialOutputStream:write(" + b + "):Exit");
1569
 			} finally {
1570
 				synchronized (IOLockedMutex) {
1571
 					IOLocked--;
1572
@@ -1148,15 +1354,16 @@
1573
 			}
1574
 		}
1575
 	/**
1576
-	*  @param b[]
1577
-	*  @throws IOException
1578
-	*/
1579
+	*	@param b[]
1580
+	*	@throws IOException
1581
+	**/
1582
 		public void write( byte b[] ) throws IOException
1583
 		{
1584
 			if (debug_write)
1585
 			{
1586
-				z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
1587
+				System.out.println("RXTXPort:SerialOutputStream:write(" + b.length + ")" /* + new String(b)*/ );
1588
 			}
1589
+			
1590
 			if( speed == 0 ) return;
1591
 			if ( monThreadisInterrupted == true )
1592
 			{
1593
@@ -1170,7 +1377,7 @@
1594
 				waitForTheNativeCodeSilly();
1595
 				writeArray( b, 0, b.length, monThreadisInterrupted );
1596
 				if (debug_write)
1597
-					z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" +b.length  +")");
1598
+					System.out.println("RXTXPort:SerialOutputStream:write(" +b.length  +"):Exit");
1599
 			} finally {
1600
 				synchronized(IOLockedMutex) {
1601
 					IOLocked--;
1602
@@ -1179,14 +1386,19 @@
1603
 			
1604
 		}
1605
 	/**
1606
-	*  @param b[]
1607
-	*  @param off
1608
-	*  @param len
1609
-	*  @throws IOException
1610
-	*/
1611
+	*	@param b[]
1612
+	*	@param off
1613
+	*	@param len
1614
+	*	@throws IOException
1615
+	**/
1616
 		public void write( byte b[], int off, int len )
1617
 			throws IOException
1618
 		{
1619
+			if (debug_write)
1620
+			{
1621
+				System.out.println("RXTXPort:SerialOutputStream:write(o:" + off + " l:" + len + ") " /*+  new String(send) */ );
1622
+			}
1623
+			
1624
 			if( speed == 0 ) return;
1625
 			if( off + len  > b.length )
1626
 			{
1627
@@ -1197,10 +1409,7 @@
1628
 	 
1629
 			byte send[] = new byte[len];
1630
 			System.arraycopy( b, off, send, 0, len );
1631
-			if (debug_write)
1632
-			{
1633
-				z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+  new String(send) */ );
1634
-			}
1635
+			
1636
 			if ( fd == 0 ) throw new IOException();
1637
 			if ( monThreadisInterrupted == true )
1638
 			{
1639
@@ -1214,7 +1423,7 @@
1640
 				waitForTheNativeCodeSilly();
1641
 				writeArray( send, 0, len, monThreadisInterrupted );
1642
 				if( debug_write )
1643
-					z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") "  /*+ new String(send)*/ );
1644
+					System.out.println("Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") "  /*+ new String(send)*/ );
1645
 			} finally {
1646
 				synchronized (IOLockedMutex) {
1647
 					IOLocked--;
1648
@@ -1222,17 +1431,17 @@
1649
 			}
1650
 		}
1651
 	/**
1652
-	*/
1653
+	**/
1654
 		public void flush() throws IOException
1655
 		{
1656
 			if (debug)
1657
-				z.reportln( "RXTXPort:SerialOutputStream:flush() enter");
1658
+				System.out.println("RXTXPort:SerialOutputStream:flush()");
1659
 			if( speed == 0 ) return;
1660
 			if ( fd == 0 ) throw new IOException();
1661
 			if ( monThreadisInterrupted == true )
1662
 			{
1663
 			if (debug)
1664
-				z.reportln( "RXTXPort:SerialOutputStream:flush() Leaving Interrupted");
1665
+				System.out.println("RXTXPort:SerialOutputStream:flush():Exit - Interrupted");
1666
 				return;
1667
 			}
1668
 			synchronized(IOLockedMutex) {
1669
@@ -1244,17 +1453,19 @@
1670
 				/* 
1671
 				   this is probably good on all OS's but for now
1672
 				   just sendEvent from java on Sol
1673
-				*/
1674
+				**/
1675
 				if ( nativeDrain( monThreadisInterrupted ) )
1676
 					sendEvent( SerialPortEvent.OUTPUT_BUFFER_EMPTY, true );
1677
 				if (debug)
1678
-					z.reportln( "RXTXPort:SerialOutputStream:flush() leave");
1679
+					System.out.println("RXTXPort:SerialOutputStream:flush():EndTry");
1680
 			}
1681
 			finally
1682
 			{
1683
 				synchronized (IOLockedMutex) {
1684
 					IOLocked--;
1685
 				}
1686
+				if (debug)
1687
+					System.out.println("RXTXPort:SerialOutputStream:flush():Exit");
1688
 			}
1689
 		}
1690
 	}
1691
@@ -1263,42 +1474,42 @@
1692
 	class SerialInputStream extends InputStream
1693
 	{
1694
 	/**
1695
-	*  @return int the int read
1696
-	*  @throws IOException
1697
-	*  @see java.io.InputStream
1698
+	*	@return int the int read
1699
+	*	@throws IOException
1700
+	*	@see java.io.InputStream
1701
 *
1702
 *timeout threshold       Behavior
1703
 *------------------------------------------------------------------------
1704
 *0       0       blocks until 1 byte is available timeout > 0,
1705
-*                threshold = 0, blocks until timeout occurs, returns -1
1706
-*                on timeout
1707
+*	              threshold = 0, blocks until timeout occurs, returns -1
1708
+*	              on timeout
1709
 *>0      >0      blocks until timeout, returns - 1 on timeout, magnitude
1710
-*                of threshold doesn't play a role.
1711
+*	              of threshold doesn't play a role.
1712
 *0       >0      Blocks until 1 byte, magnitude of  threshold doesn't
1713
-*                play a role
1714
-	*/
1715
+*	              play a role
1716
+	**/
1717
 		public synchronized int read() throws IOException
1718
 		{
1719
 			if (debug_read)
1720
-				z.reportln( "RXTXPort:SerialInputStream:read() called");
1721
+				System.out.println("RXTXPort:SerialInputStream:read()");
1722
 			if ( fd == 0 ) throw new IOException();
1723
 			if ( monThreadisInterrupted )
1724
 			{
1725
-				z.reportln( "+++++++++ read() monThreadisInterrupted" );
1726
+				System.out.println("+++++++++ read() monThreadisInterrupted" );
1727
 			}
1728
 			synchronized (IOLockedMutex) {
1729
 				IOLocked++;
1730
 			}
1731
 			try {
1732
 				if (debug_read_results)
1733
-					z.reportln(  "RXTXPort:SerialInputStream:read() L" );
1734
+					System.out.println(  "RXTXPort:SerialInputStream:read() L" );
1735
 				waitForTheNativeCodeSilly();
1736
 				if (debug_read_results)
1737
-					z.reportln(  "RXTXPort:SerialInputStream:read() N" );
1738
+					System.out.println(  "RXTXPort:SerialInputStream:read() N" );
1739
 				int result = readByte();
1740
 				if (debug_read_results)
1741
-					//z.reportln(  "RXTXPort:SerialInputStream:read() returns byte = " + result );
1742
-					z.reportln(  "RXTXPort:SerialInputStream:read() returns" );
1743
+					//System.out.println(  "RXTXPort:SerialInputStream:read() returns byte = " + result );
1744
+					System.out.println(  "RXTXPort:SerialInputStream:read() returns" );
1745
 				return( result );
1746
 			}				
1747
 			finally
1748
@@ -1309,9 +1520,9 @@
1749
 			}
1750
 		}
1751
 	/**
1752
-	*  @param b[]
1753
-	*  @return int  number of bytes read
1754
-	*  @throws IOException
1755
+	*	@param b[]
1756
+	*	@return int  number of bytes read
1757
+	*	@throws IOException
1758
 *
1759
 *timeout threshold       Behavior
1760
 *------------------------------------------------------------------------
1761
@@ -1320,12 +1531,12 @@
1762
 *>0      >0      blocks until timeout or reads threshold bytes,
1763
                  returns 0 on timeout
1764
 *0       >0      blocks until reads threshold bytes
1765
-	*/
1766
+	**/
1767
 		public synchronized int read( byte b[] ) throws IOException
1768
 		{
1769
 			int result;
1770
 			if (debug_read)
1771
-				z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + ") called");
1772
+				System.out.println("RXTXPort:SerialInputStream:read(" + b.length + ") called");
1773
 			if ( monThreadisInterrupted == true )
1774
 			{
1775
 				return(0);
1776
@@ -1338,7 +1549,7 @@
1777
 				waitForTheNativeCodeSilly();
1778
 				result = read( b, 0, b.length);
1779
 				if (debug_read_results)
1780
-					z.reportln(  "RXTXPort:SerialInputStream:read() returned " + result + " bytes" );
1781
+					System.out.println(  "RXTXPort:SerialInputStream:read() returned " + result + " bytes" );
1782
 				return( result );
1783
 			}
1784
 			finally
1785
@@ -1353,11 +1564,11 @@
1786
 Documentation is at http://java.sun.com/products/jdk/1.2/docs/api/java/io/InputStream.html#read(byte[], int, int)
1787
 */
1788
 	/**
1789
-	*  @param b[]
1790
-	*  @param off
1791
-	*  @param len
1792
-	*  @return int  number of bytes read
1793
-	*  @throws IOException
1794
+	*	@param b[]
1795
+	*	@param off
1796
+	*	@param len
1797
+	*	@return int  number of bytes read
1798
+	*	@throws IOException
1799
 *
1800
 *timeout threshold       Behavior
1801
 *------------------------------------------------------------------------
1802
@@ -1367,12 +1578,12 @@
1803
                  returns 0 on timeout
1804
 *0       >0      blocks until either threshold # of bytes or len bytes,
1805
                  whichever was lower.
1806
-	*/
1807
+	**/
1808
 		public synchronized int read( byte b[], int off, int len )
1809
 			throws IOException
1810
 		{
1811
 			if (debug_read)
1812
-				z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1813
+				System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1814
 			int result;
1815
 			/*
1816
 			 * Some sanity checks
1817
@@ -1380,24 +1591,24 @@
1818
 			if ( fd == 0 )
1819
 			{
1820
 				if (debug_read)
1821
-					z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
1822
-				z.reportln("+++++++ IOException()\n");
1823
+					System.out.println("RXTXPort:SerialInputStream:read() fd == 0");
1824
+				System.out.println("+++++++ IOException()\n");
1825
 				throw new IOException();
1826
 			}
1827
 
1828
 			if( b==null )
1829
 			{
1830
-				z.reportln("+++++++ NullPointerException()\n");
1831
+				System.out.println("+++++++ NullPointerException()\n");
1832
 				if (debug_read)
1833
-					z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
1834
+					System.out.println("RXTXPort:SerialInputStream:read() b == 0");
1835
 				throw new NullPointerException();
1836
 			}
1837
 
1838
 			if( (off < 0) || (len < 0) || (off+len > b.length))
1839
 			{
1840
-				z.reportln("+++++++ IndexOutOfBoundsException()\n");
1841
+				System.out.println("+++++++ IndexOutOfBoundsException()\n");
1842
 				if (debug_read)
1843
-					z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1844
+					System.out.println("RXTXPort:SerialInputStream:read() off < 0 ..");
1845
 				throw new IndexOutOfBoundsException();
1846
 			}
1847
 
1848
@@ -1407,7 +1618,7 @@
1849
 			if( len==0 )
1850
 			{
1851
 				if (debug_read)
1852
-					z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1853
+					System.out.println("RXTXPort:SerialInputStream:read() off < 0 ..");
1854
 				return 0;
1855
 			}
1856
 			/*
1857
@@ -1442,7 +1653,7 @@
1858
 			if ( monThreadisInterrupted == true )
1859
 			{
1860
 				if (debug_read)
1861
-					z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
1862
+					System.out.println("RXTXPort:SerialInputStream:read() Interrupted");
1863
 				return(0);
1864
 			}
1865
 			synchronized (IOLockedMutex) {
1866
@@ -1453,7 +1664,7 @@
1867
 				waitForTheNativeCodeSilly();
1868
 				result = readArray( b, off, Minimum);
1869
 				if (debug_read_results)
1870
-					z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
1871
+					System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
1872
 				return( result );
1873
 			}
1874
 			finally
1875
@@ -1465,12 +1676,12 @@
1876
 		}
1877
 
1878
 	/**
1879
-	*  @param b[]
1880
-	*  @param off
1881
-	*  @param len
1882
-	*  @param t[]
1883
-	*  @return int  number of bytes read
1884
-	*  @throws IOException
1885
+	*	@param b[]
1886
+	*	@param off
1887
+	*	@param len
1888
+	*	@param t[]
1889
+	*	@return int  number of bytes read
1890
+	*	@throws IOException
1891
 
1892
 	   We are trying to catch the terminator in the native code
1893
 	   Right now it is assumed that t[] is an array of 2 bytes.
1894
@@ -1479,13 +1690,13 @@
1895
 	   array will contain the terminator.  Otherwise read behavior should
1896
 	   be the same as read( b[], off, len ).  Timeouts have not been well
1897
 	   tested.
1898
-	*/
1899
+	**/
1900
 
1901
 		public synchronized int read( byte b[], int off, int len, byte t[] )
1902
 			throws IOException
1903
 		{
1904
 			if (debug_read)
1905
-				z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1906
+				System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1907
 			int result;
1908
 			/*
1909
 			 * Some sanity checks
1910
@@ -1493,24 +1704,24 @@
1911
 			if ( fd == 0 )
1912
 			{
1913
 				if (debug_read)
1914
-					z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
1915
-				z.reportln("+++++++ IOException()\n");
1916
+					System.out.println("RXTXPort:SerialInputStream:read() fd == 0");
1917
+				System.out.println("+++++++ IOException()\n");
1918
 				throw new IOException();
1919
 			}
1920
 
1921
 			if( b==null )
1922
 			{
1923
-				z.reportln("+++++++ NullPointerException()\n");
1924
+				System.out.println("+++++++ NullPointerException()\n");
1925
 				if (debug_read)
1926
-					z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
1927
+					System.out.println("RXTXPort:SerialInputStream:read() b == 0");
1928
 				throw new NullPointerException();
1929
 			}
1930
 
1931
 			if( (off < 0) || (len < 0) || (off+len > b.length))
1932
 			{
1933
-				z.reportln("+++++++ IndexOutOfBoundsException()\n");
1934
+				System.out.println("+++++++ IndexOutOfBoundsException()\n");
1935
 				if (debug_read)
1936
-					z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1937
+					System.out.println("RXTXPort:SerialInputStream:read() off < 0 ..");
1938
 				throw new IndexOutOfBoundsException();
1939
 			}
1940
 
1941
@@ -1520,7 +1731,7 @@
1942
 			if( len==0 )
1943
 			{
1944
 				if (debug_read)
1945
-					z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1946
+					System.out.println("RXTXPort:SerialInputStream:read() off < 0 ..");
1947
 				return 0;
1948
 			}
1949
 			/*
1950
@@ -1555,7 +1766,7 @@
1951
 			if ( monThreadisInterrupted == true )
1952
 			{
1953
 				if (debug_read)
1954
-					z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
1955
+					System.out.println("RXTXPort:SerialInputStream:read() Interrupted");
1956
 				return(0);
1957
 			}
1958
 			synchronized (IOLockedMutex) {
1959
@@ -1566,7 +1777,7 @@
1960
 				waitForTheNativeCodeSilly();
1961
 				result = readTerminatedArray( b, off, Minimum, t );
1962
 				if (debug_read_results)
1963
-					z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
1964
+					System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
1965
 				return( result );
1966
 			}
1967
 			finally
1968
@@ -1577,9 +1788,9 @@
1969
 			}
1970
 		}
1971
 	/**
1972
-	*  @return int bytes available
1973
-	*  @throws IOException
1974
-	*/
1975
+	*	@return int bytes available
1976
+	*	@throws IOException
1977
+	**/
1978
 		public synchronized int available() throws IOException
1979
 		{
1980
 			if ( monThreadisInterrupted == true )
1981
@@ -1587,7 +1798,7 @@
1982
 				return(0);
1983
 			}
1984
 			if ( debug_verbose )
1985
-				z.reportln( "RXTXPort:available() called" );
1986
+				System.out.println("RXTXPort:available() called" );
1987
 			synchronized (IOLockedMutex) {
1988
 				IOLocked++;
1989
 			}
1990
@@ -1595,7 +1806,7 @@
1991
 			{
1992
 				int r = nativeavailable();
1993
 				if ( debug_verbose )
1994
-					z.reportln( "RXTXPort:available() returning " +
1995
+					System.out.println("RXTXPort:available() returning " +
1996
 						r );
1997
 				return r;
1998
 			}
1999
@@ -1608,7 +1819,7 @@
2000
 		}
2001
 	}
2002
 	/**
2003
-	*/
2004
+	**/
2005
 	class MonitorThread extends Thread
2006
 	{
2007
 	/** Note: these have to be separate boolean flags because the
2008
@@ -1628,30 +1839,30 @@
2009
 		MonitorThread() 
2010
 		{
2011
 			if (debug)
2012
-				z.reportln( "RXTXPort:MontitorThread:MonitorThread()"); 
2013
+				System.out.println("RXTXPort:MontitorThread:MonitorThread()"); 
2014
 		}
2015
 	/**
2016
-	*  run the thread and call the event loop.
2017
-	*/
2018
+	*	run the thread and call the event loop.
2019
+	**/
2020
 		public void run()
2021
 		{
2022
 			if (debug)
2023
-				z.reportln( "RXTXPort:MontitorThread:run()"); 
2024
+				System.out.println("RXTXPort:MontitorThread:run()"); 
2025
 			monThreadisInterrupted=false;
2026
 			eventLoop();
2027
 			if (debug)
2028
-				z.reportln( "eventLoop() returned"); 
2029
+				System.out.println("eventLoop() returned"); 
2030
 		}
2031
 		protected void finalize() throws Throwable 
2032
 		{ 
2033
 			if (debug)
2034
-				z.reportln( "RXTXPort:MonitorThread exiting"); 
2035
+				System.out.println("RXTXPort:MonitorThread exiting"); 
2036
 		}
2037
 	}
2038
 	/**
2039
-	*  A dummy method added so RXTX compiles on Kaffee
2040
-	*  @deprecated deprecated but used in Kaffe 
2041
-	*/
2042
+	*	A dummy method added so RXTX compiles on Kaffee
2043
+	*	@deprecated deprecated but used in Kaffe 
2044
+	**/
2045
 	public void setRcvFifoTrigger(int trigger){};  
2046
 
2047
 /*------------------------  END OF CommAPI -----------------------------*/
2048
@@ -1724,542 +1935,542 @@
2049
 		throws UnsupportedCommOperationException;
2050
 
2051
 	/**
2052
-	*  Extension to CommAPI
2053
-	*  This is an extension to CommAPI.  It may not be supported on
2054
-	*  all operating systems.
2055
-	*
2056
-	*  This is only accurate up to 38600 baud currently.
2057
-	*
2058
-	*  @param  port the name of the port thats been preopened
2059
-	*  @return BaudRate on success
2060
-	*  @throws UnsupportedCommOperationException;
2061
-	*  This will not behave as expected with custom speeds
2062
+	*	Extension to CommAPI
2063
+	*	This is an extension to CommAPI.  It may not be supported on
2064
+	*	all operating systems.
2065
+	*
2066
+	*	This is only accurate up to 38600 baud currently.
2067
+	*
2068
+	*	@param  port the name of the port thats been preopened
2069
+	*	@return BaudRate on success
2070
+	*	@throws UnsupportedCommOperationException;
2071
+	*	This will not behave as expected with custom speeds
2072
 	*
2073
-	*/
2074
+	**/
2075
 	public static int staticGetBaudRate( String port )
2076
 		throws UnsupportedCommOperationException
2077
 	{
2078
 		if ( debug )
2079
-			z.reportln( 
2080
-				"RXTXPort:staticGetBaudRate( " + port + " )");
2081
+			System.out.println( 
2082
+				"RXTXPort:staticGetBaudRate(" + port + ")");
2083
 		return(nativeStaticGetBaudRate( port ));
2084
 	}
2085
 	/**
2086
-	*  Extension to CommAPI
2087
-	*  This is an extension to CommAPI.  It may not be supported on
2088
-	*  all operating systems.
2089
-	*
2090
-	*  @param  port the name of the port thats been preopened
2091
-	*  @return DataBits on success
2092
-	*  @throws UnsupportedCommOperationException;
2093
+	*	Extension to CommAPI
2094
+	*	This is an extension to CommAPI.  It may not be supported on
2095
+	*	all operating systems.
2096
+	*
2097
+	*	@param  port the name of the port thats been preopened
2098
+	*	@return DataBits on success
2099
+	*	@throws UnsupportedCommOperationException;
2100
 	*
2101
-	*/
2102
+	**/
2103
 	public static int staticGetDataBits( String port )
2104
 		throws UnsupportedCommOperationException
2105
 	{
2106
 		if ( debug )
2107
-			z.reportln( 
2108
-				"RXTXPort:staticGetDataBits( " + port + " )");
2109
+			System.out.println( 
2110
+				"RXTXPort:staticGetDataBits(" + port + ")");
2111
 		return(nativeStaticGetDataBits( port ) );
2112
 	}
2113
 
2114
 	/**
2115
-	*  Extension to CommAPI
2116
-	*  This is an extension to CommAPI.  It may not be supported on
2117
-	*  all operating systems.
2118
-	*
2119
-	*  @param  port the name of the port thats been preopened
2120
-	*  @return Parity on success
2121
-	*  @throws UnsupportedCommOperationException;
2122
+	*	Extension to CommAPI
2123
+	*	This is an extension to CommAPI.  It may not be supported on
2124
+	*	all operating systems.
2125
+	*
2126
+	*	@param  port the name of the port thats been preopened
2127
+	*	@return Parity on success
2128
+	*	@throws UnsupportedCommOperationException;
2129
 	*
2130
-	*/
2131
+	**/
2132
 	public static int staticGetParity( String port )
2133
 		throws UnsupportedCommOperationException
2134
 	{
2135
 		if ( debug )
2136
-			z.reportln( 
2137
-				"RXTXPort:staticGetParity( " + port + " )");
2138
+			System.out.println( 
2139
+				"RXTXPort:staticGetParity(" + port + ")");
2140
 		return( nativeStaticGetParity( port ) );
2141
 	}
2142
 
2143
 	/**
2144
-	*  Extension to CommAPI
2145
-	*  This is an extension to CommAPI.  It may not be supported on
2146
-	*  all operating systems.
2147
-	*
2148
-	*  @param  port the name of the port thats been preopened
2149
-	*  @return StopBits on success
2150
-	*  @throws UnsupportedCommOperationException;
2151
+	*	Extension to CommAPI
2152
+	*	This is an extension to CommAPI.  It may not be supported on
2153
+	*	all operating systems.
2154
+	*
2155
+	*	@param  port the name of the port thats been preopened
2156
+	*	@return StopBits on success
2157
+	*	@throws UnsupportedCommOperationException;
2158
 	*
2159
-	*/
2160
+	**/
2161
 	public static int staticGetStopBits( String port )
2162
 		throws UnsupportedCommOperationException
2163
 	{
2164
 		if ( debug )
2165
-			z.reportln( 
2166
-				"RXTXPort:staticGetStopBits( " + port + " )");
2167
+			System.out.println( 
2168
+				"RXTXPort:staticGetStopBits(" + port + ")");
2169
 			return(nativeStaticGetStopBits( port ) );
2170
 	}
2171
 
2172
 	/** 
2173
-	*  Extension to CommAPI
2174
-	*  This is an extension to CommAPI.  It may not be supported on
2175
-	*  all operating systems.
2176
-	*
2177
-	*  Set the SerialPort parameters
2178
-	*  1.5 stop bits requires 5 databits
2179
-	*  @param  f filename
2180
-	*  @param  b baudrate
2181
-	*  @param  d databits
2182
-	*  @param  s stopbits
2183
-	*  @param  p parity
2184
-	*
2185
-	*  @throws UnsupportedCommOperationException
2186
-	*  @see gnu.io.UnsupportedCommOperationException
2187
-	*/
2188
+	*	Extension to CommAPI
2189
+	*	This is an extension to CommAPI.  It may not be supported on
2190
+	*	all operating systems.
2191
+	*
2192
+	*	Set the SerialPort parameters
2193
+	*	1.5 stop bits requires 5 databits
2194
+	*	@param  f filename
2195
+	*	@param  b baudrate
2196
+	*	@param  d databits
2197
+	*	@param  s stopbits
2198
+	*	@param  p parity
2199
+	*
2200
+	*	@throws UnsupportedCommOperationException
2201
+	*	@see gnu.io.UnsupportedCommOperationException
2202
+	**/
2203
 
2204
 	public static void staticSetSerialPortParams( String f, int b, int d,
2205
 		int s, int p )
2206
 		throws UnsupportedCommOperationException
2207
 	{
2208
 		if ( debug )
2209
-			z.reportln( 
2210
-				"RXTXPort:staticSetSerialPortParams( " +
2211
+			System.out.println( 
2212
+				"RXTXPort:staticSetSerialPortParams(" +
2213
 				f + " " + b + " " + d + " " + s + " " + p );
2214
 		nativeStaticSetSerialPortParams( f, b, d, s, p );
2215
 	}
2216
 
2217
 	/**
2218
-	*  Extension to CommAPI
2219
-	*  This is an extension to CommAPI.  It may not be supported on
2220
-	*  all operating systems.
2221
-	*
2222
-	*  Open the port and set DSR.  remove lockfile and do not close
2223
-	*  This is so some software can appear to set the DSR before 'opening'
2224
-	*  the port a second time later on.
2225
+	*	Extension to CommAPI
2226
+	*	This is an extension to CommAPI.  It may not be supported on
2227
+	*	all operating systems.
2228
+	*
2229
+	*	Open the port and set DSR.  remove lockfile and do not close
2230
+	*	This is so some software can appear to set the DSR before 'opening'
2231
+	*	the port a second time later on.
2232
 	*
2233
-	*  @return true on success
2234
-	*  @throws UnsupportedCommOperationException;
2235
+	*	@return true on success
2236
+	*	@throws UnsupportedCommOperationException;
2237
 	*
2238
-	*/
2239
+	**/
2240
 
2241
 	public static boolean staticSetDSR( String port, boolean flag )
2242
 		throws UnsupportedCommOperationException
2243
 	{
2244
 		if ( debug )
2245
-			z.reportln(  "RXTXPort:staticSetDSR( " + port +
2246
+			System.out.println(  "RXTXPort:staticSetDSR(" + port +
2247
 						" " + flag );
2248
 		return( nativeStaticSetDSR( port, flag ) );
2249
 	}
2250
 
2251
 	/**
2252
-	*  Extension to CommAPI
2253
-	*  This is an extension to CommAPI.  It may not be supported on
2254
-	*  all operating systems.
2255
-	*
2256
-	*  Open the port and set DTR.  remove lockfile and do not close
2257
-	*  This is so some software can appear to set the DTR before 'opening'
2258
-	*  the port a second time later on.
2259
+	*	Extension to CommAPI
2260
+	*	This is an extension to CommAPI.  It may not be supported on
2261
+	*	all operating systems.
2262
+	*
2263
+	*	Open the port and set DTR.  remove lockfile and do not close
2264
+	*	This is so some software can appear to set the DTR before 'opening'
2265
+	*	the port a second time later on.
2266
 	*
2267
-	*  @return true on success
2268
-	*  @throws UnsupportedCommOperationException;
2269
+	*	@return true on success
2270
+	*	@throws UnsupportedCommOperationException;
2271
 	*
2272
-	*/
2273
+	**/
2274
 
2275
 	public static boolean staticSetDTR( String port, boolean flag )
2276
 		throws UnsupportedCommOperationException
2277
 	{
2278
 		if ( debug )
2279
-			z.reportln(  "RXTXPort:staticSetDTR( " + port +
2280
+			System.out.println(  "RXTXPort:staticSetDTR(" + port +
2281
 						" " + flag );
2282
 		return( nativeStaticSetDTR( port, flag ) );
2283
 	}
2284
 
2285
 	/**
2286
-	*  Extension to CommAPI
2287
-	*  This is an extension to CommAPI.  It may not be supported on
2288
-	*  all operating systems.
2289
-	*
2290
-	*  Open the port and set RTS.  remove lockfile and do not close
2291
-	*  This is so some software can appear to set the RTS before 'opening'
2292
-	*  the port a second time later on.
2293
+	*	Extension to CommAPI
2294
+	*	This is an extension to CommAPI.  It may not be supported on
2295
+	*	all operating systems.
2296
+	*
2297
+	*	Open the port and set RTS.  remove lockfile and do not close
2298
+	*	This is so some software can appear to set the RTS before 'opening'
2299
+	*	the port a second time later on.
2300
 	*
2301
-	*  @return none
2302
-	*  @throws UnsupportedCommOperationException;
2303
+	*	@return none
2304
+	*	@throws UnsupportedCommOperationException;
2305
 	*
2306
-	*/
2307
+	**/
2308
 
2309
 	public static boolean staticSetRTS( String port, boolean flag )
2310
 		throws UnsupportedCommOperationException
2311
 	{
2312
 		if ( debug )
2313
-			z.reportln(  "RXTXPort:staticSetRTS( " + port +
2314
+			System.out.println(  "RXTXPort:staticSetRTS(" + port +
2315
 						" " + flag );
2316
 		return( nativeStaticSetRTS( port, flag ) );
2317
 	}
2318
 
2319
 	/**
2320
-	*  Extension to CommAPI
2321
-	*  This is an extension to CommAPI.  It may not be supported on
2322
-	*  all operating systems.
2323
+	*	Extension to CommAPI
2324
+	*	This is an extension to CommAPI.  It may not be supported on
2325
+	*	all operating systems.
2326
 	*
2327
-	*  find the fd and return RTS without using a Java open() call
2328
+	*	find the fd and return RTS without using a Java open() call
2329
 	*
2330
-	*  @param port
2331
-	*  @return true if asserted
2332
-	*  @throws UnsupportedCommOperationException;
2333
+	*	@param port
2334
+	*	@return true if asserted
2335
+	*	@throws UnsupportedCommOperationException;
2336
 	*
2337
-	*/
2338
+	**/
2339
 
2340
 	public static boolean staticIsRTS( String port )
2341
 		throws UnsupportedCommOperationException
2342
 	{
2343
 		if ( debug )
2344
-			z.reportln(  "RXTXPort:staticIsRTS( " + port + " )" );
2345
+			System.out.println(  "RXTXPort:staticIsRTS(" + port + ")" );
2346
 		return( nativeStaticIsRTS( port ) );
2347
 	}
2348
 	/**
2349
-	*  Extension to CommAPI
2350
-	*  This is an extension to CommAPI.  It may not be supported on
2351
-	*  all operating systems.
2352
+	*	Extension to CommAPI
2353
+	*	This is an extension to CommAPI.  It may not be supported on
2354
+	*	all operating systems.
2355
 	*
2356
-	*  find the fd and return CD without using a Java open() call
2357
+	*	find the fd and return CD without using a Java open() call
2358
 	*
2359
-	*  @param port
2360
-	*  @return true if asserted
2361
-	*  @throws UnsupportedCommOperationException;
2362
+	*	@param port
2363
+	*	@return true if asserted
2364
+	*	@throws UnsupportedCommOperationException;
2365
 	*
2366
-	*/
2367
+	**/
2368
 
2369
 	public static boolean staticIsCD( String port )
2370
 		throws UnsupportedCommOperationException
2371
 	{
2372
 		if ( debug )
2373
-			z.reportln( "RXTXPort:staticIsCD( " + port + " )" );
2374
+			System.out.println("RXTXPort:staticIsCD(" + port + ")" );
2375
 		return( nativeStaticIsCD( port ) );
2376
 	}
2377
 	/**
2378
-	*  Extension to CommAPI
2379
-	*  This is an extension to CommAPI.  It may not be supported on
2380
-	*  all operating systems.
2381
+	*	Extension to CommAPI
2382
+	*	This is an extension to CommAPI.  It may not be supported on
2383
+	*	all operating systems.
2384
 	*
2385
-	*  find the fd and return CTS without using a Java open() call
2386
+	*	find the fd and return CTS without using a Java open() call
2387
 	*
2388
-	*  @param port
2389
-	*  @return true if asserted
2390
-	*  @throws UnsupportedCommOperationException;
2391
+	*	@param port
2392
+	*	@return true if asserted
2393
+	*	@throws UnsupportedCommOperationException;
2394
 	*
2395
-	*/
2396
+	**/
2397
 
2398
 	public static boolean staticIsCTS( String port )
2399
 		throws UnsupportedCommOperationException
2400
 	{
2401
 		if ( debug )
2402
-			z.reportln(  "RXTXPort:staticIsCTS( " + port + " )" );
2403
+			System.out.println(  "RXTXPort:staticIsCTS(" + port + ")" );
2404
 		return( nativeStaticIsCTS( port ) );
2405
 	}
2406
 	/**
2407
-	*  Extension to CommAPI
2408
-	*  This is an extension to CommAPI.  It may not be supported on
2409
-	*  all operating systems.
2410
+	*	Extension to CommAPI
2411
+	*	This is an extension to CommAPI.  It may not be supported on
2412
+	*	all operating systems.
2413
 	*
2414
-	*  find the fd and return DSR without using a Java open() call
2415
+	*	find the fd and return DSR without using a Java open() call
2416
 	*
2417
-	*  @param port
2418
-	*  @return true if asserted
2419
-	*  @throws UnsupportedCommOperationException;
2420
+	*	@param port
2421
+	*	@return true if asserted
2422
+	*	@throws UnsupportedCommOperationException;
2423
 	*
2424
-	*/
2425
+	**/
2426
 
2427
 	public static boolean staticIsDSR( String port )
2428
 		throws UnsupportedCommOperationException
2429
 	{
2430
 		if ( debug )
2431
-			z.reportln(  "RXTXPort:staticIsDSR( " + port + " )" );
2432
+			System.out.println(  "RXTXPort:staticIsDSR(" + port + ")" );
2433
 		return( nativeStaticIsDSR( port ) );
2434
 	}
2435
 	/**
2436
-	*  Extension to CommAPI
2437
-	*  This is an extension to CommAPI.  It may not be supported on
2438
-	*  all operating systems.
2439
+	*	Extension to CommAPI
2440
+	*	This is an extension to CommAPI.  It may not be supported on
2441
+	*	all operating systems.
2442
 	*
2443
-	*  find the fd and return DTR without using a Java open() call
2444
+	*	find the fd and return DTR without using a Java open() call
2445
 	*
2446
-	*  @param port
2447
-	*  @return true if asserted
2448
-	*  @throws UnsupportedCommOperationException;
2449
+	*	@param port
2450
+	*	@return true if asserted
2451
+	*	@throws UnsupportedCommOperationException;
2452
 	*
2453
-	*/
2454
+	**/
2455
 
2456
 	public static boolean staticIsDTR( String port )
2457
 		throws UnsupportedCommOperationException
2458
 	{
2459
 		if ( debug )
2460
-			z.reportln(  "RXTXPort:staticIsDTR( " + port + " )" );
2461
+			System.out.println(  "RXTXPort:staticIsDTR(" + port + ")" );
2462
 		return( nativeStaticIsDTR( port ) );
2463
 	}
2464
 	/**
2465
-	*  Extension to CommAPI
2466
-	*  This is an extension to CommAPI.  It may not be supported on
2467
-	*  all operating systems.
2468
+	*	Extension to CommAPI
2469
+	*	This is an extension to CommAPI.  It may not be supported on
2470
+	*	all operating systems.
2471
 	*
2472
-	*  find the fd and return RI without using a Java open() call
2473
+	*	find the fd and return RI without using a Java open() call
2474
 	*
2475
-	*  @param port
2476
-	*  @return true if asserted
2477
-	*  @throws UnsupportedCommOperationException;
2478
+	*	@param port
2479
+	*	@return true if asserted
2480
+	*	@throws UnsupportedCommOperationException;
2481
 	*
2482
-	*/
2483
+	**/
2484
 
2485
 	public static boolean staticIsRI( String port )
2486
 		throws UnsupportedCommOperationException
2487
 	{
2488
 		if ( debug )
2489
-			z.reportln(  "RXTXPort:staticIsRI( " + port + " )" );
2490
+			System.out.println(  "RXTXPort:staticIsRI(" + port + ")" );
2491
 		return( nativeStaticIsRI( port ) );
2492
 	}
2493
 
2494
 
2495
 	/**
2496
-	*  Extension to CommAPI
2497
-	*  This is an extension to CommAPI.  It may not be supported on
2498
-	*  all operating systems.
2499
-	*  @return int the Parity Error Character
2500
-	*  @throws UnsupportedCommOperationException;
2501
+	*	Extension to CommAPI
2502
+	*	This is an extension to CommAPI.  It may not be supported on
2503
+	*	all operating systems.
2504
+	*	@return int the Parity Error Character
2505
+	*	@throws UnsupportedCommOperationException;
2506
 	*
2507
-	*  Anyone know how to do this in Unix?
2508
-	*/
2509
+	*	Anyone know how to do this in Unix?
2510
+	**/
2511
 
2512
 	public byte getParityErrorChar( )
2513
 		throws UnsupportedCommOperationException
2514
 	{
2515
 		byte ret;
2516
 		if ( debug )
2517
-			z.reportln(  "getParityErrorChar()" );
2518
+			System.out.println(  "getParityErrorChar()" );
2519
 		ret = nativeGetParityErrorChar();
2520
 		if ( debug )
2521
-			z.reportln(  "getParityErrorChar() returns " +
2522
+			System.out.println(  "getParityErrorChar() returns " +
2523
 						ret );
2524
 		return( ret );
2525
 	}
2526
 
2527
 	/**
2528
-	*  Extension to CommAPI
2529
-	*  This is an extension to CommAPI.  It may not be supported on
2530
-	*  all operating systems.
2531
-	*  @param b Parity Error Character
2532
-	*  @return boolean true on success
2533
-	*  @throws UnsupportedCommOperationException;
2534
+	*	Extension to CommAPI
2535
+	*	This is an extension to CommAPI.  It may not be supported on
2536
+	*	all operating systems.
2537
+	*	@param b Parity Error Character
2538
+	*	@return boolean true on success
2539
+	*	@throws UnsupportedCommOperationException;
2540
 	*
2541
-	*  Anyone know how to do this in Unix?
2542
-	*/
2543
+	*	Anyone know how to do this in Unix?
2544
+	**/
2545
 
2546
 	public boolean setParityErrorChar( byte b )
2547
 		throws UnsupportedCommOperationException
2548
 	{
2549
 		if ( debug )
2550
-			z.reportln(  "setParityErrorChar(" + b + ")" );
2551
+			System.out.println(  "setParityErrorChar(" + b + ")" );
2552
 		return( nativeSetParityErrorChar( b ) );
2553
 	}
2554
 
2555
 	/**
2556
-	*  Extension to CommAPI
2557
-	*  This is an extension to CommAPI.  It may not be supported on
2558
-	*  all operating systems.
2559
-	*  @return int the End of Input Character
2560
-	*  @throws UnsupportedCommOperationException;
2561
+	*	Extension to CommAPI
2562
+	*	This is an extension to CommAPI.  It may not be supported on
2563
+	*	all operating systems.
2564
+	*	@return int the End of Input Character
2565
+	*	@throws UnsupportedCommOperationException;
2566
 	*
2567
-	*  Anyone know how to do this in Unix?
2568
-	*/
2569
+	*	Anyone know how to do this in Unix?
2570
+	**/
2571
 
2572
 	public byte getEndOfInputChar( )
2573
 		throws UnsupportedCommOperationException
2574
 	{
2575
 		byte ret;
2576
 		if ( debug )
2577
-			z.reportln(  "getEndOfInputChar()" );
2578
+			System.out.println(  "getEndOfInputChar()" );
2579
 		ret = nativeGetEndOfInputChar();
2580
 		if ( debug )
2581
-			z.reportln(  "getEndOfInputChar() returns " +
2582
+			System.out.println(  "getEndOfInputChar() returns " +
2583
 						ret );
2584
 		return( ret );
2585
 	}
2586
 
2587
 	/**
2588
-	*  Extension to CommAPI
2589
-	*  This is an extension to CommAPI.  It may not be supported on
2590
-	*  all operating systems.
2591
-	*  @param b End Of Input Character
2592
-	*  @return boolean true on success
2593
-	*  @throws UnsupportedCommOperationException;
2594
-	*/
2595
+	*	Extension to CommAPI
2596
+	*	This is an extension to CommAPI.  It may not be supported on
2597
+	*	all operating systems.
2598
+	*	@param b End Of Input Character
2599
+	*	@return boolean true on success
2600
+	*	@throws UnsupportedCommOperationException;
2601
+	**/
2602
 
2603
 	public boolean setEndOfInputChar( byte b )
2604
 		throws UnsupportedCommOperationException
2605
 	{
2606
 		if ( debug )
2607
-			z.reportln(  "setEndOfInputChar(" + b + ")" );
2608
+			System.out.println(  "setEndOfInputChar(" + b + ")" );
2609
 		return( nativeSetEndOfInputChar( b ) );
2610
 	}
2611
 
2612
 	/**
2613
-	*  Extension to CommAPI
2614
-	*  This is an extension to CommAPI.  It may not be supported on
2615
-	*  all operating systems.
2616
-	*  @param type String representation of the UART type which mayb
2617
-	*  be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2618
-	*  or "16750".
2619
-	*  @param test boolean flag to determin if the UART should be tested.
2620
-	*  @return boolean true on success
2621
-	*  @throws UnsupportedCommOperationException;
2622
-	*/
2623
+	*	Extension to CommAPI
2624
+	*	This is an extension to CommAPI.  It may not be supported on
2625
+	*	all operating systems.
2626
+	*	@param type String representation of the UART type which mayb
2627
+	*	be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2628
+	*	or "16750".
2629
+	*	@param test boolean flag to determin if the UART should be tested.
2630
+	*	@return boolean true on success
2631
+	*	@throws UnsupportedCommOperationException;
2632
+	**/
2633
 	public boolean setUARTType(String type, boolean test)
2634
 		throws UnsupportedCommOperationException
2635
 	{
2636
 		if ( debug )
2637
-			z.reportln(  "RXTXPort:setUARTType()");
2638
+			System.out.println(  "RXTXPort:setUARTType()");
2639
 		return nativeSetUartType(type, test);
2640
 	}
2641
 	/**
2642
-	*  Extension to CommAPI
2643
-	*  This is an extension to CommAPI.  It may not be supported on
2644
-	*  all operating systems.
2645
-	*  @return type String representation of the UART type which mayb
2646
-	*  be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2647
-	*  or "16750".
2648
-	*  @throws UnsupportedCommOperationException;
2649
-	*/
2650
+	*	Extension to CommAPI
2651
+	*	This is an extension to CommAPI.  It may not be supported on
2652
+	*	all operating systems.
2653
+	*	@return type String representation of the UART type which mayb
2654
+	*	be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2655
+	*	or "16750".
2656
+	*	@throws UnsupportedCommOperationException;
2657
+	**/
2658
 	public String getUARTType() throws UnsupportedCommOperationException
2659
 	{
2660
 		return nativeGetUartType();
2661
 	}
2662
 
2663
 	/**
2664
-	*  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
2665
-	*  before using.
2666
-	*  @param BaudBase The clock frequency divided by 16.  Default
2667
-	*  BaudBase is 115200.
2668
-	*  @return true on success
2669
-	*  @throws UnsupportedCommOperationException, IOException
2670
-	*/
2671
+	*	Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
2672
+	*	before using.
2673
+	*	@param BaudBase The clock frequency divided by 16.  Default
2674
+	*	BaudBase is 115200.
2675
+	*	@return true on success
2676
+	*	@throws UnsupportedCommOperationException, IOException
2677
+	**/
2678
 
2679
 	public boolean setBaudBase(int BaudBase)
2680
 		throws UnsupportedCommOperationException,
2681
 		IOException
2682
 	{
2683
 		if ( debug )
2684
-			z.reportln(  "RXTXPort:setBaudBase()");
2685
+			System.out.println(  "RXTXPort:setBaudBase()");
2686
 		return nativeSetBaudBase(BaudBase);
2687
 	}
2688
 
2689
 	/**
2690
-	*  Extension to CommAPI
2691
-	*  @return BaudBase
2692
-	*  @throws UnsupportedCommOperationException, IOException
2693
-	*/
2694
+	*	Extension to CommAPI
2695
+	*	@return BaudBase
2696
+	*	@throws UnsupportedCommOperationException, IOException
2697
+	**/
2698
 
2699
 	public int getBaudBase() throws UnsupportedCommOperationException,
2700
 		IOException
2701
 	{
2702
 		if ( debug )
2703
-			z.reportln(  "RXTXPort:getBaudBase()");
2704
+			System.out.println(  "RXTXPort:getBaudBase()");
2705
 		return nativeGetBaudBase();
2706
 	}
2707
 
2708
 	/**
2709
-	*  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
2710
-	*  before using.
2711
-	*  @param Divisor
2712
-	*  @throws UnsupportedCommOperationException, IOException
2713
-	*/
2714
+	*	Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
2715
+	*	before using.
2716
+	*	@param Divisor
2717
+	*	@throws UnsupportedCommOperationException, IOException
2718
+	**/
2719
 
2720
 	public boolean setDivisor(int Divisor)
2721
 		throws UnsupportedCommOperationException, IOException
2722
 	{
2723
 		if ( debug )
2724
-			z.reportln(  "RXTXPort:setDivisor()");
2725
+			System.out.println(  "RXTXPort:setDivisor()");
2726
 		return nativeSetDivisor(Divisor);
2727
 	}
2728
 
2729
 	/**
2730
-	*  Extension to CommAPI
2731
-	*  @return Divisor;
2732
-	*  @throws UnsupportedCommOperationException, IOException
2733
-	*/
2734
+	*	Extension to CommAPI
2735
+	*	@return Divisor;
2736
+	*	@throws UnsupportedCommOperationException, IOException
2737
+	**/
2738
 
2739
 	public int getDivisor() throws UnsupportedCommOperationException,
2740
 		IOException
2741
 	{
2742
 		if ( debug )
2743
-			z.reportln(  "RXTXPort:getDivisor()");
2744
+			System.out.println(  "RXTXPort:getDivisor()");
2745
 		return nativeGetDivisor();
2746
 	}
2747
 
2748
 	/**
2749
-	*  Extension to CommAPI
2750
-	*  returns boolean true on success
2751
-	*  @throws UnsupportedCommOperationException
2752
-	*/
2753
+	*	Extension to CommAPI
2754
+	*	returns boolean true on success
2755
+	*	@throws UnsupportedCommOperationException
2756
+	**/
2757
 
2758
 	public boolean setLowLatency() throws UnsupportedCommOperationException
2759
 	{
2760
 		if ( debug )
2761
-			z.reportln(  "RXTXPort:setLowLatency()");
2762
+			System.out.println(  "RXTXPort:setLowLatency()");
2763
 		return nativeSetLowLatency();
2764
 	}
2765
 
2766
 	/**
2767
-	*  Extension to CommAPI
2768
-	*  returns boolean true on success
2769
-	*  @throws UnsupportedCommOperationException
2770
-	*/
2771
+	*	Extension to CommAPI
2772
+	*	returns boolean true on success
2773
+	*	@throws UnsupportedCommOperationException
2774
+	**/
2775
 
2776
 	public boolean getLowLatency() throws UnsupportedCommOperationException
2777
 	{
2778
 		if ( debug )
2779
-			z.reportln(  "RXTXPort:getLowLatency()");
2780
+			System.out.println(  "RXTXPort:getLowLatency()");
2781
 		return nativeGetLowLatency();
2782
 	}
2783
 
2784
 	/**
2785
-	*  Extension to CommAPI
2786
-	*  returns boolean true on success
2787
-	*  @throws UnsupportedCommOperationException
2788
-	*/
2789
+	*	Extension to CommAPI
2790
+	*	returns boolean true on success
2791
+	*	@throws UnsupportedCommOperationException
2792
+	**/
2793
 
2794
 	public boolean setCallOutHangup(boolean NoHup)
2795
 		throws UnsupportedCommOperationException
2796
 	{
2797
 		if ( debug )
2798
-			z.reportln(  "RXTXPort:setCallOutHangup()");
2799
+			System.out.println(  "RXTXPort:setCallOutHangup()");
2800
 		return nativeSetCallOutHangup(NoHup);
2801
 	}
2802
 
2803
 	/**
2804
-	*  Extension to CommAPI
2805
-	*  returns boolean true on success
2806
-	*  @throws UnsupportedCommOperationException
2807
-	*/
2808
+	*	Extension to CommAPI
2809
+	*	returns boolean true on success
2810
+	*	@throws UnsupportedCommOperationException
2811
+	**/
2812
 
2813
 	public boolean getCallOutHangup()
2814
 		throws UnsupportedCommOperationException
2815
 	{
2816
 		if ( debug )
2817
-			z.reportln(  "RXTXPort:getCallOutHangup()");
2818
+			System.out.println(  "RXTXPort:getCallOutHangup()");
2819
 		return nativeGetCallOutHangup();
2820
 	}
2821
 
2822
 	/**
2823
-	*  Extension to CommAPI
2824
-	*  returns boolean true on success
2825
-	*  @throws UnsupportedCommOperationException
2826
-	*/
2827
+	*	Extension to CommAPI
2828
+	*	returns boolean true on success
2829
+	*	@throws UnsupportedCommOperationException
2830
+	**/
2831
 
2832
 	public boolean clearCommInput()
2833
 		throws UnsupportedCommOperationException
2834
 	{
2835
 		if ( debug )
2836
-			z.reportln(  "RXTXPort:clearCommInput()");
2837
+			System.out.println(  "RXTXPort:clearCommInput()");
2838
 		return nativeClearCommInput();
2839
 	}
2840
 
(-)files/patch-src-gnu-io-SerialPortEvent.java (+11 lines)
Line 0 Link Here
1
--- src/gnu/io/SerialPortEvent.java.orig	2007-04-26 06:26:06.000000000 +0100
2
+++ src/gnu/io/SerialPortEvent.java	2015-05-11 16:51:34.000000000 +0100
3
@@ -76,6 +76,8 @@
4
 	public static final int PE                  =8;
5
 	public static final int FE                  =9;
6
 	public static final int BI                 =10;
7
+	
8
+	private final static boolean debug = "true".equals( System.getProperty( "gnu.io.rxtx.DEBUG" ) );
9
 
10
 	private boolean OldValue;
11
 	private boolean NewValue;

Return to bug 200179