~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.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060301185652-ri9941gi01goklvz
Tags: 2.1.7-2
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-2002 by Trent Jarvi taj@www.linux.org.uk.
 
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
36
36
 
37
37
        protected final static boolean debug = false;
38
38
        protected final static boolean debug_read = false;
 
39
        protected final static boolean debug_read_results = false;
39
40
        protected final static boolean debug_write = false;
40
41
        protected final static boolean debug_events = false;
41
42
        protected final static boolean debug_verbose = false;
 
43
 
 
44
        private static Zystem z;
 
45
 
42
46
        static
43
47
        {
 
48
                try {
 
49
                        z = new Zystem();
 
50
                } catch ( Exception e ) {};
 
51
 
44
52
                if(debug ) 
45
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort {}");
 
53
                        z.reportln( "RXTXPort {}");
46
54
                System.loadLibrary( "rxtxSerial" );
47
55
                Initialize();
48
56
        }
49
57
 
50
 
 
51
58
        /** Initialize the native library */
52
59
        private native static void Initialize();
53
60
        boolean MonitorThreadAlive=false;
61
68
        public RXTXPort( String name ) throws PortInUseException
62
69
        {
63
70
                if (debug)
64
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:RXTXPort("+name+")");
 
71
                        z.reportln( "RXTXPort:RXTXPort("+name+") called");
65
72
        /* 
66
73
           commapi/javadocs/API_users_guide.html specifies that whenever
67
74
           an application tries to open a port in use by another application
83
90
                        waitForTheNativeCodeSilly();
84
91
                        MonitorThreadAlive=true;
85
92
        //      } catch ( PortInUseException e ){}
 
93
                timeout = -1;   /* default disabled timeout */
86
94
                if (debug)
87
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:RXTXPort("+name+") fd = " +
 
95
                        z.reportln( "RXTXPort:RXTXPort("+name+") returns with fd = " +
88
96
                                fd);
89
 
                timeout = -1;   /* default disabled timeout */
90
97
        }
91
98
        private native synchronized int open( String name )
92
99
                throws PortInUseException;
93
100
 
 
101
 
 
102
        /* dont close the file while accessing the fd */
 
103
        int IOLocked = 0;
 
104
 
94
105
        /** File descriptor */
95
106
        private int fd = 0;
 
107
 
96
108
        /** a pointer to the event info structure used to share information
97
109
            between threads so write threads can send output buffer empty
98
110
            from a pthread if need be.
 
111
 
 
112
            long for 64 bit pointers.
99
113
        */
100
 
        int eis = 0;
 
114
        long eis = 0;
101
115
        /** pid for lock files */
102
116
        int pid = 0;
103
117
 
110
124
        *  get the OutputStream
111
125
        *  @return OutputStream
112
126
        */
113
 
        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
        }
114
133
 
115
134
        /** Input stream */
116
135
        private final SerialInputStream in = new SerialInputStream();
119
138
        *  @return InputStream
120
139
        *  @see java.io.InputStream
121
140
        */
122
 
        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
        }
123
147
 
124
148
        /** 
125
149
        *  Set the SerialPort parameters
134
158
        *  If speed is not a predifined speed it is assumed to be
135
159
        *  the actual speed desired.
136
160
        */
137
 
        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 )
138
165
                throws UnsupportedCommOperationException
139
166
        {
140
167
                if (debug)
141
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:setSerialPortParams(" +
142
 
                                        b + " " + d + " " + s + " " + p + ")");
143
 
                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" );
144
173
                speed = b;
145
174
                if( s== STOPBITS_1_5 ) dataBits = DATABITS_5;
146
175
                else dataBits = d;
147
176
                stopBits = s;
148
177
                parity = p;
 
178
                        z.reportln( "RXTXPort:setSerialPortParams(" +
 
179
                                b + " " + d + " " + s + " " + p +
 
180
                                ") returning");
149
181
        }
150
182
 
151
183
        /**
153
185
        *  If speed is not a predifined speed it is assumed to be
154
186
        *  the actual speed desired.
155
187
        */
156
 
        private native void nativeSetSerialPortParams( int speed, int dataBits,
157
 
                int stopBits, int parity )
 
188
        private native boolean nativeSetSerialPortParams( int speed,
 
189
                int dataBits, int stopBits, int parity )
158
190
                throws UnsupportedCommOperationException;
159
191
 
160
192
        /** Line speed in bits-per-second */
166
198
        public int getBaudRate()
167
199
        {
168
200
                if (debug)
169
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getBaudRate()");
 
201
                        z.reportln( "RXTXPort:getBaudRate() called and returning " + speed);
170
202
                return speed;
171
203
        }
172
204
 
178
210
        public int getDataBits()
179
211
        {
180
212
                if (debug)
181
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getDataBits()");
 
213
                        z.reportln( "RXTXPort:getDataBits() called and returning " + dataBits);
182
214
                return dataBits;
183
215
        }
184
216
 
190
222
        public int getStopBits()
191
223
        {
192
224
                if (debug)
193
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getStopBits()");
 
225
                        z.reportln( "RXTXPort:getStopBits() called and returning " + stopBits);
194
226
                return stopBits;
195
227
        }
196
228
 
202
234
        public int getParity()
203
235
        {
204
236
                if (debug)
205
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getParity()");
 
237
                        z.reportln( "RXTXPort:getParity() called and returning " + parity );
206
238
                return parity;
207
239
        }
208
240
 
216
248
        public void setFlowControlMode( int flowcontrol )
217
249
        {
218
250
                if (debug)
219
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:setFlowControlMode()");
220
 
                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
                }
221
261
                catch( IOException e )
222
262
                {
223
263
                        e.printStackTrace();
224
264
                        return;
225
265
                }
226
266
                flowmode=flowcontrol;
 
267
                if (debug)
 
268
                        z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) returning");
227
269
        }
228
270
        /** 
229
271
        *  @return  int representing the flowmode
230
272
        */
231
 
        public int getFlowControlMode() { return flowmode; }
 
273
        public int getFlowControlMode()
 
274
        {
 
275
                if (debug)
 
276
                        z.reportln( "RXTXPort:getFlowControlMode() returning " + flowmode );
 
277
                return flowmode;
 
278
        }
232
279
        native void setflowcontrol( int flowcontrol ) throws IOException;
233
280
 
234
281
 
245
292
                throws UnsupportedCommOperationException
246
293
        {
247
294
                if (debug)
248
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:enableReceiveFramming()");
 
295
                        z.reportln( "RXTXPort:enableReceiveFramming() throwing exception");
249
296
                throw new UnsupportedCommOperationException( "Not supported" );
250
297
        }
