~ubuntu-branches/ubuntu/edgy/rxtx/edgy-201105201527

« back to all changes in this revision

Viewing changes to src/RXTXPort.java

  • Committer: Bazaar Package Importer
  • Author(s): Mario Joussen
  • Date: 2006-03-01 18:56:52 UTC
  • mfrom: (1.2.1 upstream) (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20060301185652-zay4t2ho3sp9fygt
Fixed stupid bug in clean target.
(closes: Bug#354859)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*-------------------------------------------------------------------------
2
2
|   rxtx is a native interface to serial ports in java.
3
 
|   Copyright 1997-2001 by Trent Jarvi trentjarvi@yahoo.com.
 
3
|   Copyright 1997-2006 by Trent Jarvi taj@www.linux.org.uk.
4
4
|
5
5
|   This library is free software; you can redistribute it and/or
6
6
|   modify it under the terms of the GNU Library General Public
30
30
 
31
31
final public class RXTXPort extends SerialPort
32
32
{
33
 
 
34
 
        private static boolean debug = false;
35
 
        private static boolean debug_verbose = false;
 
33
        /* I had a report that some JRE's complain when MonitorThread
 
34
           tries to access private variables
 
35
        */
 
36
 
 
37
        protected final static boolean debug = false;
 
38
        protected final static boolean debug_read = false;
 
39
        protected final static boolean debug_read_results = false;
 
40
        protected final static boolean debug_write = false;
 
41
        protected final static boolean debug_events = false;
 
42
        protected final static boolean debug_verbose = false;
 
43
 
 
44
        private static Zystem z;
 
45
 
36
46
        static
37
47
        {
 
48
                try {
 
49
                        z = new Zystem();
 
50
                } catch ( Exception e ) {};
 
51
 
38
52
                if(debug ) 
39
 
                        System.out.println("RXTXPort {}");
40
 
                System.loadLibrary( "Serial" );
 
53
                        z.reportln( "RXTXPort {}");
 
54
                System.loadLibrary( "rxtxSerial" );
41
55
                Initialize();
42
56
        }
43
57
 
44
 
 
45
58
        /** Initialize the native library */
46
59
        private native static void Initialize();
47
60
        boolean MonitorThreadAlive=false;
55
68
        public RXTXPort( String name ) throws PortInUseException
56
69
        {
57
70
                if (debug)
58
 
                        System.out.println("RXTXPort:RXTXPort("+name+")");
 
71
                        z.reportln( "RXTXPort:RXTXPort("+name+") called");
59
72
        /* 
60
73
           commapi/javadocs/API_users_guide.html specifies that whenever
61
74
           an application tries to open a port in use by another application
77
90
                        waitForTheNativeCodeSilly();
78
91
                        MonitorThreadAlive=true;
79
92
        //      } catch ( PortInUseException e ){}
 
93
                timeout = -1;   /* default disabled timeout */
80
94
                if (debug)
81
 
                        System.out.println("RXTXPort:RXTXPort("+name+") fd = " +
 
95
                        z.reportln( "RXTXPort:RXTXPort("+name+") returns with fd = " +
82
96
                                fd);
83
 
                timeout = -1;   /* default disabled timeout */
84
97
        }
85
98
        private native synchronized int open( String name )
86
99
                throws PortInUseException;
87
100
 
 
101
 
 
102
        /* dont close the file while accessing the fd */
 
103
        int IOLocked = 0;
 
104
 
88
105
        /** File descriptor */
89
106
        private int fd = 0;
 
107
 
90
108
        /** a pointer to the event info structure used to share information
91
109
            between threads so write threads can send output buffer empty
92
110
            from a pthread if need be.
 
111
 
 
112
            long for 64 bit pointers.
93
113
        */
94
 
        int eis = 0;
 
114
        long eis = 0;
95
115
        /** pid for lock files */
96
116
        int pid = 0;
97
117
 
104
124
        *  get the OutputStream
105
125
        *  @return OutputStream
106
126
        */
107
 
        public OutputStream getOutputStream() { return out; }
 
127
        public OutputStream getOutputStream()
 
128
        {
 
129
                if (debug)
 
130
                        z.reportln( "RXTXPort:getOutputStream() called and returning");
 
131
                return out;
 
132
        }
108
133
 
109
134
        /** Input stream */
110
135
        private final SerialInputStream in = new SerialInputStream();
113
138
        *  @return InputStream
114
139
        *  @see java.io.InputStream
115
140
        */
116
 
        public InputStream getInputStream() { return in; }
 
141
        public InputStream getInputStream()
 
142
        {
 
143
                if (debug)
 
144
                        z.reportln( "RXTXPort:getInputStream() called and returning");
 
145
                return in;
 
146
        }
117
147
 
118
148
        /** 
119
149
        *  Set the SerialPort parameters
124
154
        *  @param  p parity
125
155
        *  @throws UnsupportedCommOperationException
126
156
        *  @see gnu.io.UnsupportedCommOperationException
 
157
 
 
158
        *  If speed is not a predifined speed it is assumed to be
 
159
        *  the actual speed desired.
127
160
        */
128
 
        public synchronized void setSerialPortParams( int b, int d, int s, int p )
 
161
        private native int nativeGetParity( int fd );
 
162
        private native int nativeGetFlowControlMode( int fd );
 
163
        public synchronized void setSerialPortParams( int b, int d, int s,
 
164
                int p )
129
165
                throws UnsupportedCommOperationException
130
166
        {
131
167
                if (debug)
132
 
                        System.out.println("RXTXPort:setSerialPortParams(" +
133
 
                                        b + " " + d + " " + s + " " + p + ")");
134
 
                nativeSetSerialPortParams( b, d, s, p );
 
168
                        z.reportln( "RXTXPort:setSerialPortParams(" +
 
169
                                b + " " + d + " " + s + " " + p + ") called");
 
170
                if ( nativeSetSerialPortParams( b, d, s, p ) )
 
171
                        throw new UnsupportedCommOperationException(
 
172
                                "Invalid Parameter" );
135
173
                speed = b;
136
174
                if( s== STOPBITS_1_5 ) dataBits = DATABITS_5;
137
175
                else dataBits = d;
138
176
                stopBits = s;
139
177
                parity = p;
 
178
                        z.reportln( "RXTXPort:setSerialPortParams(" +
 
179
                                b + " " + d + " " + s + " " + p +
 
180
                                ") returning");
140
181
        }
141
182
 
142
 
        /** Set the native serial port parameters */
143
 
        private native void nativeSetSerialPortParams( int speed, int dataBits,
144
 
                int stopBits, int parity )
 
183
        /**
 
184
        *  Set the native serial port parameters
 
185
        *  If speed is not a predifined speed it is assumed to be
 
186
        *  the actual speed desired.
 
187
        */
 
188
        private native boolean nativeSetSerialPortParams( int speed,
 
189
                int dataBits, int stopBits, int parity )
145
190
                throws UnsupportedCommOperationException;
146
191
 
147
192
        /** Line speed in bits-per-second */
148
193
        private int speed=9600;
149
194
        /** 
150
195
        *  @return  int representing the baudrate
 
196
        *  This will not behave as expected with custom speeds
151
197
        */
152
 
        public int getBaudRate() { return speed; }
 
198
        public int getBaudRate()
 
199
        {
 
200
                if (debug)
 
201
                        z.reportln( "RXTXPort:getBaudRate() called and returning " + speed);
 
202
                return speed;
 
203
        }
153
204
 
154
205
        /** Data bits port parameter */
155
206
        private int dataBits=DATABITS_8;
156
207
        /** 
157
208
        *  @return int representing the databits
158
209
        */
159
 
        public int getDataBits() { return dataBits; }
 
210
        public int getDataBits()
 
211
        {
 
212
                if (debug)
 
213
                        z.reportln( "RXTXPort:getDataBits() called and returning " + dataBits);
 
214
                return dataBits;
 
215
        }
160
216
 
161
217
        /** Stop bits port parameter */
162
218
        private int stopBits=SerialPort.STOPBITS_1;
163
219
        /** 
164
220
        *  @return int representing the stopbits
165
221
        */
166
 
        public int getStopBits() { return stopBits; }
 
222
        public int getStopBits()
 
223
        {
 
224
                if (debug)
 
225
                        z.reportln( "RXTXPort:getStopBits() called and returning " + stopBits);
 
226
                return stopBits;
 
227
        }
167
228
 
168
229
        /** Parity port parameter */
169
230
        private int parity= SerialPort.PARITY_NONE;
170
231
        /** 
171
232
        *  @return int representing the parity
172
233
        */
173
 
        public int getParity() { return parity; }
 
234
        public int getParity()
 
235
        {
 
236
                if (debug)
 
237
                        z.reportln( "RXTXPort:getParity() called and returning " + parity );
 
238
                return parity;
 
239
        }
174
240
 
175
241
 
176
242
        /** Flow control */
182
248
        public void setFlowControlMode( int flowcontrol )
183
249
        {
184
250
                if (debug)
185
 
                        System.out.println("RXTXPort:setFlowControlMode()");
186
 
                try { setflowcontrol( flowcontrol ); }
 
251
                        z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) called");
 
252
                if(monThreadisInterrupted) 
 
253
                {
 
254
                        if( debug_events )
 
255
                                z.reportln(  "RXTXPort:setFlowControlMode MonThread is Interrupeted returning" );
 
256
                        return;
 
257
                }
 
258
                try {
 
259
                        setflowcontrol( flowcontrol );
 
260
                }
187
261
                catch( IOException e )
188
262
                {
189
263
                        e.printStackTrace();
190
264
                        return;
191
265
                }
192
266
                flowmode=flowcontrol;
 
267
                if (debug)
 
268
                        z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) returning");
193
269
        }
194
270
        /** 
195
271
        *  @return  int representing the flowmode
196
272
        */
197
 
        public int getFlowControlMode() { return flowmode; }
 
273
        public int getFlowControlMode()
 
274
        {
 
275
                if (debug)
 
276
                        z.reportln( "RXTXPort:getFlowControlMode() returning " + flowmode );
 
277
                return flowmode;
 
278
        }
198
279
        native void setflowcontrol( int flowcontrol ) throws IOException;
199
280
 
200
281
 
201
282
        /*
202
283
        linux/drivers/char/n_hdlc.c? FIXME
203
 
                trentjarvi@yahoo.com
 
284
                taj@www.linux.org.uk
204
285
        */
205
286
        /**
206
287
        *  Receive framing control
211
292
                throws UnsupportedCommOperationException
212
293
        {
213
294
                if (debug)
214
 
                        System.out.println("RXTXPort:enableReceiveFramming()");
 
295
                        z.reportln( "RXTXPort:enableReceiveFramming() throwing exception");
215
296
                throw new UnsupportedCommOperationException( "Not supported" );
216
297
        }
217
298
        /** 
219
300
        public void disableReceiveFraming()
220
301
        {
221
302
                if (debug)
222
 
                        System.out.println("RXTXPort:disableReceiveFramming()");
 
303
                        z.reportln( "RXTXPort:disableReceiveFramming() called and returning (noop)");
223
304
        }
224
305
        /** 
225
306
        *  @returns true if framing is enabled
227
308
        public boolean isReceiveFramingEnabled()
228
309
        {
229
310
                if (debug)
230
 
                        System.out.println("RXTXPort:isReceiveFrammingEnabled()");
 
311
                        z.reportln( "RXTXPort:isReceiveFrammingEnabled() called and returning " + false );
231
312
                return false;
232
313
        }
233
314
        /** 
236
317
        public int getReceiveFramingByte()
237
318
        {
238
319
                if (debug)
239
 
                        System.out.println("RXTXPort:getReceiveFrammingByte()");
 
320
                        z.reportln( "RXTXPort:getReceiveFrammingByte() called and returning " + 0 );
240
321
                return 0;
241
322
        }
242
323
 
251
332
        /** 
252
333
        *  @return  bloolean true if recieve timeout is enabled
253
334
        */
254
 
        public native boolean NativeisReceiveTimeoutEnabled();
 
335
        private native boolean NativeisReceiveTimeoutEnabled();
255
336
        /** 
256
337
        *  @param  time
257
338
        *  @param  threshold
258
339
        *  @param  InputBuffer
259
340
        */
260
 
        public native void NativeEnableReceiveTimeoutThreshold(int time,
 
341
        private native void NativeEnableReceiveTimeoutThreshold(int time,
261
342
                int threshold,int InputBuffer);
262
343
        /** 
263
344
        */
264
345
        public void disableReceiveTimeout()
265
346
        {
266
347
                if (debug)
267
 
                        System.out.println("RXTXPort:disableReceiveTimeout()");
268
 
                enableReceiveTimeout(0);
 
348
                        z.reportln( "RXTXPort:disableReceiveTimeout() called");
 
349
                timeout = -1;
 
350
                NativeEnableReceiveTimeoutThreshold( timeout , threshold, InputBuffer );
 
351
                if (debug)
 
352
                        z.reportln( "RXTXPort:disableReceiveTimeout() returning");
269
353
        }
270
354
        /** 
271
355
        *  @param time
273
357
        public void enableReceiveTimeout( int time )
274
358
        {
275
359
                if (debug)
276
 
                        System.out.println("RXTXPort:enableReceiveTimeout()");
 
360
                        z.reportln( "RXTXPort:enableReceiveTimeout() called");
277
361
                if( time >= 0 )
278
362
                {
279
363
                        timeout = time;
287
371
                                "Unexpected negative timeout value"
288
372
                        );
289
373
                }
 
374
                if (debug)
 
375
                        z.reportln( "RXTXPort:enableReceiveTimeout() returning");
290
376
        }
291
377
        /** 
292
378
        *  @return  boolean true if recieve timeout is enabled
294
380
        public boolean isReceiveTimeoutEnabled()
295
381
        {
296
382
                if (debug)
297
 
                        System.out.println("RXTXPort:isReceiveTimeoutEnabled()");
298
 
                return(NativeisReceiveTimeoutEnabled());
 
383
                        z.reportln( "RXTXPort:isReceiveTimeoutEnabled() called and returning " + NativeisReceiveTimeoutEnabled() );
 
384
                return( NativeisReceiveTimeoutEnabled() );
299
385
        }
300
386
        /** 
301
387
        *  @return  int the timeout
303
389
        public int getReceiveTimeout()
304
390
        {
305
391
                if (debug)
306
 
                        System.out.println("RXTXPort:getReceiveTimeout()");
 
392
                        z.reportln( "RXTXPort:getReceiveTimeout() called and returning " + NativegetReceiveTimeout() );
307
393
                return(NativegetReceiveTimeout( ));
308
394
        }
309
395
 
317
403
        public void enableReceiveThreshold( int thresh )
318
404
        {
319
405
                if (debug)
320
 
                        System.out.println("RXTXPort:enableReceiveThreshold()");
 
406
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) called");
321
407
                if(thresh >=0)
322
408
                {
323
409
                        threshold=thresh;
331
417
                                "Unexpected negative threshold value"
332
418
                        );
333
419
                }
 
420
                if (debug)
 
421
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) returned");
334
422
        }
335
423
        /** 
336
424
        */
337
425
        public void disableReceiveThreshold()
338
426
        {
339
427
                if (debug)
340
 
                        System.out.println("RXTXPort:disableReceiveThreshold()");
 
428
                        z.reportln( "RXTXPort:disableReceiveThreshold() called and returning");
341
429
                enableReceiveThreshold(0);
342
430
        }
343
431
        /** 
346
434
        public int getReceiveThreshold()
347
435
        {
348
436
                if (debug)
349
 
                        System.out.println("RXTXPort:getReceiveThreshold()");
 
437
                        z.reportln( "RXTXPort:getReceiveThreshold() called and returning " + threshold);
350
438
                return threshold;
351
439
        }
352
440
        /** 
355
443
        public boolean isReceiveThresholdEnabled()
356
444
        {
357
445
                if (debug)
358
 
                        System.out.println("RXTXPort:isReceiveThresholdEnable()");
 
446
                        z.reportln( "RXTXPort:isReceiveThresholdEnable() called and returning" + (threshold > 0) );
359
447
                return(threshold>0);
360
448
        }
361
449
 
362
450
        /** Input/output buffers */
363
451
        /** FIXME I think this refers to
364
452
                FOPEN(3)/SETBUF(3)/FREAD(3)/FCLOSE(3)
365
 
                trentjarvi@yahoo.com
 
453
                taj@www.linux.org.uk
366
454
 
367
455
                These are native stubs...
368
456
        */
374
462
        public void setInputBufferSize( int size )
375
463
        {
376
464
                if (debug)
377
 
                        System.out.println("RXTXPort:setInputBufferSize( " +
378
 
                                        size + ")");
 
465
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
466
                                        size + ") called");
379
467
                if( size < 0 )
380
468
                        throw new IllegalArgumentException
381
469
                        (
382
470
                                "Unexpected negative buffer size value"
383
471
                        );
384
472
                else InputBuffer=size;
 
473
                if (debug)
 
474
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
475
                                        size + ") returning");
385
476
        }
386
477
        /** 
387
478
        */
388
479
        public int getInputBufferSize()
389
480
        {
390
481
                if (debug)
391
 
                        System.out.println("RXTXPort:getInputBufferSize()");
 
482
                        z.reportln( "RXTXPort:getInputBufferSize() called and returning " + InputBuffer );
392
483
                return(InputBuffer);
393
484
        }
394
485
        /** 
397
488
        public void setOutputBufferSize( int size )
398
489
        {
399
490
                if (debug)
400
 
                        System.out.println("RXTXPort:setOutputBufferSize( " +
401
 
                                        size + ")");
 
491
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
492
                                        size + ") called");
402
493
                if( size < 0 )
403
494
                        throw new IllegalArgumentException
404
495
                        (
405
496
                                "Unexpected negative buffer size value"
406
497
                        );
407
498
                else OutputBuffer=size;
 
499
                if (debug)
 
500
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
501
                                        size + ") returned");
 
502
                
408
503
        }
409
504
        /** 
410
505
        *  @return  in the output buffer size
412
507
        public int getOutputBufferSize()
413
508
        {
414
509
                if (debug)
415
 
                        System.out.println("RXTXPort:getOutputBufferSize()");
 
510
                        z.reportln( "RXTXPort:getOutputBufferSize() called and returning " + OutputBuffer );
416
511
                return(OutputBuffer);
417
512
        }
418
513
 
 
514
        /* =================== cleaned messages to here */
 
515
 
419
516
        /**
420
517
        *  Line status methods
421
518
        */
459
556
        *  @param duration
460
557
        */
461
558
        public native void sendBreak( int duration );
462
 
        protected native void writeByte( int b ) throws IOException;
463
 
        protected native void writeArray( byte b[], int off, int len )
 
559
        protected native void writeByte( int b, boolean i ) throws IOException;
 
560
        protected native void writeArray( byte b[], int off, int len, boolean i )
464
561
                throws IOException;
465
 
        protected native void nativeDrain() throws IOException;
 
562
        protected native boolean nativeDrain( boolean i ) throws IOException;
466
563
 
467
564
        /** RXTXPort read methods */
468
565
        protected native int nativeavailable() throws IOException;
469
566
        protected native int readByte() throws IOException;
470
567
        protected native int readArray( byte b[], int off, int len )
471
568
                throws IOException;
 
569
        protected native int readTerminatedArray( byte b[], int off, int len, byte t[] )
 
570
                throws IOException;
472
571
 
473
572
 
474
573
        /** Serial Port Event listener */
488
587
        public boolean checkMonitorThread()
489
588
        {
490
589
                if (debug)
491
 
                        System.out.println("RXTXPort:checkMonitorThread()");
 
590
                        z.reportln( "RXTXPort:checkMonitorThread()");
492
591
                if(monThread != null)
493
592
                {
494
593
                        if ( debug )
495
 
                                System.out.println(
 
594
                                z.reportln( 
496
595
                                        "monThreadisInterrupted = " +
497
596
                                        monThreadisInterrupted );
498
597
                        return monThreadisInterrupted;
499
598
                }
500
599
                if ( debug )
501
 
                        System.out.println( "monThread is null " );
 
600
                        z.reportln(  "monThread is null " );
502
601
                return(true);
503
602
        }
504
603
 
509
608
        */
510
609
        public boolean sendEvent( int event, boolean state )
511
610
        {
512
 
                if (debug_verbose)
513
 
                        System.out.print("RXTXPort:sendEvent(");
 
611
                if (debug_events)
 
612
                        z.report( "RXTXPort:sendEvent(");
514
613
                /* Let the native side know its time to die */
515
614
 
516
615
                if ( fd == 0 || SPEventListener == null || monThread == null)
521
620
                switch( event )
522
621
                {
523
622
                        case SerialPortEvent.DATA_AVAILABLE:
524
 
                                if( debug_verbose )
525
 
                                        System.out.println( "DATA_AVAILABLE " +
 
623
                                if( debug_events )
 
624
                                        z.reportln( "DATA_AVAILABLE " +
526
625
                                                monThread.Data + ")" );
527
626
                                break;
528
627
                        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
529
 
                                if( debug_verbose )
530
 
                                        System.out.println(
 
628
                                if( debug_events )
 
629
                                        z.reportln( 
531
630
                                                "OUTPUT_BUFFER_EMPTY " +
532
631
                                                monThread.Output + ")" );
533
632
                                break;
534
633
                        case SerialPortEvent.CTS:
535
 
                                if( debug_verbose )
536
 
                                        System.out.println( "CTS " +
 
634
                                if( debug_events )
 
635
                                        z.reportln( "CTS " +
537
636
                                                monThread.CTS + ")" );
538
637
                                break;
539
638
                        case SerialPortEvent.DSR:
540
 
                                if( debug_verbose )
541
 
                                        System.out.println( "DSR " +
 
639
                                if( debug_events )
 
640
                                        z.reportln( "DSR " +
542
641
                                                monThread.Output + ")" );
543
642
                                break;
544
643
                        case SerialPortEvent.RI:
545
 
                                if( debug_verbose )
546
 
                                        System.out.println( "RI " +
 
644
                                if( debug_events )
 
645
                                        z.reportln( "RI " +
547
646
                                                monThread.RI + ")" );
548
647
                                break;
549
648
                        case SerialPortEvent.CD:
550
 
                                if( debug_verbose )
551
 
                                        System.out.println( "CD " +
 
649
                                if( debug_events )
 
650
                                        z.reportln( "CD " +
552
651
                                                monThread.CD + ")" );
553
652
                                break;
554
653
                        case SerialPortEvent.OE:
555
 
                                if( debug_verbose )
556
 
                                        System.out.println( "OE " +
 
654
                                if( debug_events )
 
655
                                        z.reportln( "OE " +
557
656
                                                monThread.OE + ")" );
558
657
                                break;
559
658
                        case SerialPortEvent.PE:
560
 
                                if( debug_verbose )
561
 
                                        System.out.println( "PE " +
 
659
                                if( debug_events )
 
660
                                        z.reportln( "PE " +
562
661
                                                monThread.PE + ")" );
563
662
                                break;
564
663
                        case SerialPortEvent.FE:
565
 
                                if( debug_verbose )
566
 
                                        System.out.println( "FE " +
 
664
                                if( debug_events )
 
665
                                        z.reportln( "FE " +
567
666
                                                monThread.FE + ")" );
568
667
                                break;
569
668
                        case SerialPortEvent.BI:
570
 
                                if( debug_verbose )
571
 
                                        System.out.println( "BI " +
 
669
                                if( debug_events )
 
670
                                        z.reportln( "BI " +
572
671
                                                monThread.BI + ")" );
573
672
                                break;
574
673
                        default:
575
 
                                if( debug_verbose )
576
 
                                        System.out.println( "XXXXXXXXXXXXXX " +
 
674
                                if( debug_events )
 
675
                                        z.reportln( "XXXXXXXXXXXXXX " +
577
676
                                                event + ")" );
578
677
                                break;
579
678
                }
580
 
                if( debug_verbose )
581
 
                        System.out.println( "checking flags " );
 
679
                if( debug_events && debug_verbose )
 
680
                        z.reportln(  "  checking flags " );
582
681
 
583
682
                switch( event )
584
683
                {
613
712
                                if( monThread.BI ) break;
614
713
                                return(false);
615
714
                        default:
616
 
                                System.err.println("unknown event: " + event);
 
715
                                System.err.println( "unknown event: " + event);
617
716
                                return(false);
618
717
                }
619
 
                if( debug_verbose )
620
 
                        System.out.println( "getting event" );
 
718
                if( debug_events && debug_verbose )
 
719
                        z.reportln(  "  getting event" );
621
720
                SerialPortEvent e = new SerialPortEvent(this, event, !state,
622
721
                        state );
623
 
                if( debug_verbose )
624
 
                        System.out.println( "sending event" );
 
722
                if( debug_events && debug_verbose )
 
723
                        z.reportln(  "  sending event" );
625
724
                if(monThreadisInterrupted) 
626
725
                {
627
 
                        if( debug_verbose )
628
 
                                System.out.println( "return" );
 
726
                        if( debug_events )
 
727
                                z.reportln(  "  sendEvent return" );
629
728
                        return(true);
630
729
                }
631
730
                if( SPEventListener != null )
633
732
                        SPEventListener.serialEvent( e );
634
733
                }
635
734
 
636
 
                if( debug_verbose )
637
 
                        System.out.println( "return" );
 
735
                if( debug_events && debug_verbose )
 
736
                        z.reportln(  "  sendEvent return" );
638
737
 
639
738
                if (fd == 0 ||  SPEventListener == null || monThread == null) 
640
739
                {
653
752
        */
654
753
 
655
754
        boolean MonitorThreadLock = true;
656
 
        boolean MonitorThreadCloseLock = true;
657
755
 
658
756
        public void addEventListener(
659
757
                SerialPortEventListener lsnr ) throws TooManyListenersException
663
761
                */
664
762
 
665
763
                if (debug)
666
 
                        System.out.println("RXTXPort:addEventListener()");
 
764
                        z.reportln( "RXTXPort:addEventListener()");
667
765
                if( SPEventListener != null )
 
766
                {
668
767
                        throw new TooManyListenersException();
 
768
                }
669
769
                SPEventListener = lsnr;
670
770
                if( !MonitorThreadAlive )
671
771
                {
676
776
                        MonitorThreadAlive=true;
677
777
                }
678
778
                if (debug)
679
 
                        System.out.println("RXTXPort:Interrupt=false");
 
779
                        z.reportln( "RXTXPort:Interrupt=false");
680
780
        }
681
781
        /**
682
782
        *  Remove the serial port event listener
684
784
        public void removeEventListener()
685
785
        {
686
786
                if (debug)
687
 
                        System.out.println("RXTXPort:removeEventListener()");
 
787
                        z.reportln( "RXTXPort:removeEventListener() called");
688
788
                waitForTheNativeCodeSilly();
689
789
                //if( monThread != null && monThread.isAlive() )
690
790
                if( monThreadisInterrupted == true )
691
791
                {
692
 
                        System.out.println("RXTXPort:removeEventListener() already interrupted");
 
792
                        z.reportln( "   RXTXPort:removeEventListener() already interrupted");
693
793
                        monThread = null;
694
794
                        SPEventListener = null;
695
 
                        Runtime.getRuntime().gc();
696
795
                        return;
697
796
                }
698
797
                else if( monThread != null && monThread.isAlive() )
699
798
                {
700
799
                        if (debug)
701
 
                                System.out.println("RXTXPort:Interrupt=true");
 
800
                                z.reportln( "   RXTXPort:Interrupt=true");
702
801
                        monThreadisInterrupted=true;
703
802
                        /*
704
803
                           Notify all threads in this PID that something is up
705
804
                           They will call back to see if its their thread
706
805
                           using isInterrupted().
707
806
                        */
708
 
                        MonitorThreadCloseLock = true;
709
807
                        if (debug)
710
 
                                System.out.println("RXTXPort:calling interruptEventLoop");
 
808
                                z.reportln( "   RXTXPort:calling interruptEventLoop");
711
809
                        interruptEventLoop( );
712
 
                        if (debug)
713
 
                                System.out.print("RXTXPort:waiting on closelock");
714
 
                        while( MonitorThreadCloseLock )
715
 
                        {
716
 
                                if (debug)
717
 
                                        System.out.print(".");
718
 
                                try {
719
 
                                        Thread.sleep(100);
720
 
                                } catch( Exception e ) {}
721
 
                        }
722
 
                        if (debug)
723
 
                                System.out.println();
724
 
                        if (debug)
725
 
                                System.out.println("RXTXPort:calling monThread.join()");
 
810
                        
 
811
                        if (debug)
 
812
                                z.reportln( "   RXTXPort:calling monThread.join()");
726
813
                        try {
727
814
                                monThread.join(1000);
728
815
                        } catch (Exception ex) {
730
817
                                ex.printStackTrace();
731
818
                        }
732
819
                        if (debug)
733
 
                                System.out.println("RXTXPort:waiting on isAlive()");
 
820
                                z.reportln( "   RXTXPort:waiting on isAlive()");
734
821
                        while( monThread.isAlive() )
735
822
                        {
736
823
                                if ( debug )
737
 
                                        System.out.println("MonThread is still alive!");
 
824
                                        z.reportln( "   MonThread is still alive!");
738
825
                                try {
739
826
                                        monThread.join(1000);
740
827
                                        Thread.sleep( 1000 );
741
828
                                } catch( Exception e ){} 
742
 
                                monThread.stop();
 
829
                                //monThread.stop();
743
830
                        }
744
831
                        
745
832
                }
746
833
                if (debug)
747
 
                        System.out.println("RXTXPort:calling gc()");
 
834
                        z.reportln( "   RXTXPort:calling gc()");
748
835
                monThread = null;
749
836
                SPEventListener = null;
750
 
                Runtime.getRuntime().gc();
751
837
                MonitorThreadLock = false;
752
838
                MonitorThreadAlive=false;
 
839
                monThreadisInterrupted=true;
 
840
                z.reportln( "RXTXPort:removeEventListener() returning");
753
841
        }
754
842
        /**
755
843
         *      Give the native code a chance to start listening to the hardware
765
853
                while( MonitorThreadLock )
766
854
                {
767
855
                        try {
768
 
                                Thread.sleep(100);
 
856
                                Thread.sleep(5);
769
857
                        } catch( Exception e ) {}
770
858
                }
771
859
        }
777
865
        public void notifyOnDataAvailable( boolean enable )
778
866
        {
779
867
                if (debug)
780
 
                        System.out.println("RXTXPort:notifyOnDataAvailable( " +
 
868
                        z.reportln( "RXTXPort:notifyOnDataAvailable( " +
781
869
                                enable+" )");
782
870
                
783
871
                waitForTheNativeCodeSilly();
795
883
        public void notifyOnOutputEmpty( boolean enable )
796
884
        {
797
885
                if (debug)
798
 
                        System.out.println("RXTXPort:notifyOnOutputEmpty( " +
 
886
                        z.reportln( "RXTXPort:notifyOnOutputEmpty( " +
799
887
                                enable+" )");
800
888
                waitForTheNativeCodeSilly();
801
889
                MonitorThreadLock = true;
811
899
        public void notifyOnCTS( boolean enable )
812
900
        {
813
901
                if (debug)
814
 
                        System.out.println("RXTXPort:notifyOnCTS( " +
 
902
                        z.reportln( "RXTXPort:notifyOnCTS( " +
815
903
                                enable+" )");
816
904
                waitForTheNativeCodeSilly();
817
905
                MonitorThreadLock = true;
825
913
        public void notifyOnDSR( boolean enable )
826
914
        {
827
915
                if (debug)
828
 
                        System.out.println("RXTXPort:notifyOnDSR( " +
 
916
                        z.reportln( "RXTXPort:notifyOnDSR( " +
829
917
                                enable+" )");
830
918
                waitForTheNativeCodeSilly();
831
919
                MonitorThreadLock = true;
839
927
        public void notifyOnRingIndicator( boolean enable )
840
928
        {
841
929
                if (debug)
842
 
                        System.out.println("RXTXPort:notifyOnRingIndicator( " +
 
930
                        z.reportln( "RXTXPort:notifyOnRingIndicator( " +
843
931
                                enable+" )");
844
932
                waitForTheNativeCodeSilly();
845
933
                MonitorThreadLock = true;
853
941
        public void notifyOnCarrierDetect( boolean enable )
854
942
        {
855
943
                if (debug)
856
 
                        System.out.println("RXTXPort:notifyOnCarrierDetect( " +
 
944
                        z.reportln( "RXTXPort:notifyOnCarrierDetect( " +
857
945
                                enable+" )");
858
946
                waitForTheNativeCodeSilly();
859
947
                MonitorThreadLock = true;
867
955
        public void notifyOnOverrunError( boolean enable )
868
956
        {
869
957
                if (debug)
870
 
                        System.out.println("RXTXPort:notifyOnOverrunError( " +
 
958
                        z.reportln( "RXTXPort:notifyOnOverrunError( " +
871
959
                                enable+" )");
872
960
                waitForTheNativeCodeSilly();
873
961
                MonitorThreadLock = true;
881
969
        public void notifyOnParityError( boolean enable )
882
970
        {
883
971
                if (debug)
884
 
                        System.out.println("RXTXPort:notifyOnParityError( " +
 
972
                        z.reportln( "RXTXPort:notifyOnParityError( " +
885
973
                                enable+" )");
886
974
                waitForTheNativeCodeSilly();
887
975
                MonitorThreadLock = true;
895
983
        public void notifyOnFramingError( boolean enable )
896
984
        {
897
985
                if (debug)
898
 
                        System.out.println("RXTXPort:notifyOnFramingError( " +
 
986
                        z.reportln( "RXTXPort:notifyOnFramingError( " +
899
987
                                enable+" )");
900
988
                waitForTheNativeCodeSilly();
901
989
                MonitorThreadLock = true;
909
997
        public void notifyOnBreakInterrupt( boolean enable )
910
998
        {
911
999
                if (debug)
912
 
                        System.out.println("RXTXPort:notifyOnBreakInterrupt( " +
 
1000
                        z.reportln( "RXTXPort:notifyOnBreakInterrupt( " +
913
1001
                                enable+" )");
914
1002
                waitForTheNativeCodeSilly();
915
1003
                MonitorThreadLock = true;
926
1014
        public synchronized void close()
927
1015
        {
928
1016
                if (debug)
929
 
                        System.out.println("RXTXPort:close( " + this.name + " )"); 
 
1017
                        z.reportln( "RXTXPort:close( " + this.name + " )"); 
930
1018
                if( closeLock ) return;
931
1019
                closeLock = true;
 
1020
                while( IOLocked > 0 )
 
1021
                {
 
1022
                        if( debug )
 
1023
                                z.reportln("IO is locked " + IOLocked);
 
1024
                        try {
 
1025
                                Thread.sleep(500);
 
1026
                        } catch( Exception e ) {}
 
1027
                }
932
1028
                if ( fd <= 0 )
933
1029
                {
934
 
                        System.out.println( "RXTXPort:close detected bad File Descriptor" );
 
1030
                        z.reportln(  "RXTXPort:close detected bad File Descriptor" );
935
1031
                        return;
936
1032
                }
937
1033
                setDTR(false);
938
1034
                setDSR(false);
939
1035
                if (debug)
940
 
                        System.out.println("RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
 
1036
                        z.reportln( "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
941
1037
                if ( ! monThreadisInterrupted )
942
1038
                {
943
1039
                        removeEventListener();
944
1040
                }
945
1041
                if (debug)
946
 
                        System.out.println("RXTXPort:close( " + this.name + " ) calling nativeClose"); 
 
1042
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling nativeClose"); 
947
1043
                nativeClose( this.name );
948
1044
                if (debug)
949
 
                        System.out.println("RXTXPort:close( " + this.name + " ) calling super.close"); 
 
1045
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling super.close"); 
950
1046
                super.close();
951
 
                if (debug)
952
 
                        System.out.println("RXTXPort:close( " + this.name + " ) calling System.gc"); 
953
 
 
954
1047
                fd = 0;
955
 
                Runtime.getRuntime().gc();
956
1048
                closeLock = false;
957
1049
                if (debug)
958
 
                        System.out.println("RXTXPort:close( " + this.name + " ) leaving"); 
 
1050
                        z.reportln( "RXTXPort:close( " + this.name + " ) leaving"); 
959
1051
        }
960
1052
 
961
1053
 
963
1055
        protected void finalize()
964
1056
        {
965
1057
                if (debug)
966
 
                        System.out.println("RXTXPort:finalize()");
967
 
                if( fd > 0 ) close();
 
1058
                        z.reportln( "RXTXPort:finalize()");
 
1059
                if( fd > 0 )
 
1060
                {
 
1061
                        if (debug)
 
1062
                                z.reportln( "RXTXPort:calling close()");
 
1063
                        close();
 
1064
                }
 
1065
                z.finalize();
968
1066
        }
969
1067
 
970
1068
        /** Inner class for SerialOutputStream */
976
1074
        */
977
1075
                public void write( int b ) throws IOException
978
1076
                {
979
 
                        if (debug_verbose)
980
 
                                System.out.println("RXTXPort:SerialOutputStream:write(int)");
 
1077
                        if (debug_write)
 
1078
                                z.reportln( "RXTXPort:SerialOutputStream:write(int)");
 
1079
                        if( speed == 0 ) return;
981
1080
                        if ( monThreadisInterrupted == true )
982
1081
                        {
983
 
                                throw new IOException( "Port has been Closed" );
 
1082
                                return;
984
1083
                        }
 
1084
                        IOLocked++;
985
1085
                        waitForTheNativeCodeSilly();
986
 
                        if ( fd == 0 ) throw new IOException();
987
 
                        writeByte( b );
 
1086
                        if ( fd == 0 )
 
1087
                        {
 
1088
                                IOLocked--;
 
1089
                                throw new IOException();
 
1090
                        }
 
1091
                        try
 
1092
                        {
 
1093
                                writeByte( b, monThreadisInterrupted );
 
1094
                                if (debug_write)
 
1095
                                        z.reportln( "Leaving RXTXPort:SerialOutputStream:write( int )");
 
1096
                        }
 
1097
                        catch( IOException e )
 
1098
                        {
 
1099
                                IOLocked--;
 
1100
                                throw e;
 
1101
                        }
 
1102
                        IOLocked--;
988
1103
                }
989
1104
        /**
990
1105
        *  @param b[]
992
1107
        */
993
1108
                public void write( byte b[] ) throws IOException
994
1109
                {
995
 
                        if (debug_verbose)
 
1110
                        if (debug_write)
996
1111
                        {
997
 
                                System.out.println("Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
 
1112
                                z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
998
1113
                        }
 
1114
                        if( speed == 0 ) return;
999
1115
                        if ( monThreadisInterrupted == true )
1000
1116
                        {
1001
 
                                throw new IOException( "Port has been Closed" );
 
1117
                                return;
1002
1118
                        }
1003
1119
                        if ( fd == 0 ) throw new IOException();
 
1120
                        IOLocked++;
1004
1121
                        waitForTheNativeCodeSilly();
1005
 
                        writeArray( b, 0, b.length );
1006
 
                        if (debug)
1007
 
                                System.out.println("Leaving RXTXPort:SerialOutputStream:write(" +b.length  +")");
 
1122
                        try
 
1123
                        {
 
1124
                                writeArray( b, 0, b.length, monThreadisInterrupted );
 
1125
                                if (debug_write)
 
1126
                                        z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" +b.length  +")");
 
1127
                        }
 
1128
                        catch( IOException e )
 
1129
                        {
 
1130
                                IOLocked--;
 
1131
                                throw e;
 
1132
                        }
 
1133
                        IOLocked--;
 
1134
                        
1008
1135
                }
1009
1136
        /**
1010
1137
        *  @param b[]
1015
1142
                public void write( byte b[], int off, int len )
1016
1143
                        throws IOException
1017
1144
                {
 
1145
                        if( speed == 0 ) return;
1018
1146
                        if( off + len  > b.length )
1019
1147
                        {
1020
1148
                                throw new IndexOutOfBoundsException(
1021
1149
                                        "Invalid offset/length passed to read"
1022
1150
                                );
1023
1151
                        }
1024
 
 
 
1152
         
1025
1153
                        byte send[] = new byte[len];
1026
1154
                        System.arraycopy( b, off, send, 0, len );
1027
 
                        if (debug_verbose)
 
1155
                        if (debug_write)
1028
1156
                        {
1029
 
                                System.out.println("Entering RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+  new String(send) */ );
 
1157
                                z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+  new String(send) */ );
1030
1158
                        }
1031
1159
                        if ( fd == 0 ) throw new IOException();
1032
1160
                        if ( monThreadisInterrupted == true )
1033
1161
                        {
1034
 
                                throw new IOException( "Port has been Closed" );
 
1162
                                return;
1035
1163
                        }
 
1164
                        IOLocked++;
1036
1165
                        waitForTheNativeCodeSilly();
1037
 
                        writeArray( send, 0, len );
1038
 
                        if( debug )
1039
 
                                System.out.println("Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") "  /*+ new String(send)*/ );
 
1166
                        try
 
1167
                        {
 
1168
                                writeArray( send, 0, len, monThreadisInterrupted );
 
1169
                                if( debug_write )
 
1170
                                        z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") "  /*+ new String(send)*/ );
 
1171
                        }
 
1172
                        catch( IOException e )
 
1173
                        {
 
1174
                                IOLocked--;
 
1175
                                throw e;
 
1176
                        }
 
1177
                        IOLocked--;
1040
1178
                }
1041
1179
        /**
1042
1180
        */
1043
1181
                public void flush() throws IOException
1044
1182
                {
1045
1183
                        if (debug)
1046
 
                                System.out.println("RXTXPort:SerialOutputStream:flush() enter");
 
1184
                                z.reportln( "RXTXPort:SerialOutputStream:flush() enter");
 
1185
                        if( speed == 0 ) return;
1047
1186
                        if ( fd == 0 ) throw new IOException();
1048
1187
                        if ( monThreadisInterrupted == true )
1049
1188
                        {
 
1189
                        if (debug)
 
1190
                                z.reportln( "RXTXPort:SerialOutputStream:flush() Leaving Interrupted");
1050
1191
                                return;
1051
 
                                /* FIXME Trent this breaks
1052
 
                                        InstrumentControlSerialPort = hGetPort
1053
 
                                        in Matlab.
1054
 
                                */
1055
 
                                //throw new IOException( "flush() Port has been Closed" );
1056
1192
                        }
 
1193
                        IOLocked++;
1057
1194
                        waitForTheNativeCodeSilly();
1058
 
                        nativeDrain();
1059
 
                        if (debug)
1060
 
                                System.out.println("RXTXPort:SerialOutputStream:flush() leave");
 
1195
                        /* 
 
1196
                           this is probably good on all OS's but for now
 
1197
                           just sendEvent from java on Sol
 
1198
                        */
 
1199
                        try
 
1200
                        {
 
1201
                                if ( nativeDrain( monThreadisInterrupted ) )
 
1202
                                        sendEvent( SerialPortEvent.OUTPUT_BUFFER_EMPTY, true );
 
1203
                                if (debug)
 
1204
                                        z.reportln( "RXTXPort:SerialOutputStream:flush() leave");
 
1205
                        }
 
1206
                        catch( IOException e )
 
1207
                        {
 
1208
                                IOLocked--;
 
1209
                                throw e;
 
1210
                        }
 
1211
                        IOLocked--;
1061
1212
                }
1062
1213
        }
1063
1214
 
1068
1219
        *  @return int the int read
1069
1220
        *  @throws IOException
1070
1221
        *  @see java.io.InputStream
 
1222
*
 
1223
*timeout threshold       Behavior
 
1224
*------------------------------------------------------------------------
 
1225
*0       0       blocks until 1 byte is available timeout > 0,
 
1226
*                threshold = 0, blocks until timeout occurs, returns -1
 
1227
*                on timeout
 
1228
*>0      >0      blocks until timeout, returns - 1 on timeout, magnitude
 
1229
*                of threshold doesn't play a role.
 
1230
*0       >0      Blocks until 1 byte, magnitude of  threshold doesn't
 
1231
*                play a role
1071
1232
        */
1072
 
                public int read() throws IOException
 
1233
                public synchronized int read() throws IOException
1073
1234
                {
1074
 
                        if (debug_verbose)
1075
 
                                System.out.println("RXTXPort:SerialInputStream:read()");
1076
 
                        if ( monThreadisInterrupted ) return( -1 ) ;
 
1235
                        if (debug_read)
 
1236
                                z.reportln( "RXTXPort:SerialInputStream:read() called");
1077
1237
                        if ( fd == 0 ) throw new IOException();
1078
 
                        if ( monThreadisInterrupted == true )
 
1238
                        if ( monThreadisInterrupted )
1079
1239
                        {
1080
 
                                throw new IOException( "Port has been Closed" );
 
1240
                                z.reportln( "+++++++++ read() monThreadisInterrupted" );
1081
1241
                        }
 
1242
                        IOLocked++;
 
1243
                        if (debug_read_results)
 
1244
                                z.reportln(  "RXTXPort:SerialInputStream:read() L" );
1082
1245
                        waitForTheNativeCodeSilly();
1083
 
                        int result = readByte();
1084
 
                        if (debug)
1085
 
                                System.out.println( "readByte= " + result );
1086
 
                        return( result );
 
1246
                        if (debug_read_results)
 
1247
                                z.reportln(  "RXTXPort:SerialInputStream:read() N" );
 
1248
                        try
 
1249
                        {
 
1250
                                int result = readByte();
 
1251
                                if (debug_read_results)
 
1252
                                        //z.reportln(  "RXTXPort:SerialInputStream:read() returns byte = " + result );
 
1253
                                        z.reportln(  "RXTXPort:SerialInputStream:read() returns" );
 
1254
                                return( result );
 
1255
                        }                               
 
1256
                        finally
 
1257
                        {
 
1258
                                IOLocked--;
 
1259
                        }
1087
1260
                }
1088
1261
        /**
1089
1262
        *  @param b[]
1090
1263
        *  @return int  number of bytes read
1091
1264
        *  @throws IOException
 
1265
*
 
1266
*timeout threshold       Behavior
 
1267
*------------------------------------------------------------------------
 
1268
*0       0       blocks until 1 byte is available
 
1269
*>0      0       blocks until timeout occurs, returns 0 on timeout
 
1270
*>0      >0      blocks until timeout or reads threshold bytes,
 
1271
                 returns 0 on timeout
 
1272
*0       >0      blocks until reads threshold bytes
1092
1273
        */
1093
 
                public int read( byte b[] ) throws IOException
 
1274
                public synchronized int read( byte b[] ) throws IOException
1094
1275
                {
1095
1276
                        int result;
1096
 
                        if (debug_verbose)
1097
 
                                System.out.println("RXTXPort:SerialInputStream:read(" + b.length + ")");
 
1277
                        if (debug_read)
 
1278
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + ") called");
1098
1279
                        if ( monThreadisInterrupted == true )
1099
1280
                        {
1100
 
                                throw new IOException( "Port has been Closed" );
 
1281
                                return(0);
1101
1282
                        }
 
1283
                        IOLocked++;
1102
1284
                        waitForTheNativeCodeSilly();
1103
 
                        result = read( b, 0, b.length);
1104
 
                        if (debug)
1105
 
                                System.out.println( "read = " + result );
1106
 
                        return( result );
 
1285
                        try
 
1286
                        {
 
1287
                                result = read( b, 0, b.length);
 
1288
                                if (debug_read_results)
 
1289
                                        z.reportln(  "RXTXPort:SerialInputStream:read() returned " + result + " bytes" );
 
1290
                                return( result );
 
1291
                        }
 
1292
                        finally
 
1293
                        {
 
1294
                                IOLocked--;
 
1295
                        }
1107
1296
                }
1108
1297
/*
1109
1298
read(byte b[], int, int)
1115
1304
        *  @param len
1116
1305
        *  @return int  number of bytes read
1117
1306
        *  @throws IOException
1118
 
        */
1119
 
                public int read( byte b[], int off, int len )
1120
 
                        throws IOException
1121
 
                {
1122
 
                        if (debug_verbose)
1123
 
                                System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") " /*+ new String(b) */ );
1124
 
                        int result;
1125
 
                        /*
1126
 
                         * Some sanity checks
1127
 
                         */
1128
 
                        if ( fd == 0 ) throw new IOException();
1129
 
 
1130
 
                        if( b==null )
1131
 
                                throw new NullPointerException();
1132
 
 
1133
 
                        if( (off < 0) || (len < 0) || (off+len > b.length))
1134
 
                                throw new IndexOutOfBoundsException();
1135
 
 
1136
 
                        /*
1137
 
                         * Return immediately if len==0
1138
 
                         */
1139
 
                        if( len==0 ) return 0;
1140
 
 
1141
 
                        /*
1142
 
                         * See how many bytes we should read
1143
 
                         */
1144
 
                        int Minimum = len;
1145
 
 
1146
 
                        if( threshold==0 )
1147
 
                        {
1148
 
                        /*
1149
 
                         * If threshold is disabled, read should return as soon
1150
 
                         * as data are available (up to the amount of available
1151
 
                         * bytes in order to avoid blocking)
1152
 
                         * Read may return earlier depending of the receive time
1153
 
                         * out.
1154
 
                         */
1155
 
                                if( available()==0 )
1156
 
                                        Minimum = 1;
1157
 
                                else
1158
 
                                        Minimum = Math.min(Minimum,available());
1159
 
                        }
1160
 
                        else
1161
 
                        {
1162
 
                        /*
1163
 
                         * Threshold is enabled. Read should return when
1164
 
                         * 'threshold' bytes have been received (or when the
1165
 
                         * receive timeout expired)
1166
 
                         */
1167
 
                                Minimum = Math.min(Minimum, threshold);
1168
 
                        }
1169
 
                        if ( monThreadisInterrupted == true )
1170
 
                        {
1171
 
                                throw new IOException( "Port has been Closed" );
1172
 
                        }
1173
 
                        waitForTheNativeCodeSilly();
1174
 
                        result = readArray( b, off, Minimum);
1175
 
                        if (debug)
1176
 
                                System.out.println("RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") = " + result + " bytes containing "  /*+ new String(b) */);
1177
 
                        return( result );
 
1307
*
 
1308
*timeout threshold       Behavior
 
1309
*------------------------------------------------------------------------
 
1310
*0       0       blocks until 1 byte is available
 
1311
*>0      0       blocks until timeout occurs, returns 0 on timeout
 
1312
*>0      >0      blocks until timeout or reads threshold bytes,
 
1313
                 returns 0 on timeout
 
1314
*0       >0      blocks until either threshold # of bytes or len bytes,
 
1315
                 whichever was lower.
 
1316
        */
 
1317
                public synchronized int read( byte b[], int off, int len )
 
1318
                        throws IOException
 
1319
                {
 
1320
                        if (debug_read)
 
1321
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
 
1322
                        int result;
 
1323
                        /*
 
1324
                         * Some sanity checks
 
1325
                         */
 
1326
                        if ( fd == 0 )
 
1327
                        {
 
1328
                                if (debug_read)
 
1329
                                        z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
 
1330
                                z.reportln("+++++++ IOException()\n");
 
1331
                                throw new IOException();
 
1332
                        }
 
1333
 
 
1334
                        if( b==null )
 
1335
                        {
 
1336
                                z.reportln("+++++++ NullPointerException()\n");
 
1337
                                if (debug_read)
 
1338
                                        z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
 
1339
                                throw new NullPointerException();
 
1340
                        }
 
1341
 
 
1342
                        if( (off < 0) || (len < 0) || (off+len > b.length))
 
1343
                        {
 
1344
                                z.reportln("+++++++ IndexOutOfBoundsException()\n");
 
1345
                                if (debug_read)
 
1346
                                        z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
 
1347
                                throw new IndexOutOfBoundsException();
 
1348
                        }
 
1349
 
 
1350
                        /*
 
1351
                         * Return immediately if len==0
 
1352
                         */
 
1353
                        if( len==0 )
 
1354
                        {
 
1355
                                if (debug_read)
 
1356
                                        z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
 
1357
                                return 0;
 
1358
                        }
 
1359
                        /*
 
1360
                         * See how many bytes we should read
 
1361
                         */
 
1362
                        int Minimum = len;
 
1363
 
 
1364
                        if( threshold==0 )
 
1365
                        {
 
1366
                        /*
 
1367
                         * If threshold is disabled, read should return as soon
 
1368
                         * as data are available (up to the amount of available
 
1369
                         * bytes in order to avoid blocking)
 
1370
                         * Read may return earlier depending of the receive time
 
1371
                         * out.
 
1372
                         */
 
1373
                                int a = nativeavailable();
 
1374
                                if( a == 0 )
 
1375
                                        Minimum = 1;
 
1376
                                else
 
1377
                                        Minimum = Math.min( Minimum, a );
 
1378
                        }
 
1379
                        else
 
1380
                        {
 
1381
                        /*
 
1382
                         * Threshold is enabled. Read should return when
 
1383
                         * 'threshold' bytes have been received (or when the
 
1384
                         * receive timeout expired)
 
1385
                         */
 
1386
                                Minimum = Math.min(Minimum, threshold);
 
1387
                        }
 
1388
                        if ( monThreadisInterrupted == true )
 
1389
                        {
 
1390
                                if (debug_read)
 
1391
                                        z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
 
1392
                                return(0);
 
1393
                        }
 
1394
                        IOLocked++;
 
1395
                        waitForTheNativeCodeSilly();
 
1396
                        try
 
1397
                        {
 
1398
                                result = readArray( b, off, Minimum);
 
1399
                                if (debug_read_results)
 
1400
                                        z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
 
1401
                                return( result );
 
1402
                        }
 
1403
                        finally
 
1404
                        {
 
1405
                                IOLocked--;
 
1406
                        }
 
1407
                }
 
1408
 
 
1409
        /**
 
1410
        *  @param b[]
 
1411
        *  @param off
 
1412
        *  @param len
 
1413
        *  @param t[]
 
1414
        *  @return int  number of bytes read
 
1415
        *  @throws IOException
 
1416
 
 
1417
           We are trying to catch the terminator in the native code
 
1418
           Right now it is assumed that t[] is an array of 2 bytes.
 
1419
        
 
1420
           if the read encounters the two bytes, it will return and the
 
1421
           array will contain the terminator.  Otherwise read behavior should
 
1422
           be the same as read( b[], off, len ).  Timeouts have not been well
 
1423
           tested.
 
1424
        */
 
1425
 
 
1426
                public synchronized int read( byte b[], int off, int len, byte t[] )
 
1427
                        throws IOException
 
1428
                {
 
1429
                        if (debug_read)
 
1430
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
 
1431
                        int result;
 
1432
                        /*
 
1433
                         * Some sanity checks
 
1434
                         */
 
1435
                        if ( fd == 0 )
 
1436
                        {
 
1437
                                if (debug_read)
 
1438
                                        z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
 
1439
                                z.reportln("+++++++ IOException()\n");
 
1440
                                throw new IOException();
 
1441
                        }
 
1442
 
 
1443
                        if( b==null )
 
1444
                        {
 
1445
                                z.reportln("+++++++ NullPointerException()\n");
 
1446
                                if (debug_read)
 
1447
                                        z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
 
1448
                                throw new NullPointerException();
 
1449
                        }
 
1450
 
 
1451
                        if( (off < 0) || (len < 0) || (off+len > b.length))
 
1452
                        {
 
1453
                                z.reportln("+++++++ IndexOutOfBoundsException()\n");
 
1454
                                if (debug_read)
 
1455
                                        z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
 
1456
                                throw new IndexOutOfBoundsException();
 
1457
                        }
 
1458
 
 
1459
                        /*
 
1460
                         * Return immediately if len==0
 
1461
                         */
 
1462
                        if( len==0 )
 
1463
                        {
 
1464
                                if (debug_read)
 
1465
                                        z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
 
1466
                                return 0;
 
1467
                        }
 
1468
                        /*
 
1469
                         * See how many bytes we should read
 
1470
                         */
 
1471
                        int Minimum = len;
 
1472
 
 
1473
                        if( threshold==0 )
 
1474
                        {
 
1475
                        /*
 
1476
                         * If threshold is disabled, read should return as soon
 
1477
                         * as data are available (up to the amount of available
 
1478
                         * bytes in order to avoid blocking)
 
1479
                         * Read may return earlier depending of the receive time
 
1480
                         * out.
 
1481
                         */
 
1482
                                int a = nativeavailable();
 
1483
                                if( a == 0 )
 
1484
                                        Minimum = 1;
 
1485
                                else
 
1486
                                        Minimum = Math.min( Minimum, a );
 
1487
                        }
 
1488
                        else
 
1489
                        {
 
1490
                        /*
 
1491
                         * Threshold is enabled. Read should return when
 
1492
                         * 'threshold' bytes have been received (or when the
 
1493
                         * receive timeout expired)
 
1494
                         */
 
1495
                                Minimum = Math.min(Minimum, threshold);
 
1496
                        }
 
1497
                        if ( monThreadisInterrupted == true )
 
1498
                        {
 
1499
                                if (debug_read)
 
1500
                                        z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
 
1501
                                return(0);
 
1502
                        }
 
1503
                        IOLocked++;
 
1504
                        waitForTheNativeCodeSilly();
 
1505
                        try
 
1506
                        {
 
1507
                                result = readTerminatedArray( b, off, Minimum, t );
 
1508
                                if (debug_read_results)
 
1509
                                        z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
 
1510
                                return( result );
 
1511
                        }
 
1512
                        finally
 
1513
                        {
 
1514
                                IOLocked--;
 
1515
                        }
1178
1516
                }
1179
1517
        /**
1180
1518
        *  @return int bytes available
1181
1519
        *  @throws IOException
1182
1520
        */
1183
 
                public int available() throws IOException
 
1521
                public synchronized int available() throws IOException
1184
1522
                {
1185
1523
                        if ( monThreadisInterrupted == true )
1186
1524
                        {
1187
 
                                throw new IOException( "Port has been Closed" );
1188
 
                        }
1189
 
                        int r = nativeavailable();
1190
 
                        if ( debug_verbose && r > 0 )
1191
 
                                System.out.println("available() returning " +
1192
 
                                        r );
1193
 
                        return r;
 
1525
                                return(0);
 
1526
                        }
 
1527
                        if ( debug_verbose )
 
1528
                                z.reportln( "RXTXPort:available() called" );
 
1529
                        IOLocked++;
 
1530
                        try
 
1531
                        {
 
1532
                                int r = nativeavailable();
 
1533
                                if ( debug_verbose )
 
1534
                                        z.reportln( "RXTXPort:available() returning " +
 
1535
                                                r );
 
1536
                                return r;
 
1537
                        }
 
1538
                        finally
 
1539
                        {
 
1540
                                IOLocked--;
 
1541
                        }
1194
1542
                }
1195
1543
        }
1196
1544
        /**
1214
1562
                MonitorThread() 
1215
1563
                {
1216
1564
                        if (debug)
1217
 
                                System.out.println("RXTXPort:MontitorThread:MonitorThread()"); 
 
1565
                                z.reportln( "RXTXPort:MontitorThread:MonitorThread()"); 
1218
1566
                }
1219
1567
        /**
1220
1568
        *  run the thread and call the event loop.
1222
1570
                public void run()
1223
1571
                {
1224
1572
                        if (debug)
1225
 
                                System.out.println("RXTXPort:MontitorThread:run()"); 
 
1573
                                z.reportln( "RXTXPort:MontitorThread:run()"); 
1226
1574
                        monThreadisInterrupted=false;
1227
1575
                        eventLoop();
1228
 
 
1229
1576
                        if (debug)
1230
 
                                System.out.println("eventLoop() returned"); 
 
1577
                                z.reportln( "eventLoop() returned"); 
1231
1578
                }
1232
1579
                protected void finalize() throws Throwable 
1233
1580
                { 
1234
1581
                        if (debug)
1235
 
                                System.out.println("MonitorThread finalizing"); 
 
1582
                                z.reportln( "RXTXPort:MonitorThread exiting"); 
1236
1583
                }
1237
1584
        }
1238
1585
        /**
1307
1654
                throws UnsupportedCommOperationException;
1308
1655
        private native boolean nativeGetCallOutHangup()
1309
1656
                throws UnsupportedCommOperationException;
 
1657
        private native boolean nativeClearCommInput()
 
1658
                throws UnsupportedCommOperationException;
1310
1659
 
1311
1660
        /**
1312
1661
        *  Extension to CommAPI
1318
1667
        *  @param  port the name of the port thats been preopened
1319
1668
        *  @return BaudRate on success
1320
1669
        *  @throws UnsupportedCommOperationException;
 
1670
        *  This will not behave as expected with custom speeds
1321
1671
        *
1322
1672
        */
1323
1673
        public static int staticGetBaudRate( String port )
1324
1674
                throws UnsupportedCommOperationException
1325
1675
        {
1326
1676
                if ( debug )
1327
 
                        System.out.println(
 
1677
                        z.reportln( 
1328
1678
                                "RXTXPort:staticGetBaudRate( " + port + " )");
1329
1679
                return(nativeStaticGetBaudRate( port ));
1330
1680
        }
1342
1692
                throws UnsupportedCommOperationException
1343
1693
        {
1344
1694
                if ( debug )
1345
 
                        System.out.println(
 
1695
                        z.reportln( 
1346
1696
                                "RXTXPort:staticGetDataBits( " + port + " )");
1347
1697
                return(nativeStaticGetDataBits( port ) );
1348
1698
        }
1361
1711
                throws UnsupportedCommOperationException
1362
1712
        {
1363
1713
                if ( debug )
1364
 
                        System.out.println(
 
1714
                        z.reportln( 
1365
1715
                                "RXTXPort:staticGetParity( " + port + " )");
1366
1716
                return( nativeStaticGetParity( port ) );
1367
1717
        }
1380
1730
                throws UnsupportedCommOperationException
1381
1731
        {
1382
1732
                if ( debug )
1383
 
                        System.out.println(
 
1733
                        z.reportln( 
1384
1734
                                "RXTXPort:staticGetStopBits( " + port + " )");
1385
1735
                        return(nativeStaticGetStopBits( port ) );
1386
1736
        }
1407
1757
                throws UnsupportedCommOperationException
1408
1758
        {
1409
1759
                if ( debug )
1410
 
                        System.out.println(
 
1760
                        z.reportln( 
1411
1761
                                "RXTXPort:staticSetSerialPortParams( " +
1412
1762
                                f + " " + b + " " + d + " " + s + " " + p );
1413
1763
                nativeStaticSetSerialPortParams( f, b, d, s, p );
1431
1781
                throws UnsupportedCommOperationException
1432
1782
        {
1433
1783
                if ( debug )
1434
 
                        System.out.println( "RXTXPort:staticSetDSR( " + port +
 
1784
                        z.reportln(  "RXTXPort:staticSetDSR( " + port +
1435
1785
                                                " " + flag );
1436
1786
                return( nativeStaticSetDSR( port, flag ) );
1437
1787
        }
1454
1804
                throws UnsupportedCommOperationException
1455
1805
        {
1456
1806
                if ( debug )
1457
 
                        System.out.println( "RXTXPort:staticSetDTR( " + port +
 
1807
                        z.reportln(  "RXTXPort:staticSetDTR( " + port +
1458
1808
                                                " " + flag );
1459
1809
                return( nativeStaticSetDTR( port, flag ) );
1460
1810
        }
1477
1827
                throws UnsupportedCommOperationException
1478
1828
        {
1479
1829
                if ( debug )
1480
 
                        System.out.println( "RXTXPort:staticSetRTS( " + port +
 
1830
                        z.reportln(  "RXTXPort:staticSetRTS( " + port +
1481
1831
                                                " " + flag );
1482
1832
                return( nativeStaticSetRTS( port, flag ) );
1483
1833
        }
1499
1849
                throws UnsupportedCommOperationException
1500
1850
        {
1501
1851
                if ( debug )
1502
 
                        System.out.println( "RXTXPort:staticIsRTS( " + port + " )" );
 
1852
                        z.reportln(  "RXTXPort:staticIsRTS( " + port + " )" );
1503
1853
                return( nativeStaticIsRTS( port ) );
1504
1854
        }
1505
1855
        /**
1519
1869
                throws UnsupportedCommOperationException
1520
1870
        {
1521
1871
                if ( debug )
1522
 
                        System.out.println( "RXTXPort:staticIsCD( " + port + " )" );
 
1872
                        z.reportln( "RXTXPort:staticIsCD( " + port + " )" );
1523
1873
                return( nativeStaticIsCD( port ) );
1524
1874
        }
1525
1875
        /**
1539
1889
                throws UnsupportedCommOperationException
1540
1890
        {
1541
1891
                if ( debug )
1542
 
                        System.out.println( "RXTXPort:staticIsCTS( " + port + " )" );
 
1892
                        z.reportln(  "RXTXPort:staticIsCTS( " + port + " )" );
1543
1893
                return( nativeStaticIsCTS( port ) );
1544
1894
        }
1545
1895
        /**
1559
1909
                throws UnsupportedCommOperationException
1560
1910
        {
1561
1911
                if ( debug )
1562
 
                        System.out.println( "RXTXPort:staticIsDSR( " + port + " )" );
 
1912
                        z.reportln(  "RXTXPort:staticIsDSR( " + port + " )" );
1563
1913
                return( nativeStaticIsDSR( port ) );
1564
1914
        }
1565
1915
        /**
1579
1929
                throws UnsupportedCommOperationException
1580
1930
        {
1581
1931
                if ( debug )
1582
 
                        System.out.println( "RXTXPort:staticIsDTR( " + port + " )" );
 
1932
                        z.reportln(  "RXTXPort:staticIsDTR( " + port + " )" );
1583
1933
                return( nativeStaticIsDTR( port ) );
1584
1934
        }
1585
1935
        /**
1599
1949
                throws UnsupportedCommOperationException
1600
1950
        {
1601
1951
                if ( debug )
1602
 
                        System.out.println( "RXTXPort:staticIsRI( " + port + " )" );
 
1952
                        z.reportln(  "RXTXPort:staticIsRI( " + port + " )" );
1603
1953
                return( nativeStaticIsRI( port ) );
1604
1954
        }
1605
1955
 
1619
1969
        {
1620
1970
                byte ret;
1621
1971
                if ( debug )
1622
 
                        System.out.println( "getParityErrorChar()" );
 
1972
                        z.reportln(  "getParityErrorChar()" );
1623
1973
                ret = nativeGetParityErrorChar();
1624
1974
                if ( debug )
1625
 
                        System.out.println( "getParityErrorChar() returns " +
 
1975
                        z.reportln(  "getParityErrorChar() returns " +
1626
1976
                                                ret );
1627
1977
                return( ret );
1628
1978
        }
1642
1992
                throws UnsupportedCommOperationException
1643
1993
        {
1644
1994
                if ( debug )
1645
 
                        System.out.println( "setParityErrorChar(" + b + ")" );
 
1995
                        z.reportln(  "setParityErrorChar(" + b + ")" );
1646
1996
                return( nativeSetParityErrorChar( b ) );
1647
1997
        }
1648
1998
 
1661
2011
        {
1662
2012
                byte ret;
1663
2013
                if ( debug )
1664
 
                        System.out.println( "getEndOfInputChar()" );
 
2014
                        z.reportln(  "getEndOfInputChar()" );
1665
2015
                ret = nativeGetEndOfInputChar();
1666
2016
                if ( debug )
1667
 
                        System.out.println( "getEndOfInputChar() returns " +
 
2017
                        z.reportln(  "getEndOfInputChar() returns " +
1668
2018
                                                ret );
1669
2019
                return( ret );
1670
2020
        }
1682
2032
                throws UnsupportedCommOperationException
1683
2033
        {
1684
2034
                if ( debug )
1685
 
                        System.out.println( "setEndOfInputChar(" + b + ")" );
 
2035
                        z.reportln(  "setEndOfInputChar(" + b + ")" );
1686
2036
                return( nativeSetEndOfInputChar( b ) );
1687
2037
        }
1688
2038
 
1701
2051
                throws UnsupportedCommOperationException
1702
2052
        {
1703
2053
                if ( debug )
1704
 
                        System.out.println( "RXTXPort:setUARTType()");
 
2054
                        z.reportln(  "RXTXPort:setUARTType()");
1705
2055
                return nativeSetUartType(type, test);
1706
2056
        }
1707
2057
        /**
1719
2069
        }
1720
2070
 
1721
2071
        /**
1722
 
        *  Extension to CommAPI
 
2072
        *  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
 
2073
        *  before using.
1723
2074
        *  @param int BaudBase The clock frequency divided by 16.  Default
1724
2075
        *  BaudBase is 115200.
1725
2076
        *  @return boolean true on success
1726
 
        *  @throws UnsupportedCommOperationException
 
2077
        *  @throws UnsupportedCommOperationException, IOException
1727
2078
        */
1728
2079
 
1729
2080
        public boolean setBaudBase(int BaudBase)
1730
 
                throws UnsupportedCommOperationException
 
2081
                throws UnsupportedCommOperationException,
 
2082
                IOException
1731
2083
        {
1732
2084
                if ( debug )
1733
 
                        System.out.println( "RXTXPort:setBaudBase()");
 
2085
                        z.reportln(  "RXTXPort:setBaudBase()");
1734
2086
                return nativeSetBaudBase(BaudBase);
1735
2087
        }
1736
2088
 
1737
2089
        /**
1738
2090
        *  Extension to CommAPI
1739
2091
        *  @return int BaudBase
1740
 
        *  @throws UnsupportedCommOperationException
 
2092
        *  @throws UnsupportedCommOperationException, IOException
1741
2093
        */
1742
2094
 
1743
 
        public int getBaudBase() throws UnsupportedCommOperationException
 
2095
        public int getBaudBase() throws UnsupportedCommOperationException,
 
2096
                IOException
1744
2097
        {
1745
2098
                if ( debug )
1746
 
                        System.out.println( "RXTXPort:getBaudBase()");
 
2099
                        z.reportln(  "RXTXPort:getBaudBase()");
1747
2100
                return nativeGetBaudBase();
1748
2101
        }
1749
2102
 
1750
2103
        /**
1751
 
        *  Extension to CommAPI
 
2104
        *  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
 
2105
        *  before using.
1752
2106
        *  @param int Divisor;
1753
 
        *  @throws UnsupportedCommOperationException
 
2107
        *  @throws UnsupportedCommOperationException, IOException
1754
2108
        */
1755
2109
 
1756
2110
        public boolean setDivisor(int Divisor)
1757
 
                throws UnsupportedCommOperationException
 
2111
                throws UnsupportedCommOperationException, IOException
1758
2112
        {
1759
2113
                if ( debug )
1760
 
                        System.out.println( "RXTXPort:setDivisor()");
 
2114
                        z.reportln(  "RXTXPort:setDivisor()");
1761
2115
                return nativeSetDivisor(Divisor);
1762
2116
        }
1763
2117
 
1764
2118
        /**
1765
2119
        *  Extension to CommAPI
1766
2120
        *  @returns int Divisor;
1767
 
        *  @throws UnsupportedCommOperationException
 
2121
        *  @throws UnsupportedCommOperationException, IOException
1768
2122
        */
1769
2123
 
1770
 
        public int getDivisor() throws UnsupportedCommOperationException
 
2124
        public int getDivisor() throws UnsupportedCommOperationException,
 
2125
                IOException
1771
2126
        {
1772
2127
                if ( debug )
1773
 
                        System.out.println( "RXTXPort:getDivisor()");
 
2128
                        z.reportln(  "RXTXPort:getDivisor()");
1774
2129
                return nativeGetDivisor();
1775
2130
        }
1776
2131
 
1783
2138
        public boolean setLowLatency() throws UnsupportedCommOperationException
1784
2139
        {
1785
2140
                if ( debug )
1786
 
                        System.out.println( "RXTXPort:setLowLatency()");
 
2141
                        z.reportln(  "RXTXPort:setLowLatency()");
1787
2142
                return nativeSetLowLatency();
1788
2143
        }
1789
2144
 
1796
2151
        public boolean getLowLatency() throws UnsupportedCommOperationException
1797
2152
        {
1798
2153
                if ( debug )
1799
 
                        System.out.println( "RXTXPort:getLowLatency()");
 
2154
                        z.reportln(  "RXTXPort:getLowLatency()");
1800
2155
                return nativeGetLowLatency();
1801
2156
        }
1802
2157
 
1810
2165
                throws UnsupportedCommOperationException
1811
2166
        {
1812
2167
                if ( debug )
1813
 
                        System.out.println( "RXTXPort:setCallOutHangup()");
 
2168
                        z.reportln(  "RXTXPort:setCallOutHangup()");
1814
2169
                return nativeSetCallOutHangup(NoHup);
1815
2170
        }
1816
2171
 
1824
2179
                throws UnsupportedCommOperationException
1825
2180
        {
1826
2181
                if ( debug )
1827
 
                        System.out.println( "RXTXPort:getCallOutHangup()");
 
2182
                        z.reportln(  "RXTXPort:getCallOutHangup()");
1828
2183
                return nativeGetCallOutHangup();
1829
2184
        }
1830
2185
 
 
2186
        /**
 
2187
        *  Extension to CommAPI
 
2188
        *  returns boolean true on success
 
2189
        *  @throws UnsupportedCommOperationException
 
2190
        */
 
2191
 
 
2192
        public boolean clearCommInput()
 
2193
                throws UnsupportedCommOperationException
 
2194
        {
 
2195
                if ( debug )
 
2196
                        z.reportln(  "RXTXPort:clearCommInput()");
 
2197
                return nativeClearCommInput();
 
2198
        }
 
2199
 
1831
2200
/*------------------------  END OF CommAPI Extensions -----------------------*/
1832
2201
}