251
298
        /** 
253
300
        public void disableReceiveFraming()
254
301
        {
255
302
                if (debug)
256
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:disableReceiveFramming()");
 
303
                        z.reportln( "RXTXPort:disableReceiveFramming() called and returning (noop)");
257
304
        }
258
305
        /** 
259
306
        *  @returns true if framing is enabled
261
308
        public boolean isReceiveFramingEnabled()
262
309
        {
263
310
                if (debug)
264
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:isReceiveFrammingEnabled()");
 
311
                        z.reportln( "RXTXPort:isReceiveFrammingEnabled() called and returning " + false );
265
312
                return false;
266
313
        }
267
314
        /** 
270
317
        public int getReceiveFramingByte()
271
318
        {
272
319
                if (debug)
273
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getReceiveFrammingByte()");
 
320
                        z.reportln( "RXTXPort:getReceiveFrammingByte() called and returning " + 0 );
274
321
                return 0;
275
322
        }
276
323
 
285
332
        /** 
286
333
        *  @return  bloolean true if recieve timeout is enabled
287
334
        */
288
 
        public native boolean NativeisReceiveTimeoutEnabled();
 
335
        private native boolean NativeisReceiveTimeoutEnabled();
289
336
        /** 
290
337
        *  @param  time
291
338
        *  @param  threshold
292
339
        *  @param  InputBuffer
293
340
        */
294
 
        public native void NativeEnableReceiveTimeoutThreshold(int time,
 
341
        private native void NativeEnableReceiveTimeoutThreshold(int time,
295
342
                int threshold,int InputBuffer);
296
343
        /** 
297
344
        */
298
345
        public void disableReceiveTimeout()
299
346
        {
300
347
                if (debug)
301
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:disableReceiveTimeout()");
 
348
                        z.reportln( "RXTXPort:disableReceiveTimeout() called");
302
349
                timeout = -1;
303
350
                NativeEnableReceiveTimeoutThreshold( timeout , threshold, InputBuffer );
 
351
                if (debug)
 
352
                        z.reportln( "RXTXPort:disableReceiveTimeout() returning");
304
353
        }
305
354
        /** 
306
355
        *  @param time
308
357
        public void enableReceiveTimeout( int time )
309
358
        {
310
359
                if (debug)
311
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:enableReceiveTimeout()");
 
360
                        z.reportln( "RXTXPort:enableReceiveTimeout() called");
312
361
                if( time >= 0 )
313
362
                {
314
363
                        timeout = time;
322
371
                                "Unexpected negative timeout value"
323
372
                        );
324
373
                }
 
374
                if (debug)
 
375
                        z.reportln( "RXTXPort:enableReceiveTimeout() returning");
325
376
        }
326
377
        /** 
327
378
        *  @return  boolean true if recieve timeout is enabled
329
380
        public boolean isReceiveTimeoutEnabled()
330
381
        {
331
382
                if (debug)
332
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:isReceiveTimeoutEnabled()");
333
 
                return(NativeisReceiveTimeoutEnabled());
 
383
                        z.reportln( "RXTXPort:isReceiveTimeoutEnabled() called and returning " + NativeisReceiveTimeoutEnabled() );
 
384
                return( NativeisReceiveTimeoutEnabled() );
334
385
        }
335
386
        /** 
336
387
        *  @return  int the timeout
338
389
        public int getReceiveTimeout()
339
390
        {
340
391
                if (debug)
341
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getReceiveTimeout()");
 
392
                        z.reportln( "RXTXPort:getReceiveTimeout() called and returning " + NativegetReceiveTimeout() );
342
393
                return(NativegetReceiveTimeout( ));
343
394
        }
344
395
 
352
403
        public void enableReceiveThreshold( int thresh )
353
404
        {
354
405
                if (debug)
355
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:enableReceiveThreshold()");
 
406
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) called");
356
407
                if(thresh >=0)
357
408
                {
358
409
                        threshold=thresh;
366
417
                                "Unexpected negative threshold value"
367
418
                        );
368
419
                }
 
420
                if (debug)
 
421
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) returned");
369
422
        }
370
423
        /** 
371
424
        */
372
425
        public void disableReceiveThreshold()
373
426
        {
374
427
                if (debug)
375
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:disableReceiveThreshold()");
 
428
                        z.reportln( "RXTXPort:disableReceiveThreshold() called and returning");
376
429
                enableReceiveThreshold(0);
377
430
        }
378
431
        /** 
381
434
        public int getReceiveThreshold()
382
435
        {
383
436
                if (debug)
384
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getReceiveThreshold()");
 
437
                        z.reportln( "RXTXPort:getReceiveThreshold() called and returning " + threshold);
385
438
                return threshold;
386
439
        }
387
440
        /** 
390
443
        public boolean isReceiveThresholdEnabled()
391
444
        {
392
445
                if (debug)
393
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:isReceiveThresholdEnable()");
 
446
                        z.reportln( "RXTXPort:isReceiveThresholdEnable() called and returning" + (threshold > 0) );
394
447
                return(threshold>0);
395
448
        }
396
449
 
409
462
        public void setInputBufferSize( int size )
410
463
        {
411
464
                if (debug)
412
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:setInputBufferSize( " +
413
 
                                        size + ")");
 
465
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
466
                                        size + ") called");
414
467
                if( size < 0 )
415
468
                        throw new IllegalArgumentException
416
469
                        (
417
470
                                "Unexpected negative buffer size value"
418
471
                        );
419
472
                else InputBuffer=size;
 
473
                if (debug)
 
474
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
475
                                        size + ") returning");
420
476
        }
421
477
        /** 
422
478
        */
423
479
        public int getInputBufferSize()
424
480
        {
425
481
                if (debug)
426
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getInputBufferSize()");
 
482
                        z.reportln( "RXTXPort:getInputBufferSize() called and returning " + InputBuffer );
427
483
                return(InputBuffer);
428
484
        }
429
485
        /** 
432
488
        public void setOutputBufferSize( int size )
433
489
        {
434
490
                if (debug)
435
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:setOutputBufferSize( " +
436
 
                                        size + ")");
 
491
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
492
                                        size + ") called");
437
493
                if( size < 0 )
438
494
                        throw new IllegalArgumentException
439
495
                        (
440
496
                                "Unexpected negative buffer size value"
441
497
                        );
442
498
                else OutputBuffer=size;
 
499
                if (debug)
 
500
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
501
                                        size + ") returned");
 
502
                
443
503
        }
444
504
        /** 
445
505
        *  @return  in the output buffer size
447
507
        public int getOutputBufferSize()
448
508
        {
449
509
                if (debug)
450
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:getOutputBufferSize()");
 
510
                        z.reportln( "RXTXPort:getOutputBufferSize() called and returning " + OutputBuffer );
451
511
                return(OutputBuffer);
452
512
        }
453
513
 
 
514
        /* =================== cleaned messages to here */
 
515
 
454
516
        /**
455
517
        *  Line status methods
456
518
        */
504
566
        protected native int readByte() throws IOException;
505
567
        protected native int readArray( byte b[], int off, int len )
506
568
                throws IOException;
 
569
        protected native int readTerminatedArray( byte b[], int off, int len, byte t[] )
 
570
                throws IOException;
507
571
 
508
572
 
509
573
        /** Serial Port Event listener */
523
587
        public boolean checkMonitorThread()
524
588
        {
525
589
                if (debug)
526
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:checkMonitorThread()");
 
590
                        z.reportln( "RXTXPort:checkMonitorThread()");
527
591
                if(monThread != null)
528
592
                {
529
593
                        if ( debug )
530
 
                                System.out.println(System.currentTimeMillis() + ": " + 
 
594
                                z.reportln( 
531
595
                                        "monThreadisInterrupted = " +
532
596
                                        monThreadisInterrupted );
533
597
                        return monThreadisInterrupted;
534
598
                }
535
599
                if ( debug )
536
 
                        System.out.println(System.currentTimeMillis() + ": " +  "monThread is null " );
 
600
                        z.reportln(  "monThread is null " );
537
601
                return(true);
538
602
        }
539
603
 
545
609
        public boolean sendEvent( int event, boolean state )
546
610
        {
547
611
                if (debug_events)
548
 
                        System.out.print(System.currentTimeMillis() + ": " + "RXTXPort:sendEvent(");
 
612
                        z.report( "RXTXPort:sendEvent(");
549
613
                /* Let the native side know its time to die */
550
614
 
551
615
                if ( fd == 0 || SPEventListener == null || monThread == null)
557
621
                {
558
622
                        case SerialPortEvent.DATA_AVAILABLE:
559
623
                                if( debug_events )
560
 
                                        System.out.println( "DATA_AVAILABLE " +
 
624
                                        z.reportln( "DATA_AVAILABLE " +
561
625
                                                monThread.Data + ")" );
562
626
                                break;
563
627
                        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
564
628
                                if( debug_events )
565
 
                                        System.out.println( 
 
629
                                        z.reportln( 
566
630
                                                "OUTPUT_BUFFER_EMPTY " +
567
631
                                                monThread.Output + ")" );
568
632
                                break;
569
633
                        case SerialPortEvent.CTS:
570
634
                                if( debug_events )
571
 
                                        System.out.println( "CTS " +
 
635
                                        z.reportln( "CTS " +
572
636
                                                monThread.CTS + ")" );
573
637
                                break;
574
638
                        case SerialPortEvent.DSR:
575
639
                                if( debug_events )
576
 
                                        System.out.println( "DSR " +
 
640
                                        z.reportln( "DSR " +
577
641
                                                monThread.Output + ")" );
578
642
                                break;
579
643
                        case SerialPortEvent.RI:
580
644
                                if( debug_events )
581
 
                                        System.out.println( "RI " +
 
645
                                        z.reportln( "RI " +
582
646
                                                monThread.RI + ")" );
583
647
                                break;
584
648
                        case SerialPortEvent.CD:
585
649
                                if( debug_events )
586
 
                                        System.out.println( "CD " +
 
650
                                        z.reportln( "CD " +
587
651
                                                monThread.CD + ")" );
588
652
                                break;
589
653
                        case SerialPortEvent.OE:
590
654
                                if( debug_events )
591
 
                                        System.out.println( "OE " +
 
655
                                        z.reportln( "OE " +
592
656
                                                monThread.OE + ")" );
593
657
                                break;
594
658
                        case SerialPortEvent.PE:
595
659
                                if( debug_events )
596
 
                                        System.out.println( "PE " +
 
660
                                        z.reportln( "PE " +
597
661
                                                monThread.PE + ")" );
598
662
                                break;
599
663
                        case SerialPortEvent.FE:
600
664
                                if( debug_events )
601
 
                                        System.out.println( "FE " +
 
665
                                        z.reportln( "FE " +
602
666
                                                monThread.FE + ")" );
603
667
                                break;
604
668
                        case SerialPortEvent.BI:
605
669
                                if( debug_events )
606
 
                                        System.out.println( "BI " +
 
670
                                        z.reportln( "BI " +
607
671
                                                monThread.BI + ")" );
608
672
                                break;
609
673
                        default:
610
674
                                if( debug_events )
611
 
                                        System.out.println( "XXXXXXXXXXXXXX " +
 
675
                                        z.reportln( "XXXXXXXXXXXXXX " +
612
676
                                                event + ")" );
613
677
                                break;
614
678
                }
615
679
                if( debug_events && debug_verbose )
616
 
                        System.out.println(System.currentTimeMillis() + ": " +  "checking flags " );
 
680
                        z.reportln(  "  checking flags " );
617
681
 
618
682
                switch( event )
619
683
                {
648
712
                                if( monThread.BI ) break;
649
713
                                return(false);
650
714
                        default:
651
 
                                System.err.println(System.currentTimeMillis() + ": " + "unknown event: " + event);
 
715
                                System.err.println( "unknown event: " + event);
652
716
                                return(false);
653
717
                }
654
718
                if( debug_events && debug_verbose )
655
 
                        System.out.println(System.currentTimeMillis() + ": " +  "getting event" );
 
719
                        z.reportln(  "  getting event" );
656
720
                SerialPortEvent e = new SerialPortEvent(this, event, !state,
657
721
                        state );
658
722
                if( debug_events && debug_verbose )
659
 
                        System.out.println(System.currentTimeMillis() + ": " +  "sending event" );
 
723
                        z.reportln(  "  sending event" );
660
724
                if(monThreadisInterrupted) 
661
725
                {
662
726
                        if( debug_events )
663
 
                                System.out.println(System.currentTimeMillis() + ": " +  "sendEvent return" );
 
727
                                z.reportln(  "  sendEvent return" );
664
728
                        return(true);
665
729
                }
666
730
                if( SPEventListener != null )
669
733
                }
670
734
 
671
735
                if( debug_events && debug_verbose )
672
 
                        System.out.println(System.currentTimeMillis() + ": " +  "sendEvent return" );
 
736
                        z.reportln(  "  sendEvent return" );
673
737
 
674
738
                if (fd == 0 ||  SPEventListener == null || monThread == null) 
675
739
                {
688
752
        */
689
753
 
690
754
        boolean MonitorThreadLock = true;
691
 
        boolean MonitorThreadCloseLock = true;
692
755
 
693
756
        public void addEventListener(
694
757
                SerialPortEventListener lsnr ) throws TooManyListenersException
698
761
                */
699
762
 
700
763
                if (debug)
701
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:addEventListener()");
 
764
                        z.reportln( "RXTXPort:addEventListener()");
702
765
                if( SPEventListener != null )
 
766
                {
703
767
                        throw new TooManyListenersException();
 
768
                }
704
769
                SPEventListener = lsnr;
705
770
                if( !MonitorThreadAlive )
706
771
                {
711
776
                        MonitorThreadAlive=true;
712
777
                }
713
778
                if (debug)
714
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:Interrupt=false");
 
779
                        z.reportln( "RXTXPort:Interrupt=false");
715
780
        }
716
781
        /**
717
782
        *  Remove the serial port event listener
719
784
        public void removeEventListener()
720
785
        {
721
786
                if (debug)
722
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:removeEventListener()");
 
787
                        z.reportln( "RXTXPort:removeEventListener() called");
723
788
                waitForTheNativeCodeSilly();
724
789
                //if( monThread != null && monThread.isAlive() )
725
790
                if( monThreadisInterrupted == true )
726
791
                {
727
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:removeEventListener() already interrupted");
 
792
                        z.reportln( "   RXTXPort:removeEventListener() already interrupted");
728
793
                        monThread = null;
729
794
                        SPEventListener = null;
730
 
                        Runtime.getRuntime().gc();
731
795
                        return;
732
796
                }
733
797
                else if( monThread != null && monThread.isAlive() )
734
798
                {
735
799
                        if (debug)
736
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:Interrupt=true");
 
800
                                z.reportln( "   RXTXPort:Interrupt=true");
737
801
                        monThreadisInterrupted=true;
738
802
                        /*
739
803
                           Notify all threads in this PID that something is up
740
804
                           They will call back to see if its their thread
741
805
                           using isInterrupted().
742
806
                        */
743
 
                        MonitorThreadCloseLock = true;
744
807
                        if (debug)
745
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:calling interruptEventLoop");
 
808
                                z.reportln( "   RXTXPort:calling interruptEventLoop");
746
809
                        interruptEventLoop( );
747
 
                        if (debug)
748
 
                                System.out.print("RXTXPort:waiting on closelock");
749
 
                        while( MonitorThreadCloseLock )
750
 
                        {
751
 
                                if (debug)
752
 
                                        System.out.print(".");
753
 
                                try {
754
 
                                        Thread.sleep(100);
755
 
                                } catch( Exception e ) {}
756
 
                        }
757
 
                        if (debug)
758
 
                                System.out.println();
759
 
                        if (debug)
760
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:calling monThread.join()");
 
810
                        
 
811
                        if (debug)
 
812
                                z.reportln( "   RXTXPort:calling monThread.join()");
761
813
                        try {
762
814
                                monThread.join(1000);
763
815
                        } catch (Exception ex) {
765
817
                                ex.printStackTrace();
766
818
                        }
767
819
                        if (debug)
768
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:waiting on isAlive()");
 
820
                                z.reportln( "   RXTXPort:waiting on isAlive()");
769
821
                        while( monThread.isAlive() )
770
822
                        {
771
823
                                if ( debug )
772
 
                                        System.out.println(System.currentTimeMillis() + ": " + "MonThread is still alive!");
 
824
                                        z.reportln( "   MonThread is still alive!");
773
825
                                try {
774
826
                                        monThread.join(1000);
775
827
                                        Thread.sleep( 1000 );
776
828
                                } catch( Exception e ){} 
777
 
                                monThread.stop();
 
829
                                //monThread.stop();
778
830
                        }
779
831
                        
780
832
                }
781
833
                if (debug)
782
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:calling gc()");
 
834
                        z.reportln( "   RXTXPort:calling gc()");
783
835
                monThread = null;
784
836
                SPEventListener = null;
785
 
                Runtime.getRuntime().gc();
786
837
                MonitorThreadLock = false;
787
838
                MonitorThreadAlive=false;
 
839
                monThreadisInterrupted=true;
 
840
                z.reportln( "RXTXPort:removeEventListener() returning");
788
841
        }
789
842
        /**
790
843
         *      Give the native code a chance to start listening to the hardware
800
853
                while( MonitorThreadLock )
801
854
                {
802
855
                        try {
803
 
                                Thread.sleep(100);
 
856
                                Thread.sleep(5);
804
857
                        } catch( Exception e ) {}
805
858
                }
806
859
        }
812
865
        public void notifyOnDataAvailable( boolean enable )
813
866
        {
814
867
                if (debug)
815
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnDataAvailable( " +
 
868
                        z.reportln( "RXTXPort:notifyOnDataAvailable( " +
816
869
                                enable+" )");
817
870
                
818
871
                waitForTheNativeCodeSilly();
830
883
        public void notifyOnOutputEmpty( boolean enable )
831
884
        {
832
885
                if (debug)
833
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnOutputEmpty( " +
 
886
                        z.reportln( "RXTXPort:notifyOnOutputEmpty( " +
834
887
                                enable+" )");
835
888
                waitForTheNativeCodeSilly();
836
889
                MonitorThreadLock = true;
846
899
        public void notifyOnCTS( boolean enable )
847
900
        {
848
901
                if (debug)
849
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnCTS( " +
 
902
                        z.reportln( "RXTXPort:notifyOnCTS( " +
850
903
                                enable+" )");
851
904
                waitForTheNativeCodeSilly();
852
905
                MonitorThreadLock = true;
860
913
        public void notifyOnDSR( boolean enable )
861
914
        {
862
915
                if (debug)
863
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnDSR( " +
 
916
                        z.reportln( "RXTXPort:notifyOnDSR( " +
864
917
                                enable+" )");
865
918
                waitForTheNativeCodeSilly();
866
919
                MonitorThreadLock = true;
874
927
        public void notifyOnRingIndicator( boolean enable )
875
928
        {
876
929
                if (debug)
877
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnRingIndicator( " +
 
930
                        z.reportln( "RXTXPort:notifyOnRingIndicator( " +
878
931
                                enable+" )");
879
932
                waitForTheNativeCodeSilly();
880
933
                MonitorThreadLock = true;
888
941
        public void notifyOnCarrierDetect( boolean enable )
889
942
        {
890
943
                if (debug)
891
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnCarrierDetect( " +
 
944
                        z.reportln( "RXTXPort:notifyOnCarrierDetect( " +
892
945
                                enable+" )");
893
946
                waitForTheNativeCodeSilly();
894
947
                MonitorThreadLock = true;
902
955
        public void notifyOnOverrunError( boolean enable )
903
956
        {
904
957
                if (debug)
905
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnOverrunError( " +
 
958
                        z.reportln( "RXTXPort:notifyOnOverrunError( " +
906
959
                                enable+" )");
907
960
                waitForTheNativeCodeSilly();
908
961
                MonitorThreadLock = true;
916
969
        public void notifyOnParityError( boolean enable )
917
970
        {
918
971
                if (debug)
919
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnParityError( " +
 
972
                        z.reportln( "RXTXPort:notifyOnParityError( " +
920
973
                                enable+" )");
921
974
                waitForTheNativeCodeSilly();
922
975
                MonitorThreadLock = true;
930
983
        public void notifyOnFramingError( boolean enable )
931
984
        {
932
985
                if (debug)
933
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnFramingError( " +
 
986
                        z.reportln( "RXTXPort:notifyOnFramingError( " +
934
987
                                enable+" )");
935
988
                waitForTheNativeCodeSilly();
936
989
                MonitorThreadLock = true;
944
997
        public void notifyOnBreakInterrupt( boolean enable )
945
998
        {
946
999
                if (debug)
947
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:notifyOnBreakInterrupt( " +
 
1000
                        z.reportln( "RXTXPort:notifyOnBreakInterrupt( " +
948
1001
                                enable+" )");
949
1002
                waitForTheNativeCodeSilly();
950
1003
                MonitorThreadLock = true;
961
1014
        public synchronized void close()
962
1015
        {
963
1016
                if (debug)
964
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " )"); 
 
1017
                        z.reportln( "RXTXPort:close( " + this.name + " )"); 
965
1018
                if( closeLock ) return;
966
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
                }
967
1028
                if ( fd <= 0 )
968
1029
                {
969
 
                        System.out.println( System.currentTimeMillis() + ": " + "RXTXPort:close detected bad File Descriptor" );
 
1030
                        z.reportln(  "RXTXPort:close detected bad File Descriptor" );
970
1031
                        return;
971
1032
                }
972
1033
                setDTR(false);
973
1034
                setDSR(false);
974
1035
                if (debug)
975
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
 
1036
                        z.reportln( "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
976
1037
                if ( ! monThreadisInterrupted )
977
1038
                {
978
1039
                        removeEventListener();
979
1040
                }
980
1041
                if (debug)
981
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " ) calling nativeClose"); 
 
1042
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling nativeClose"); 
982
1043
                nativeClose( this.name );
983
1044
                if (debug)
984
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " ) calling super.close"); 
 
1045
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling super.close"); 
985
1046
                super.close();
986
 
                if (debug)
987
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " ) calling System.gc"); 
988
 
 
989
1047
                fd = 0;
990
 
                Runtime.getRuntime().gc();
991
1048
                closeLock = false;
992
1049
                if (debug)
993
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:close( " + this.name + " ) leaving"); 
 
1050
                        z.reportln( "RXTXPort:close( " + this.name + " ) leaving"); 
994
1051
        }
995
1052
 
996
1053
 
998
1055
        protected void finalize()
999
1056
        {
1000
1057
                if (debug)
1001
 
                        System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:finalize()");
1002
 
                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();
1003
1066
        }
1004
1067
 
1005
1068
        /** Inner class for SerialOutputStream */
1012
1075
                public void write( int b ) throws IOException
1013
1076
                {
1014
1077
                        if (debug_write)
1015
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialOutputStream:write(int)");
 
1078
                                z.reportln( "RXTXPort:SerialOutputStream:write(int)");
1016
1079
                        if( speed == 0 ) return;
1017
 
        /* hmm this turns out to be a very bad idea
1018
1080
                        if ( monThreadisInterrupted == true )
1019
1081
                        {
1020
 
                                throw new IOException( "Port has been Closed" );
 
1082
                                return;
1021
1083
                        }
1022
 
        */
 
1084
                        IOLocked++;
1023
1085
                        waitForTheNativeCodeSilly();
1024
 
                        if ( fd == 0 ) throw new IOException();
1025
 
                        writeByte( b, monThreadisInterrupted );
1026
 
                        if (debug_write)
1027
 
                                System.out.println(System.currentTimeMillis() + ": " + "Leaving RXTXPort:SerialOutputStream:write( int )");
 
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--;
1028
1103
                }
1029
1104
        /**
1030
1105
        *  @param b[]
1034
1109
                {
1035
1110
                        if (debug_write)
1036
1111
                        {
1037
 
                                System.out.println(System.currentTimeMillis() + ": " + "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
 
1112
                                z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
1038
1113
                        }
1039
1114
                        if( speed == 0 ) return;
1040
 
        /* hmm this turns out to be a very bad idea
1041
1115
                        if ( monThreadisInterrupted == true )
1042
1116
                        {
1043
 
                                throw new IOException( "Port has been Closed" );
 
1117
                                return;
1044
1118
                        }
1045
 
        */
1046
1119
                        if ( fd == 0 ) throw new IOException();
 
1120
                        IOLocked++;
1047
1121
                        waitForTheNativeCodeSilly();
1048
 
                        writeArray( b, 0, b.length, monThreadisInterrupted );
1049
 
                        if (debug_write)
1050
 
                                System.out.println(System.currentTimeMillis() + ": " + "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
                        
1051
1135
                }
1052
1136
        /**
1053
1137
        *  @param b[]
1065
1149
                                        "Invalid offset/length passed to read"
1066
1150
                                );
1067
1151
                        }
1068
 
 
 
1152
         
1069
1153
                        byte send[] = new byte[len];
1070
1154
                        System.arraycopy( b, off, send, 0, len );
1071
1155
                        if (debug_write)
1072
1156
                        {
1073
 
                                System.out.println(System.currentTimeMillis() + ": " + "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) */ );
1074
1158
                        }
1075
1159
                        if ( fd == 0 ) throw new IOException();
1076
 
        /* hmm this turns out to be a very bad idea
1077
1160
                        if ( monThreadisInterrupted == true )
1078
1161
                        {
1079
 
                                throw new IOException( "Port has been Closed" );
 
1162
                                return;
1080
1163
                        }
1081
 
        */
 
1164
                        IOLocked++;
1082
1165
                        waitForTheNativeCodeSilly();
1083
 
                        writeArray( send, 0, len, monThreadisInterrupted );
1084
 
                        if( debug_write )
1085
 
                                System.out.println(System.currentTimeMillis() + ": " + "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--;
1086
1178
                }
1087
1179
        /**
1088
1180
        */
1089
1181
                public void flush() throws IOException
1090
1182
                {
1091
1183
                        if (debug)
1092
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialOutputStream:flush() enter");
 
1184
                                z.reportln( "RXTXPort:SerialOutputStream:flush() enter");
1093
1185
                        if( speed == 0 ) return;
1094
1186
                        if ( fd == 0 ) throw new IOException();
1095
 
        /* hmm this turns out to be a very bad idea
1096
1187
                        if ( monThreadisInterrupted == true )
1097
1188
                        {
 
1189
                        if (debug)
 
1190
                                z.reportln( "RXTXPort:SerialOutputStream:flush() Leaving Interrupted");
1098
1191
                                return;
1099
 
                                // FIXME Trent this breaks
1100
 
                                //throw new IOException( "flush() Port has been Closed" );
1101
1192
                        }
1102
 
        */
 
1193
                        IOLocked++;
1103
1194
                        waitForTheNativeCodeSilly();
1104
1195
                        /* 
1105
1196
                           this is probably good on all OS's but for now
1106
1197
                           just sendEvent from java on Sol
1107
1198
                        */
1108
 
                        if ( nativeDrain( monThreadisInterrupted ) )
1109
 
                                sendEvent( SerialPortEvent.OUTPUT_BUFFER_EMPTY, true );
1110
 
                        if (debug)
1111
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialOutputStream:flush() leave");
 
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--;
1112
1212
                }
1113
1213
        }
1114
1214
 
1119
1219
        *  @return int the int read
1120
1220
        *  @throws IOException
1121
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
1122
1232
        */
1123
 
                public int read() throws IOException
 
1233
                public synchronized int read() throws IOException
1124
1234
                {
1125
1235
                        if (debug_read)
1126
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialInputStream:read()");
1127
 
        /* hmm this turns out to be a very bad idea
1128
 
                        if ( monThreadisInterrupted ) return( -1 ) ;
1129
 
        */
 
1236
                                z.reportln( "RXTXPort:SerialInputStream:read() called");
1130
1237
                        if ( fd == 0 ) throw new IOException();
1131
 
        /* hmm this turns out to be a very bad idea
1132
 
                        if ( monThreadisInterrupted == true )
 
1238
                        if ( monThreadisInterrupted )
1133
1239
                        {
1134
 
                                throw new IOException( "Port has been Closed" );
 
1240
                                z.reportln( "+++++++++ read() monThreadisInterrupted" );
1135
1241
                        }
1136
 
        */
 
1242
                        IOLocked++;
 
1243
                        if (debug_read_results)
 
1244
                                z.reportln(  "RXTXPort:SerialInputStream:read() L" );
1137
1245
                        waitForTheNativeCodeSilly();
1138
 
                        int result = readByte();
1139
 
                        if (debug_read)
1140
 
                                System.out.println(System.currentTimeMillis() + ": " +  "readByte= " + result );
1141
 
                        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
                        }
1142
1260
                }
1143
1261
        /**
1144
1262
        *  @param b[]
1145
1263
        *  @return int  number of bytes read
1146
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
1147
1273
        */
1148
 
                public int read( byte b[] ) throws IOException
 
1274
                public synchronized int read( byte b[] ) throws IOException
1149
1275
                {
1150
1276
                        int result;
1151
1277
                        if (debug_read)
1152
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialInputStream:read(" + b.length + ")");
1153
 
        /* hmm this turns out to be a very bad idea
 
1278
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + ") called");
1154
1279
                        if ( monThreadisInterrupted == true )
1155
1280
                        {
1156
 
                                throw new IOException( "Port has been Closed" );
 
1281
                                return(0);
1157
1282
                        }
1158
 
        */
 
1283
                        IOLocked++;
1159
1284
                        waitForTheNativeCodeSilly();
1160
 
                        result = read( b, 0, b.length);
1161
 
                        if (debug_read)
1162
 
                                System.out.println(System.currentTimeMillis() + ": " +  "read = " + result );
1163
 
                        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
                        }
1164
1296
                }
1165
1297
/*
1166
1298
read(byte b[], int, int)
1172
1304
        *  @param len
1173
1305
        *  @return int  number of bytes read
1174
1306
        *  @throws IOException
1175
 
        */
1176
 
                public int read( byte b[], int off, int len )
1177
 
                        throws IOException
1178
 
                {
1179
 
                        if (debug_read)
1180
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") " /*+ new String(b) */ );
1181
 
                        int result;
1182
 
                        /*
1183
 
                         * Some sanity checks
1184
 
                         */
1185
 
                        if ( fd == 0 ) throw new IOException();
1186
 
 
1187
 
                        if( b==null )
1188
 
                                throw new NullPointerException();
1189
 
 
1190
 
                        if( (off < 0) || (len < 0) || (off+len > b.length))
1191
 
                                throw new IndexOutOfBoundsException();
1192
 
 
1193
 
                        /*
1194
 
                         * Return immediately if len==0
1195
 
                         */
1196
 
                        if( len==0 ) return 0;
1197
 
 
1198
 
                        /*
1199
 
                         * See how many bytes we should read
1200
 
                         */
1201
 
                        int Minimum = len;
1202
 
 
1203
 
                        if( threshold==0 )
1204
 
                        {
1205
 
                        /*
1206
 
                         * If threshold is disabled, read should return as soon
1207
 
                         * as data are available (up to the amount of available
1208
 
                         * bytes in order to avoid blocking)
1209
 
                         * Read may return earlier depending of the receive time
1210
 
                         * out.
1211
 
                         */
1212
 
                                if( available()==0 )
1213
 
                                        Minimum = 1;
1214
 
                                else
1215
 
                                        Minimum = Math.min(Minimum,available());
1216
 
                        }
1217
 
                        else
1218
 
                        {
1219
 
                        /*
1220
 
                         * Threshold is enabled. Read should return when
1221
 
                         * 'threshold' bytes have been received (or when the
1222
 
                         * receive timeout expired)
1223
 
                         */
1224
 
                                Minimum = Math.min(Minimum, threshold);
1225
 
                        }
1226
 
        /* hmm this turns out to be a very bad idea
1227
 
                        if ( monThreadisInterrupted == true )
1228
 
                        {
1229
 
                                throw new IOException( "Port has been Closed" );
1230
 
                        }
1231
 
        */
1232
 
                        waitForTheNativeCodeSilly();
1233
 
                        result = readArray( b, off, Minimum);
1234
 
                        if (debug_read)
1235
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") = " + result + " bytes containing "  /*+ new String(b) */);
1236
 
                        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
                        }
1237
1516
                }
1238
1517
        /**
1239
1518
        *  @return int bytes available
1240
1519
        *  @throws IOException
1241
1520
        */
1242
 
                public int available() throws IOException
 
1521
                public synchronized int available() throws IOException
1243
1522
                {
1244
 
        /* hmm this turns out to be a very bad idea
1245
1523
                        if ( monThreadisInterrupted == true )
1246
1524
                        {
1247
 
                                throw new IOException( "Port has been Closed" );
1248
 
                        }
1249
 
        */
1250
 
                        int r = nativeavailable();
1251
 
                        if ( debug_verbose && r > 0 )
1252
 
                                System.out.println(System.currentTimeMillis() + ": " + "available() returning " +
1253
 
                                        r );
1254
 
                        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
                        }
1255
1542
                }
1256
1543
        }
1257
1544
        /**
1275
1562
                MonitorThread() 
1276
1563
                {
1277
1564
                        if (debug)
1278
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:MontitorThread:MonitorThread()"); 
 
1565
                                z.reportln( "RXTXPort:MontitorThread:MonitorThread()"); 
1279
1566
                }
1280
1567
        /**
1281
1568
        *  run the thread and call the event loop.
1283
1570
                public void run()
1284
1571
                {
1285
1572
                        if (debug)
1286
 
                                System.out.println(System.currentTimeMillis() + ": " + "RXTXPort:MontitorThread:run()"); 
 
1573
                                z.reportln( "RXTXPort:MontitorThread:run()"); 
1287
1574
                        monThreadisInterrupted=false;
1288
1575
                        eventLoop();
1289
 
 
1290
1576
                        if (debug)
1291
 
                                System.out.println(System.currentTimeMillis() + ": " + "eventLoop() returned"); 
 
1577
                                z.reportln( "eventLoop() returned"); 
1292
1578
                }
1293
1579
                protected void finalize() throws Throwable 
1294
1580
                { 
1295
1581
                        if (debug)
1296
 
                                System.out.println(System.currentTimeMillis() + ": " + "MonitorThread finalizing"); 
 
1582
                                z.reportln( "RXTXPort:MonitorThread exiting"); 
1297
1583
                }
1298
1584
        }
1299
1585
        /**
1368
1654
                throws UnsupportedCommOperationException;
1369
1655
        private native boolean nativeGetCallOutHangup()
1370
1656
                throws UnsupportedCommOperationException;
 
1657
        private native boolean nativeClearCommInput()
 
1658
                throws UnsupportedCommOperationException;
1371
1659
 
1372
1660
        /**
1373
1661
        *  Extension to CommAPI
1386
1674
                throws UnsupportedCommOperationException
1387
1675
        {
1388
1676
                if ( debug )
1389
 
                        System.out.println(System.currentTimeMillis() + ": " + 
 
1677
                        z.reportln( 
1390
1678
                                "RXTXPort:staticGetBaudRate( " + port + " )");
1391
1679
                return(nativeStaticGetBaudRate( port ));
1392
1680
        }
1404
1692
                throws UnsupportedCommOperationException
1405
1693
        {
1406
1694
                if ( debug )
1407
 
                        System.out.println(System.currentTimeMillis() + ": " + 
 
1695
                        z.reportln( 
1408
1696
                                "RXTXPort:staticGetDataBits( " + port + " )");
1409
1697
                return(nativeStaticGetDataBits( port ) );
1410
1698
        }
1423
1711
                throws UnsupportedCommOperationException
1424
1712
        {
1425
1713
                if ( debug )
1426
 
                        System.out.println(System.currentTimeMillis() + ": " + 
 
1714
                        z.reportln( 
1427
1715
                                "RXTXPort:staticGetParity( " + port + " )");
1428
1716
                return( nativeStaticGetParity( port ) );
1429
1717
        }
1442
1730
                throws UnsupportedCommOperationException
1443
1731
        {
1444
1732
                if ( debug )
1445
 
                        System.out.println(System.currentTimeMillis() + ": " + 
 
1733
                        z.reportln( 
1446
1734
                                "RXTXPort:staticGetStopBits( " + port + " )");
1447
1735
                        return(nativeStaticGetStopBits( port ) );
1448
1736
        }
1469
1757
                throws UnsupportedCommOperationException
1470
1758
        {
1471
1759
                if ( debug )
1472
 
                        System.out.println(System.currentTimeMillis() + ": " + 
 
1760
                        z.reportln( 
1473
1761
                                "RXTXPort:staticSetSerialPortParams( " +
1474
1762
                                f + " " + b + " " + d + " " + s + " " + p );
1475
1763
                nativeStaticSetSerialPortParams( f, b, d, s, p );
1493
1781
                throws UnsupportedCommOperationException
1494
1782
        {
1495
1783
                if ( debug )
1496
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticSetDSR( " + port +
 
1784
                        z.reportln(  "RXTXPort:staticSetDSR( " + port +
1497
1785
                                                " " + flag );
1498
1786
                return( nativeStaticSetDSR( port, flag ) );
1499
1787
        }
1516
1804
                throws UnsupportedCommOperationException
1517
1805
        {
1518
1806
                if ( debug )
1519
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticSetDTR( " + port +
 
1807
                        z.reportln(  "RXTXPort:staticSetDTR( " + port +
1520
1808
                                                " " + flag );
1521
1809
                return( nativeStaticSetDTR( port, flag ) );
1522
1810
        }
1539
1827
                throws UnsupportedCommOperationException
1540
1828
        {
1541
1829
                if ( debug )
1542
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticSetRTS( " + port +
 
1830
                        z.reportln(  "RXTXPort:staticSetRTS( " + port +
1543
1831
                                                " " + flag );
1544
1832
                return( nativeStaticSetRTS( port, flag ) );
1545
1833
        }
1561
1849
                throws UnsupportedCommOperationException
1562
1850
        {
1563
1851
                if ( debug )
1564
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticIsRTS( " + port + " )" );
 
1852
                        z.reportln(  "RXTXPort:staticIsRTS( " + port + " )" );
1565
1853
                return( nativeStaticIsRTS( port ) );
1566
1854
        }
1567
1855
        /**
1581
1869
                throws UnsupportedCommOperationException
1582
1870
        {
1583
1871
                if ( debug )
1584
 
                        System.out.println( "RXTXPort:staticIsCD( " + port + " )" );
 
1872
                        z.reportln( "RXTXPort:staticIsCD( " + port + " )" );
1585
1873
                return( nativeStaticIsCD( port ) );
1586
1874
        }
1587
1875
        /**
1601
1889
                throws UnsupportedCommOperationException
1602
1890
        {
1603
1891
                if ( debug )
1604
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticIsCTS( " + port + " )" );
 
1892
                        z.reportln(  "RXTXPort:staticIsCTS( " + port + " )" );
1605
1893
                return( nativeStaticIsCTS( port ) );
1606
1894
        }
1607
1895
        /**
1621
1909
                throws UnsupportedCommOperationException
1622
1910
        {
1623
1911
                if ( debug )
1624
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticIsDSR( " + port + " )" );
 
1912
                        z.reportln(  "RXTXPort:staticIsDSR( " + port + " )" );
1625
1913
                return( nativeStaticIsDSR( port ) );
1626
1914
        }
1627
1915
        /**
1641
1929
                throws UnsupportedCommOperationException
1642
1930
        {
1643
1931
                if ( debug )
1644
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticIsDTR( " + port + " )" );
 
1932
                        z.reportln(  "RXTXPort:staticIsDTR( " + port + " )" );
1645
1933
                return( nativeStaticIsDTR( port ) );
1646
1934
        }
1647
1935
        /**
1661
1949
                throws UnsupportedCommOperationException
1662
1950
        {
1663
1951
                if ( debug )
1664
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:staticIsRI( " + port + " )" );
 
1952
                        z.reportln(  "RXTXPort:staticIsRI( " + port + " )" );
1665
1953
                return( nativeStaticIsRI( port ) );
1666
1954
        }
1667
1955
 
1681
1969
        {
1682
1970
                byte ret;
1683
1971
                if ( debug )
1684
 
                        System.out.println(System.currentTimeMillis() + ": " +  "getParityErrorChar()" );
 
1972
                        z.reportln(  "getParityErrorChar()" );
1685
1973
                ret = nativeGetParityErrorChar();
1686
1974
                if ( debug )
1687
 
                        System.out.println(System.currentTimeMillis() + ": " +  "getParityErrorChar() returns " +
 
1975
                        z.reportln(  "getParityErrorChar() returns " +
1688
1976
                                                ret );
1689
1977
                return( ret );
1690
1978
        }
1704
1992
                throws UnsupportedCommOperationException
1705
1993
        {
1706
1994
                if ( debug )
1707
 
                        System.out.println(System.currentTimeMillis() + ": " +  "setParityErrorChar(" + b + ")" );
 
1995
                        z.reportln(  "setParityErrorChar(" + b + ")" );
1708
1996
                return( nativeSetParityErrorChar( b ) );
1709
1997
        }
1710
1998
 
1723
2011
        {
1724
2012
                byte ret;
1725
2013
                if ( debug )
1726
 
                        System.out.println(System.currentTimeMillis() + ": " +  "getEndOfInputChar()" );
 
2014
                        z.reportln(  "getEndOfInputChar()" );
1727
2015
                ret = nativeGetEndOfInputChar();
1728
2016
                if ( debug )
1729
 
                        System.out.println(System.currentTimeMillis() + ": " +  "getEndOfInputChar() returns " +
 
2017
                        z.reportln(  "getEndOfInputChar() returns " +
1730
2018
                                                ret );
1731
2019
                return( ret );
1732
2020
        }
1744
2032
                throws UnsupportedCommOperationException
1745
2033
        {
1746
2034
                if ( debug )
1747
 
                        System.out.println(System.currentTimeMillis() + ": " +  "setEndOfInputChar(" + b + ")" );
 
2035
                        z.reportln(  "setEndOfInputChar(" + b + ")" );
1748
2036
                return( nativeSetEndOfInputChar( b ) );
1749
2037
        }
1750
2038
 
1763
2051
                throws UnsupportedCommOperationException
1764
2052
        {
1765
2053
                if ( debug )
1766
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:setUARTType()");
 
2054
                        z.reportln(  "RXTXPort:setUARTType()");
1767
2055
                return nativeSetUartType(type, test);
1768
2056
        }
1769
2057
        /**
1781
2069
        }
1782
2070
 
1783
2071
        /**
1784
 
        *  Extension to CommAPI
 
2072
        *  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
 
2073
        *  before using.
1785
2074
        *  @param int BaudBase The clock frequency divided by 16.  Default
1786
2075
        *  BaudBase is 115200.
1787
2076
        *  @return boolean true on success
1788
 
        *  @throws UnsupportedCommOperationException
 
2077
        *  @throws UnsupportedCommOperationException, IOException
1789
2078
        */
1790
2079
 
1791
2080
        public boolean setBaudBase(int BaudBase)
1792
 
                throws UnsupportedCommOperationException
 
2081
                throws UnsupportedCommOperationException,
 
2082
                IOException
1793
2083
        {
1794
2084
                if ( debug )
1795
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:setBaudBase()");
 
2085
                        z.reportln(  "RXTXPort:setBaudBase()");
1796
2086
                return nativeSetBaudBase(BaudBase);
1797
2087
        }
1798
2088
 
1799
2089
        /**
1800
2090
        *  Extension to CommAPI
1801
2091
        *  @return int BaudBase
1802
 
        *  @throws UnsupportedCommOperationException
 
2092
        *  @throws UnsupportedCommOperationException, IOException
1803
2093
        */
1804
2094
 
1805
 
        public int getBaudBase() throws UnsupportedCommOperationException
 
2095
        public int getBaudBase() throws UnsupportedCommOperationException,
 
2096
                IOException
1806
2097
        {
1807
2098
                if ( debug )
1808
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:getBaudBase()");
 
2099
                        z.reportln(  "RXTXPort:getBaudBase()");
1809
2100
                return nativeGetBaudBase();
1810
2101
        }
1811
2102
 
1812
2103
        /**
1813
 
        *  Extension to CommAPI
 
2104
        *  Extension to CommAPI.  Set Baud Base to 38600 on Linux and W32
 
2105
        *  before using.
1814
2106
        *  @param int Divisor;
1815
 
        *  @throws UnsupportedCommOperationException
 
2107
        *  @throws UnsupportedCommOperationException, IOException
1816
2108
        */
1817
2109
 
1818
2110
        public boolean setDivisor(int Divisor)
1819
 
                throws UnsupportedCommOperationException
 
2111
                throws UnsupportedCommOperationException, IOException
1820
2112
        {
1821
2113
                if ( debug )
1822
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:setDivisor()");
 
2114
                        z.reportln(  "RXTXPort:setDivisor()");
1823
2115
                return nativeSetDivisor(Divisor);
1824
2116
        }
1825
2117
 
1826
2118
        /**
1827
2119
        *  Extension to CommAPI
1828
2120
        *  @returns int Divisor;
1829
 
        *  @throws UnsupportedCommOperationException
 
2121
        *  @throws UnsupportedCommOperationException, IOException
1830
2122
        */
1831
2123
 
1832
 
        public int getDivisor() throws UnsupportedCommOperationException
 
2124
        public int getDivisor() throws UnsupportedCommOperationException,
 
2125
                IOException
1833
2126
        {
1834
2127
                if ( debug )
1835
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:getDivisor()");
 
2128
                        z.reportln(  "RXTXPort:getDivisor()");
1836
2129
                return nativeGetDivisor();
1837
2130
        }
1838
2131
 
1845
2138
        public boolean setLowLatency() throws UnsupportedCommOperationException
1846
2139
        {
1847
2140
                if ( debug )
1848
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:setLowLatency()");
 
2141
                        z.reportln(  "RXTXPort:setLowLatency()");
1849
2142
                return nativeSetLowLatency();
1850
2143
        }
1851
2144
 
1858
2151
        public boolean getLowLatency() throws UnsupportedCommOperationException
1859
2152
        {
1860
2153
                if ( debug )
1861
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:getLowLatency()");
 
2154
                        z.reportln(  "RXTXPort:getLowLatency()");
1862
2155
                return nativeGetLowLatency();
1863
2156
        }
1864
2157
 
1872
2165
                throws UnsupportedCommOperationException
1873
2166
        {
1874
2167
                if ( debug )
1875
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:setCallOutHangup()");
 
2168
                        z.reportln(  "RXTXPort:setCallOutHangup()");
1876
2169
                return nativeSetCallOutHangup(NoHup);
1877
2170
        }
1878
2171
 
1886
2179
                throws UnsupportedCommOperationException
1887
2180
        {
1888
2181
                if ( debug )
1889
 
                        System.out.println(System.currentTimeMillis() + ": " +  "RXTXPort:getCallOutHangup()");
 
2182
                        z.reportln(  "RXTXPort:getCallOutHangup()");
1890
2183
                return nativeGetCallOutHangup();
1891
2184
        }
1892
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
 
1893
2200
/*------------------------  END OF CommAPI Extensions -----------------------*/
1894
2201
}