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

« back to all changes in this revision

Viewing changes to CNI/RXTXPort.java

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
|   rxtx is a native interface to serial ports in java.
 
3
|   Copyright 1997-2004 by Trent Jarvi taj@www.linux.org.uk.
 
4
|
 
5
|   This library is free software; you can redistribute it and/or
 
6
|   modify it under the terms of the GNU Library General Public
 
7
|   License as published by the Free Software Foundation; either
 
8
|   version 2 of the License, or (at your option) any later version.
 
9
|
 
10
|   This library is distributed in the hope that it will be useful,
 
11
|   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
|   Library General Public License for more details.
 
14
|
 
15
|   You should have received a copy of the GNU Library General Public
 
16
|   License along with this library; if not, write to the Free
 
17
|   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
--------------------------------------------------------------------------*/
 
19
package gnu.io;
 
20
import java.io.InputStream;
 
21
import java.io.OutputStream;
 
22
import java.io.IOException;
 
23
import java.util.TooManyListenersException;
 
24
import java.lang.Math;
 
25
 
 
26
/**
 
27
* An extension of gnu.io.SerialPort
 
28
* @see gnu.io.SerialPort
 
29
*/
 
30
 
 
31
final public class RXTXPort extends SerialPort
 
32
{
 
33
        /* I had a report that some JRE's complain when MonitorThread
 
34
           tries to access private variables
 
35
        */
 
36
 
 
37
        protected final static boolean debug = false;
 
38
        protected final static boolean debug_read = false;
 
39
        protected final static boolean debug_read_results = false;
 
40
        protected final static boolean debug_write = false;
 
41
        protected final static boolean debug_events = false;
 
42
        protected final static boolean debug_verbose = false;
 
43
 
 
44
        private static Zystem z;
 
45
 
 
46
        static
 
47
        {
 
48
                try {
 
49
                        z = new Zystem( Zystem.PRINT_MODE );
 
50
                } catch ( Exception e ) {};
 
51
 
 
52
                if(debug ) 
 
53
                        z.reportln( "RXTXPort {}");
 
54
/*
 
55
                System.loadLibrary( "rxtxSerial" );
 
56
*/
 
57
                Initialize();
 
58
        }
 
59
 
 
60
        /** Initialize the native library */
 
61
        private native static void Initialize();
 
62
        boolean MonitorThreadAlive=false;
 
63
 
 
64
        /** 
 
65
        *  Open the named port
 
66
        *  @param name the name of the device to open
 
67
        *  @throws  PortInUseException
 
68
        *  @see gnu.io.SerialPort
 
69
        */
 
70
        public RXTXPort( String name ) throws PortInUseException
 
71
        {
 
72
                if (debug)
 
73
                        z.reportln( "RXTXPort:RXTXPort("+name+") called");
 
74
        /* 
 
75
           commapi/javadocs/API_users_guide.html specifies that whenever
 
76
           an application tries to open a port in use by another application
 
77
           the PortInUseException will be thrown
 
78
 
 
79
           I know some didnt like it this way but I'm not sure how to avoid
 
80
           it.  We will just be writing to a bogus fd if we catch the 
 
81
           exeption
 
82
 
 
83
           Trent
 
84
        */
 
85
        //      try {
 
86
                        fd = open( name );
 
87
                        this.name = name;
 
88
 
 
89
                        MonitorThreadLock = true;
 
90
                        monThread = new MonitorThread();
 
91
                        monThread.start();
 
92
                        waitForTheNativeCodeSilly();
 
93
                        MonitorThreadAlive=true;
 
94
        //      } catch ( PortInUseException e ){}
 
95
                timeout = -1;   /* default disabled timeout */
 
96
                if (debug)
 
97
                        z.reportln( "RXTXPort:RXTXPort("+name+") returns with fd = " +
 
98
                                fd);
 
99
        }
 
100
        private native synchronized int open( String name )
 
101
                throws PortInUseException;
 
102
 
 
103
        /** File descriptor */
 
104
        protected int fd = 0;
 
105
        /** a pointer to the event info structure used to share information
 
106
            between threads so write threads can send output buffer empty
 
107
            from a pthread if need be.
 
108
        */
 
109
        int eis = 0;
 
110
        /** pid for lock files */
 
111
        int pid = 0;
 
112
 
 
113
        /** DSR flag **/
 
114
        static boolean dsrFlag = false;
 
115
 
 
116
        /** Output stream */
 
117
        private final SerialOutputStream out = new SerialOutputStream();
 
118
        /** 
 
119
        *  get the OutputStream
 
120
        *  @return OutputStream
 
121
        */
 
122
        public OutputStream getOutputStream()
 
123
        {
 
124
                if (debug)
 
125
                        z.reportln( "RXTXPort:getOutputStream() called and returning");
 
126
                return out;
 
127
        }
 
128
 
 
129
        /** Input stream */
 
130
        private final SerialInputStream in = new SerialInputStream();
 
131
        /** 
 
132
        *  get the InputStream
 
133
        *  @return InputStream
 
134
        *  @see java.io.InputStream
 
135
        */
 
136
        public InputStream getInputStream()
 
137
        {
 
138
                if (debug)
 
139
                        z.reportln( "RXTXPort:getInputStream() called and returning");
 
140
                return in;
 
141
        }
 
142
 
 
143
        /** 
 
144
        *  Set the SerialPort parameters
 
145
        *  1.5 stop bits requires 5 databits
 
146
        *  @param  b baudrate
 
147
        *  @param  d databits
 
148
        *  @param  s stopbits
 
149
        *  @param  p parity
 
150
        *  @throws UnsupportedCommOperationException
 
151
        *  @see gnu.io.UnsupportedCommOperationException
 
152
 
 
153
        *  If speed is not a predifined speed it is assumed to be
 
154
        *  the actual speed desired.
 
155
        */
 
156
        private native int nativeGetParity( int fd );
 
157
        private native int nativeGetFlowControlMode( int fd );
 
158
        public synchronized void setSerialPortParams( int b, int d, int s,
 
159
                int p )
 
160
                throws UnsupportedCommOperationException
 
161
        {
 
162
                if (debug)
 
163
                        z.reportln( "RXTXPort:setSerialPortParams(" +
 
164
                                b + " " + d + " " + s + " " + p + ") called");
 
165
                if ( nativeSetSerialPortParams( b, d, s, p ) )
 
166
                        throw new UnsupportedCommOperationException(
 
167
                                "Invalid Parameter" );
 
168
                speed = b;
 
169
                if( s== STOPBITS_1_5 ) dataBits = DATABITS_5;
 
170
                else dataBits = d;
 
171
                stopBits = s;
 
172
                parity = p;
 
173
                if (debug)
 
174
                        z.reportln( "RXTXPort:setSerialPortParams(" +
 
175
                                b + " " + d + " " + s + " " + p +
 
176
                                ") returning");
 
177
        }
 
178
 
 
179
        /**
 
180
        *  Set the native serial port parameters
 
181
        *  If speed is not a predifined speed it is assumed to be
 
182
        *  the actual speed desired.
 
183
        */
 
184
        private native boolean nativeSetSerialPortParams( int speed,
 
185
                int dataBits, int stopBits, int parity )
 
186
                throws UnsupportedCommOperationException;
 
187
 
 
188
        /** Line speed in bits-per-second */
 
189
        protected int speed=9600;
 
190
        /** 
 
191
        *  @return  int representing the baudrate
 
192
        *  This will not behave as expected with custom speeds
 
193
        */
 
194
        public int getBaudRate()
 
195
        {
 
196
                if (debug)
 
197
                        z.reportln( "RXTXPort:getBaudRate() called and returning " + speed);
 
198
                return speed;
 
199
        }
 
200
 
 
201
        /** Data bits port parameter */
 
202
        protected int dataBits=DATABITS_8;
 
203
        /** 
 
204
        *  @return int representing the databits
 
205
        */
 
206
        public int getDataBits()
 
207
        {
 
208
                if (debug)
 
209
                        z.reportln( "RXTXPort:getDataBits() called and returning " + dataBits);
 
210
                return dataBits;
 
211
        }
 
212
 
 
213
        /** Stop bits port parameter */
 
214
        protected int stopBits=SerialPort.STOPBITS_1;
 
215
        /** 
 
216
        *  @return int representing the stopbits
 
217
        */
 
218
        public int getStopBits()
 
219
        {
 
220
                if (debug)
 
221
                        z.reportln( "RXTXPort:getStopBits() called and returning " + stopBits);
 
222
                return stopBits;
 
223
        }
 
224
 
 
225
        /** Parity port parameter */
 
226
        protected int parity= SerialPort.PARITY_NONE;
 
227
        /** 
 
228
        *  @return int representing the parity
 
229
        */
 
230
        public int getParity()
 
231
        {
 
232
                if (debug)
 
233
                        z.reportln( "RXTXPort:getParity() called and returning " + parity );
 
234
                return parity;
 
235
        }
 
236
 
 
237
 
 
238
        /** Flow control */
 
239
        protected int flowmode = SerialPort.FLOWCONTROL_NONE;
 
240
        /** 
 
241
        *  @param  flowcontrol FLOWCONTROL_NONE is default
 
242
        *  @see gnu.io.SerialPort#FLOWCONTROL_NONE
 
243
        */
 
244
        public void setFlowControlMode( int flowcontrol )
 
245
        {
 
246
                if (debug)
 
247
                        z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) called");
 
248
                if(monThreadisInterrupted) 
 
249
                {
 
250
                        if( debug_events )
 
251
                                z.reportln(  "RXTXPort:setFlowControlMode MonThread is Interrupeted returning" );
 
252
                        return;
 
253
                }
 
254
                try {
 
255
                        setflowcontrol( flowcontrol );
 
256
                }
 
257
                catch( IOException e )
 
258
                {
 
259
                        e.printStackTrace();
 
260
                        return;
 
261
                }
 
262
                flowmode=flowcontrol;
 
263
                if (debug)
 
264
                        z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) returning");
 
265
        }
 
266
        /** 
 
267
        *  @return  int representing the flowmode
 
268
        */
 
269
        public int getFlowControlMode()
 
270
        {
 
271
                if (debug)
 
272
                        z.reportln( "RXTXPort:getFlowControlMode() returning " + flowmode );
 
273
                return flowmode;
 
274
        }
 
275
        native void setflowcontrol( int flowcontrol ) throws IOException;
 
276
 
 
277
 
 
278
        /*
 
279
        linux/drivers/char/n_hdlc.c? FIXME
 
280
                taj@www.linux.org.uk
 
281
        */
 
282
        /**
 
283
        *  Receive framing control
 
284
        *  @param  f framming
 
285
        *  @throws UnsupportedCommOperationException
 
286
        */
 
287
        public void enableReceiveFraming( int f )
 
288
                throws UnsupportedCommOperationException
 
289
        {
 
290
                if (debug)
 
291
                        z.reportln( "RXTXPort:enableReceiveFramming() throwing exception");
 
292
                throw new UnsupportedCommOperationException( "Not supported" );
 
293
        }
 
294
        /** 
 
295
        */
 
296
        public void disableReceiveFraming()
 
297
        {
 
298
                if (debug)
 
299
                        z.reportln( "RXTXPort:disableReceiveFramming() called and returning (noop)");
 
300
        }
 
301
        /** 
 
302
        *  @returns true if framing is enabled
 
303
        */
 
304
        public boolean isReceiveFramingEnabled()
 
305
        {
 
306
                if (debug)
 
307
                        z.reportln( "RXTXPort:isReceiveFrammingEnabled() called and returning " + false );
 
308
                return false;
 
309
        }
 
310
        /** 
 
311
        *  @return  int representing the framing byte
 
312
        */
 
313
        public int getReceiveFramingByte()
 
314
        {
 
315
                if (debug)
 
316
                        z.reportln( "RXTXPort:getReceiveFrammingByte() called and returning " + 0 );
 
317
                return 0;
 
318
        }
 
319
 
 
320
 
 
321
        /** Receive timeout control */
 
322
        protected int timeout;
 
323
 
 
324
        /** 
 
325
        *  @return  int the timeout
 
326
        */
 
327
        public native int NativegetReceiveTimeout();
 
328
        /** 
 
329
        *  @return  bloolean true if recieve timeout is enabled
 
330
        */
 
331
        private native boolean NativeisReceiveTimeoutEnabled();
 
332
        /** 
 
333
        *  @param  time
 
334
        *  @param  threshold
 
335
        *  @param  InputBuffer
 
336
        */
 
337
        private native void NativeEnableReceiveTimeoutThreshold(int time,
 
338
                int threshold,int InputBuffer);
 
339
        /** 
 
340
        */
 
341
        public void disableReceiveTimeout()
 
342
        {
 
343
                if (debug)
 
344
                        z.reportln( "RXTXPort:disableReceiveTimeout() called");
 
345
                timeout = -1;
 
346
                NativeEnableReceiveTimeoutThreshold( timeout , threshold, InputBuffer );
 
347
                if (debug)
 
348
                        z.reportln( "RXTXPort:disableReceiveTimeout() returning");
 
349
        }
 
350
        /** 
 
351
        *  @param time
 
352
        */
 
353
        public void enableReceiveTimeout( int time )
 
354
        {
 
355
                if (debug)
 
356
                        z.reportln( "RXTXPort:enableReceiveTimeout() called");
 
357
                if( time >= 0 )
 
358
                {
 
359
                        timeout = time;
 
360
                        NativeEnableReceiveTimeoutThreshold( time , threshold,
 
361
                                InputBuffer );
 
362
                }
 
363
                else
 
364
                {
 
365
                        throw new IllegalArgumentException
 
366
                        (
 
367
                                "Unexpected negative timeout value"
 
368
                        );
 
369
                }
 
370
                if (debug)
 
371
                        z.reportln( "RXTXPort:enableReceiveTimeout() returning");
 
372
        }
 
373
        /** 
 
374
        *  @return  boolean true if recieve timeout is enabled
 
375
        */
 
376
        public boolean isReceiveTimeoutEnabled()
 
377
        {
 
378
                if (debug)
 
379
                        z.reportln( "RXTXPort:isReceiveTimeoutEnabled() called and returning " + NativeisReceiveTimeoutEnabled() );
 
380
                return( NativeisReceiveTimeoutEnabled() );
 
381
        }
 
382
        /** 
 
383
        *  @return  int the timeout
 
384
        */
 
385
        public int getReceiveTimeout()
 
386
        {
 
387
                if (debug)
 
388
                        z.reportln( "RXTXPort:getReceiveTimeout() called and returning " + NativegetReceiveTimeout() );
 
389
                return(NativegetReceiveTimeout( ));
 
390
        }
 
391
 
 
392
        /** Receive threshold control */
 
393
 
 
394
        private int threshold = 0;
 
395
 
 
396
        /** 
 
397
        *  @param thresh threshold
 
398
        */
 
399
        public void enableReceiveThreshold( int thresh )
 
400
        {
 
401
                if (debug)
 
402
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) called");
 
403
                if(thresh >=0)
 
404
                {
 
405
                        threshold=thresh;
 
406
                        NativeEnableReceiveTimeoutThreshold(timeout, threshold,
 
407
                                InputBuffer);
 
408
                }
 
409
                else /* invalid thresh */
 
410
                {
 
411
                        throw new IllegalArgumentException
 
412
                        (
 
413
                                "Unexpected negative threshold value"
 
414
                        );
 
415
                }
 
416
                if (debug)
 
417
                        z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) returned");
 
418
        }
 
419
        /** 
 
420
        */
 
421
        public void disableReceiveThreshold()
 
422
        {
 
423
                if (debug)
 
424
                        z.reportln( "RXTXPort:disableReceiveThreshold() called and returning");
 
425
                enableReceiveThreshold(0);
 
426
        }
 
427
        /** 
 
428
        *  @return  int the recieve threshold
 
429
        */
 
430
        public int getReceiveThreshold()
 
431
        {
 
432
                if (debug)
 
433
                        z.reportln( "RXTXPort:getReceiveThreshold() called and returning " + threshold);
 
434
                return threshold;
 
435
        }
 
436
        /** 
 
437
        *  @return  boolean true if receive threshold is enabled
 
438
        */
 
439
        public boolean isReceiveThresholdEnabled()
 
440
        {
 
441
                if (debug)
 
442
                        z.reportln( "RXTXPort:isReceiveThresholdEnable() called and returning" + (threshold > 0) );
 
443
                return(threshold>0);
 
444
        }
 
445
 
 
446
        /** Input/output buffers */
 
447
        /** FIXME I think this refers to
 
448
                FOPEN(3)/SETBUF(3)/FREAD(3)/FCLOSE(3)
 
449
                taj@www.linux.org.uk
 
450
 
 
451
                These are native stubs...
 
452
        */
 
453
        private int InputBuffer=0;
 
454
        private int OutputBuffer=0;
 
455
        /** 
 
456
        *  @param size
 
457
        */
 
458
        public void setInputBufferSize( int size )
 
459
        {
 
460
                if (debug)
 
461
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
462
                                        size + ") called");
 
463
                if( size < 0 )
 
464
                        throw new IllegalArgumentException
 
465
                        (
 
466
                                "Unexpected negative buffer size value"
 
467
                        );
 
468
                else InputBuffer=size;
 
469
                if (debug)
 
470
                        z.reportln( "RXTXPort:setInputBufferSize( " +
 
471
                                        size + ") returning");
 
472
        }
 
473
        /** 
 
474
        */
 
475
        public int getInputBufferSize()
 
476
        {
 
477
                if (debug)
 
478
                        z.reportln( "RXTXPort:getInputBufferSize() called and returning " + InputBuffer );
 
479
                return(InputBuffer);
 
480
        }
 
481
        /** 
 
482
        *  @param size
 
483
        */
 
484
        public void setOutputBufferSize( int size )
 
485
        {
 
486
                if (debug)
 
487
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
488
                                        size + ") called");
 
489
                if( size < 0 )
 
490
                        throw new IllegalArgumentException
 
491
                        (
 
492
                                "Unexpected negative buffer size value"
 
493
                        );
 
494
                else OutputBuffer=size;
 
495
                if (debug)
 
496
                        z.reportln( "RXTXPort:setOutputBufferSize( " +
 
497
                                        size + ") returned");
 
498
                
 
499
        }
 
500
        /** 
 
501
        *  @return  in the output buffer size
 
502
        */
 
503
        public int getOutputBufferSize()
 
504
        {
 
505
                if (debug)
 
506
                        z.reportln( "RXTXPort:getOutputBufferSize() called and returning " + OutputBuffer );
 
507
                return(OutputBuffer);
 
508
        }
 
509
 
 
510
        /* =================== cleaned messages to here */
 
511
 
 
512
        /**
 
513
        *  Line status methods
 
514
        */
 
515
        /**
 
516
        *  @returns true if DTR is set
 
517
        */
 
518
        public native boolean isDTR();
 
519
        /** 
 
520
        *  @param state
 
521
        */
 
522
        public native void setDTR( boolean state );
 
523
        /** 
 
524
        *  @param state
 
525
        */
 
526
        public native void setRTS( boolean state );
 
527
        private native void setDSR( boolean state );
 
528
        /** 
 
529
        *  @return boolean true if CTS is set
 
530
        */
 
531
        public native boolean isCTS();
 
532
        /** 
 
533
        *  @return boolean true if DSR is set
 
534
        */
 
535
        public native boolean isDSR();
 
536
        /** 
 
537
        *  @return boolean true if CD is set
 
538
        */
 
539
        public native boolean isCD();
 
540
        /** 
 
541
        *  @return boolean true if RI is set
 
542
        */
 
543
        public native boolean isRI();
 
544
        /** 
 
545
        *  @return boolean true if RTS is set
 
546
        */
 
547
        public native boolean isRTS();
 
548
 
 
549
 
 
550
        /**
 
551
        *  Write to the port
 
552
        *  @param duration
 
553
        */
 
554
        public native void sendBreak( int duration );
 
555
        protected native void writeByte( int b, boolean i ) throws IOException;
 
556
        protected native void writeArray( byte b[], int off, int len, boolean i )
 
557
                throws IOException;
 
558
        protected native boolean nativeDrain( boolean i ) throws IOException;
 
559
 
 
560
        /** RXTXPort read methods */
 
561
        protected native int nativeavailable() throws IOException;
 
562
        protected native int readByte() throws IOException;
 
563
        protected native int readArray( byte b[], int off, int len )
 
564
                throws IOException;
 
565
 
 
566
 
 
567
        /** Serial Port Event listener */
 
568
        private SerialPortEventListener SPEventListener;
 
569
 
 
570
        /** Thread to monitor data */
 
571
        private MonitorThread monThread;
 
572
 
 
573
        /** Process SerialPortEvents */
 
574
        native void eventLoop();
 
575
 
 
576
        /** 
 
577
        *  @return boolean  true if monitor thread is interrupted
 
578
        */
 
579
        boolean monThreadisInterrupted=true;
 
580
        private native void interruptEventLoop( );
 
581
        public boolean checkMonitorThread()
 
582
        {
 
583
                if (debug)
 
584
                        z.reportln( "RXTXPort:checkMonitorThread()");
 
585
                if(monThread != null)
 
586
                {
 
587
                        if ( debug )
 
588
                                z.reportln( 
 
589
                                        "monThreadisInterrupted = " +
 
590
                                        monThreadisInterrupted );
 
591
                        return monThreadisInterrupted;
 
592
                }
 
593
                if ( debug )
 
594
                        z.reportln(  "monThread is null " );
 
595
                return(true);
 
596
        }
 
597
 
 
598
        /** 
 
599
        *  @param event
 
600
        *  @param state
 
601
        *  @return boolean true if the port is closing
 
602
        */
 
603
        public boolean sendEvent( int event, boolean state )
 
604
        {
 
605
                if (debug_events)
 
606
                        z.report( "RXTXPort:sendEvent(");
 
607
                /* Let the native side know its time to die */
 
608
 
 
609
                if ( fd == 0 || SPEventListener == null || monThread == null)
 
610
                {
 
611
                        return(true);
 
612
                }
 
613
 
 
614
                switch( event )
 
615
                {
 
616
                        case SerialPortEvent.DATA_AVAILABLE:
 
617
                                if( debug_events )
 
618
                                        z.reportln( "DATA_AVAILABLE " +
 
619
                                                monThread.Data + ")" );
 
620
                                break;
 
621
                        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
 
622
                                if( debug_events )
 
623
                                        z.reportln( 
 
624
                                                "OUTPUT_BUFFER_EMPTY " +
 
625
                                                monThread.Output + ")" );
 
626
                                break;
 
627
                        case SerialPortEvent.CTS:
 
628
                                if( debug_events )
 
629
                                        z.reportln( "CTS " +
 
630
                                                monThread.CTS + ")" );
 
631
                                break;
 
632
                        case SerialPortEvent.DSR:
 
633
                                if( debug_events )
 
634
                                        z.reportln( "DSR " +
 
635
                                                monThread.Output + ")" );
 
636
                                break;
 
637
                        case SerialPortEvent.RI:
 
638
                                if( debug_events )
 
639
                                        z.reportln( "RI " +
 
640
                                                monThread.RI + ")" );
 
641
                                break;
 
642
                        case SerialPortEvent.CD:
 
643
                                if( debug_events )
 
644
                                        z.reportln( "CD " +
 
645
                                                monThread.CD + ")" );
 
646
                                break;
 
647
                        case SerialPortEvent.OE:
 
648
                                if( debug_events )
 
649
                                        z.reportln( "OE " +
 
650
                                                monThread.OE + ")" );
 
651
                                break;
 
652
                        case SerialPortEvent.PE:
 
653
                                if( debug_events )
 
654
                                        z.reportln( "PE " +
 
655
                                                monThread.PE + ")" );
 
656
                                break;
 
657
                        case SerialPortEvent.FE:
 
658
                                if( debug_events )
 
659
                                        z.reportln( "FE " +
 
660
                                                monThread.FE + ")" );
 
661
                                break;
 
662
                        case SerialPortEvent.BI:
 
663
                                if( debug_events )
 
664
                                        z.reportln( "BI " +
 
665
                                                monThread.BI + ")" );
 
666
                                break;
 
667
                        default:
 
668
                                if( debug_events )
 
669
                                        z.reportln( "XXXXXXXXXXXXXX " +
 
670
                                                event + ")" );
 
671
                                break;
 
672
                }
 
673
                if( debug_events && debug_verbose )
 
674
                        z.reportln(  "  checking flags " );
 
675
 
 
676
                switch( event )
 
677
                {
 
678
                        case SerialPortEvent.DATA_AVAILABLE:
 
679
                                if( monThread.Data ) break;
 
680
                                return(false);
 
681
                        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
 
682
                                if( monThread.Output ) break;
 
683
                                return(false);
 
684
                        case SerialPortEvent.CTS:
 
685
                                if( monThread.CTS ) break;
 
686
                                return(false);
 
687
                        case SerialPortEvent.DSR:
 
688
                                if( monThread.DSR ) break;
 
689
                                return(false);
 
690
                        case SerialPortEvent.RI:
 
691
                                if( monThread.RI ) break;
 
692
                                return(false);
 
693
                        case SerialPortEvent.CD:
 
694
                                if( monThread.CD ) break;
 
695
                                return(false);
 
696
                        case SerialPortEvent.OE:
 
697
                                if( monThread.OE ) break;
 
698
                                return(false);
 
699
                        case SerialPortEvent.PE:
 
700
                                if( monThread.PE ) break;
 
701
                                return(false);
 
702
                        case SerialPortEvent.FE:
 
703
                                if( monThread.FE ) break;
 
704
                                return(false);
 
705
                        case SerialPortEvent.BI:
 
706
                                if( monThread.BI ) break;
 
707
                                return(false);
 
708
                        default:
 
709
                                System.err.println( "unknown event: " + event);
 
710
                                return(false);
 
711
                }
 
712
                if( debug_events && debug_verbose )
 
713
                        z.reportln(  "  getting event" );
 
714
                SerialPortEvent e = new SerialPortEvent(this, event, !state,
 
715
                        state );
 
716
                if( debug_events && debug_verbose )
 
717
                        z.reportln(  "  sending event" );
 
718
                if(monThreadisInterrupted) 
 
719
                {
 
720
                        if( debug_events )
 
721
                                z.reportln(  "  sendEvent return" );
 
722
                        return(true);
 
723
                }
 
724
                if( SPEventListener != null )
 
725
                {
 
726
                        SPEventListener.serialEvent( e );
 
727
                }
 
728
 
 
729
                if( debug_events && debug_verbose )
 
730
                        z.reportln(  "  sendEvent return" );
 
731
 
 
732
                if (fd == 0 ||  SPEventListener == null || monThread == null) 
 
733
                {
 
734
                        return(true);
 
735
                }
 
736
                else 
 
737
                {
 
738
                        return(false);  
 
739
                }
 
740
        }
 
741
 
 
742
        /**
 
743
        *  Add an event listener
 
744
        *  @param lsnr SerialPortEventListener
 
745
        *  @throws TooManyListenersException
 
746
        */
 
747
 
 
748
        boolean MonitorThreadLock = true;
 
749
        boolean MonitorThreadCloseLock = true;
 
750
 
 
751
        public void addEventListener(
 
752
                SerialPortEventListener lsnr ) throws TooManyListenersException
 
753
        {
 
754
                /*  Don't let and notification requests happen until the
 
755
                    Eventloop is ready
 
756
                */
 
757
 
 
758
                if (debug)
 
759
                        z.reportln( "RXTXPort:addEventListener()");
 
760
                if( SPEventListener != null )
 
761
                {
 
762
                        throw new TooManyListenersException();
 
763
                }
 
764
                SPEventListener = lsnr;
 
765
                if( !MonitorThreadAlive )
 
766
                {
 
767
                        MonitorThreadLock = true;
 
768
                        monThread = new MonitorThread();
 
769
                        monThread.start();
 
770
                        waitForTheNativeCodeSilly();
 
771
                        MonitorThreadAlive=true;
 
772
                }
 
773
                if (debug)
 
774
                        z.reportln( "RXTXPort:Interrupt=false");
 
775
        }
 
776
        /**
 
777
        *  Remove the serial port event listener
 
778
        */
 
779
        public void removeEventListener()
 
780
        {
 
781
                if (debug)
 
782
                        z.reportln( "RXTXPort:removeEventListener() called");
 
783
                waitForTheNativeCodeSilly();
 
784
                //if( monThread != null && monThread.isAlive() )
 
785
                if( monThreadisInterrupted == true )
 
786
                {
 
787
                        z.reportln( "   RXTXPort:removeEventListener() already interrupted");
 
788
                        monThread = null;
 
789
                        SPEventListener = null;
 
790
                        Runtime.getRuntime().gc();
 
791
                        return;
 
792
                }
 
793
                else if( monThread != null && monThread.isAlive() )
 
794
                {
 
795
                        if (debug)
 
796
                                z.reportln( "   RXTXPort:Interrupt=true");
 
797
                        monThreadisInterrupted=true;
 
798
                        /*
 
799
                           Notify all threads in this PID that something is up
 
800
                           They will call back to see if its their thread
 
801
                           using isInterrupted().
 
802
                        */
 
803
                        MonitorThreadCloseLock = true;
 
804
                        if (debug)
 
805
                                z.reportln( "   RXTXPort:calling interruptEventLoop");
 
806
                        interruptEventLoop( );
 
807
                        if (debug)
 
808
                                z.reportln("    RXTXPort:waiting on closelock");
 
809
                        while( MonitorThreadCloseLock )
 
810
                        {
 
811
                                if (debug)
 
812
                                        z.reportln("    .");
 
813
                                try {
 
814
                                        Thread.sleep(100);
 
815
                                } catch( Exception e ) {}
 
816
                        }
 
817
                        if (debug)
 
818
                                z.reportln("    RXTXPort:set closelock");
 
819
                        if (debug)
 
820
                                z.reportln( "   RXTXPort:calling monThread.join()");
 
821
                        try {
 
822
                                monThread.join(1000);
 
823
                        } catch (Exception ex) {
 
824
                                /* yikes */
 
825
                                ex.printStackTrace();
 
826
                        }
 
827
                        if (debug)
 
828
                                z.reportln( "   RXTXPort:waiting on isAlive()");
 
829
                        while( monThread.isAlive() )
 
830
                        {
 
831
                                if ( debug )
 
832
                                        z.reportln( "   MonThread is still alive!");
 
833
                                try {
 
834
                                        monThread.join(1000);
 
835
                                        Thread.sleep( 1000 );
 
836
                                } catch( Exception e ){} 
 
837
                                //monThread.stop();
 
838
                        }
 
839
                        
 
840
                }
 
841
                if (debug)
 
842
                        z.reportln( "   RXTXPort:calling gc()");
 
843
                monThread = null;
 
844
                SPEventListener = null;
 
845
                Runtime.getRuntime().gc();
 
846
                MonitorThreadLock = false;
 
847
                MonitorThreadAlive=false;
 
848
                if (debug)
 
849
                  z.reportln( "RXTXPort:removeEventListener() returning");
 
850
        }
 
851
        /**
 
852
         *      Give the native code a chance to start listening to the hardware
 
853
         *      or should we say give the native code control of the issue.
 
854
         *
 
855
         *      This is important for applications that flicker the Monitor
 
856
         *      thread while keeping the port open.
 
857
         *      In worst case test cases this loops once or twice every time.
 
858
         */
 
859
 
 
860
        protected void waitForTheNativeCodeSilly()
 
861
        {
 
862
                while( MonitorThreadLock )
 
863
                {
 
864
                        try {
 
865
                                Thread.sleep(100);
 
866
                        } catch( Exception e ) {}
 
867
                }
 
868
        }
 
869
        /**
 
870
        *  @param enable
 
871
        */
 
872
        private native void nativeSetEventFlag( int fd, int event,
 
873
                                                boolean flag );
 
874
        public void notifyOnDataAvailable( boolean enable )
 
875
        {
 
876
                if (debug)
 
877
                        z.reportln( "RXTXPort:notifyOnDataAvailable( " +
 
878
                                enable+" )");
 
879
                
 
880
                waitForTheNativeCodeSilly();
 
881
 
 
882
                MonitorThreadLock = true;
 
883
                nativeSetEventFlag( fd, SerialPortEvent.DATA_AVAILABLE,
 
884
                                        enable );
 
885
                monThread.Data = enable;
 
886
                MonitorThreadLock = false;
 
887
        }
 
888
 
 
889
        /**
 
890
        *  @param enable
 
891
        */
 
892
        public void notifyOnOutputEmpty( boolean enable )
 
893
        {
 
894
                if (debug)
 
895
                        z.reportln( "RXTXPort:notifyOnOutputEmpty( " +
 
896
                                enable+" )");
 
897
                waitForTheNativeCodeSilly();
 
898
                MonitorThreadLock = true;
 
899
                nativeSetEventFlag( fd, SerialPortEvent.OUTPUT_BUFFER_EMPTY,
 
900
                                        enable );
 
901
                monThread.Output = enable;
 
902
                MonitorThreadLock = false;
 
903
        }
 
904
 
 
905
        /**
 
906
        *  @param enable
 
907
        */
 
908
        public void notifyOnCTS( boolean enable )
 
909
        {
 
910
                if (debug)
 
911
                        z.reportln( "RXTXPort:notifyOnCTS( " +
 
912
                                enable+" )");
 
913
                waitForTheNativeCodeSilly();
 
914
                MonitorThreadLock = true;
 
915
                nativeSetEventFlag( fd, SerialPortEvent.CTS, enable );
 
916
                monThread.CTS = enable;
 
917
                MonitorThreadLock = false;
 
918
        }
 
919
        /**
 
920
        *  @param enable
 
921
        */
 
922
        public void notifyOnDSR( boolean enable )
 
923
        {
 
924
                if (debug)
 
925
                        z.reportln( "RXTXPort:notifyOnDSR( " +
 
926
                                enable+" )");
 
927
                waitForTheNativeCodeSilly();
 
928
                MonitorThreadLock = true;
 
929
                nativeSetEventFlag( fd, SerialPortEvent.DSR, enable );
 
930
                monThread.DSR = enable;
 
931
                MonitorThreadLock = false;
 
932
        }
 
933
        /**
 
934
        *  @param enable
 
935
        */
 
936
        public void notifyOnRingIndicator( boolean enable )
 
937
        {
 
938
                if (debug)
 
939
                        z.reportln( "RXTXPort:notifyOnRingIndicator( " +
 
940
                                enable+" )");
 
941
                waitForTheNativeCodeSilly();
 
942
                MonitorThreadLock = true;
 
943
                nativeSetEventFlag( fd, SerialPortEvent.RI, enable );
 
944
                monThread.RI = enable;
 
945
                MonitorThreadLock = false;
 
946
        }
 
947
        /**
 
948
        *  @param enable
 
949
        */
 
950
        public void notifyOnCarrierDetect( boolean enable )
 
951
        {
 
952
                if (debug)
 
953
                        z.reportln( "RXTXPort:notifyOnCarrierDetect( " +
 
954
                                enable+" )");
 
955
                waitForTheNativeCodeSilly();
 
956
                MonitorThreadLock = true;
 
957
                nativeSetEventFlag( fd, SerialPortEvent.CD, enable );
 
958
                monThread.CD = enable;
 
959
                MonitorThreadLock = false;
 
960
        }
 
961
        /**
 
962
        *  @param enable
 
963
        */
 
964
        public void notifyOnOverrunError( boolean enable )
 
965
        {
 
966
                if (debug)
 
967
                        z.reportln( "RXTXPort:notifyOnOverrunError( " +
 
968
                                enable+" )");
 
969
                waitForTheNativeCodeSilly();
 
970
                MonitorThreadLock = true;
 
971
                nativeSetEventFlag( fd, SerialPortEvent.OE, enable );
 
972
                monThread.OE = enable;
 
973
                MonitorThreadLock = false;
 
974
        }
 
975
        /**
 
976
        *  @param enable
 
977
        */
 
978
        public void notifyOnParityError( boolean enable )
 
979
        {
 
980
                if (debug)
 
981
                        z.reportln( "RXTXPort:notifyOnParityError( " +
 
982
                                enable+" )");
 
983
                waitForTheNativeCodeSilly();
 
984
                MonitorThreadLock = true;
 
985
                nativeSetEventFlag( fd, SerialPortEvent.PE, enable );
 
986
                monThread.PE = enable;
 
987
                MonitorThreadLock = false;
 
988
        }
 
989
        /**
 
990
        *  @param enable
 
991
        */
 
992
        public void notifyOnFramingError( boolean enable )
 
993
        {
 
994
                if (debug)
 
995
                        z.reportln( "RXTXPort:notifyOnFramingError( " +
 
996
                                enable+" )");
 
997
                waitForTheNativeCodeSilly();
 
998
                MonitorThreadLock = true;
 
999
                nativeSetEventFlag( fd, SerialPortEvent.FE, enable );
 
1000
                monThread.FE = enable;
 
1001
                MonitorThreadLock = false;
 
1002
        }
 
1003
        /**
 
1004
        *  @param enable
 
1005
        */
 
1006
        public void notifyOnBreakInterrupt( boolean enable )
 
1007
        {
 
1008
                if (debug)
 
1009
                        z.reportln( "RXTXPort:notifyOnBreakInterrupt( " +
 
1010
                                enable+" )");
 
1011
                waitForTheNativeCodeSilly();
 
1012
                MonitorThreadLock = true;
 
1013
                nativeSetEventFlag( fd, SerialPortEvent.BI, enable );
 
1014
                monThread.BI = enable;
 
1015
                MonitorThreadLock = false;
 
1016
        }
 
1017
 
 
1018
        /** Close the port */
 
1019
        private native void nativeClose( String name );
 
1020
        /**
 
1021
        */
 
1022
        boolean closeLock = false;
 
1023
        public synchronized void close()
 
1024
        {
 
1025
                if (debug)
 
1026
                        z.reportln( "RXTXPort:close( " + this.name + " )"); 
 
1027
                if( closeLock ) return;
 
1028
                closeLock = true;
 
1029
                if ( fd <= 0 )
 
1030
                {
 
1031
                        z.reportln(  "RXTXPort:close detected bad File Descriptor" );
 
1032
                        return;
 
1033
                }
 
1034
                setDTR(false);
 
1035
                setDSR(false);
 
1036
                if (debug)
 
1037
                        z.reportln( "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted"); 
 
1038
                if ( ! monThreadisInterrupted )
 
1039
                {
 
1040
                        removeEventListener();
 
1041
                }
 
1042
                if (debug)
 
1043
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling nativeClose"); 
 
1044
                nativeClose( this.name );
 
1045
                if (debug)
 
1046
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling super.close"); 
 
1047
                super.close();
 
1048
                if (debug)
 
1049
                        z.reportln( "RXTXPort:close( " + this.name + " ) calling System.gc"); 
 
1050
 
 
1051
                fd = 0;
 
1052
                Runtime.getRuntime().gc();
 
1053
                closeLock = false;
 
1054
                if (debug)
 
1055
                        z.reportln( "RXTXPort:close( " + this.name + " ) leaving"); 
 
1056
        }
 
1057
 
 
1058
 
 
1059
        /** Finalize the port */
 
1060
        protected void finalize()
 
1061
        {
 
1062
                if (debug)
 
1063
                        z.reportln( "RXTXPort:finalize()");
 
1064
                if( fd > 0 ) close();
 
1065
                z.finalize();
 
1066
        }
 
1067
 
 
1068
        /** Inner class for SerialOutputStream */
 
1069
        class SerialOutputStream extends OutputStream
 
1070
        {
 
1071
        /**
 
1072
        *  @param b
 
1073
        *  @throws IOException
 
1074
        */
 
1075
                public void write( int b ) throws IOException
 
1076
                {
 
1077
                        if (debug_write)
 
1078
                                z.reportln( "RXTXPort:SerialOutputStream:write(int)");
 
1079
                        if( speed == 0 ) return;
 
1080
        /* hmm this turns out to be a very bad idea
 
1081
                        if ( monThreadisInterrupted == true )
 
1082
                        {
 
1083
                                throw new IOException( "Port has been Closed" );
 
1084
                        }
 
1085
        */
 
1086
                        waitForTheNativeCodeSilly();
 
1087
                        if ( fd == 0 ) throw new IOException();
 
1088
                        writeByte( b, monThreadisInterrupted );
 
1089
                        if (debug_write)
 
1090
                                z.reportln( "Leaving RXTXPort:SerialOutputStream:write( int )");
 
1091
                }
 
1092
        /**
 
1093
        *  @param b[]
 
1094
        *  @throws IOException
 
1095
        */
 
1096
                public void write( byte b[] ) throws IOException
 
1097
                {
 
1098
                        if (debug_write)
 
1099
                        {
 
1100
                                z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
 
1101
                        }
 
1102
                        if( speed == 0 ) return;
 
1103
        /* hmm this turns out to be a very bad idea
 
1104
                        if ( monThreadisInterrupted == true )
 
1105
                        {
 
1106
                                throw new IOException( "Port has been Closed" );
 
1107
                        }
 
1108
        */
 
1109
                        if ( fd == 0 ) throw new IOException();
 
1110
                        waitForTheNativeCodeSilly();
 
1111
                        writeArray( b, 0, b.length, monThreadisInterrupted );
 
1112
                        if (debug_write)
 
1113
                                z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" +b.length  +")");
 
1114
                }
 
1115
        /**
 
1116
        *  @param b[]
 
1117
        *  @param off
 
1118
        *  @param len
 
1119
        *  @throws IOException
 
1120
        */
 
1121
                public void write( byte b[], int off, int len )
 
1122
                        throws IOException
 
1123
                {
 
1124
                        if( speed == 0 ) return;
 
1125
                        if( off + len  > b.length )
 
1126
                        {
 
1127
                                throw new IndexOutOfBoundsException(
 
1128
                                        "Invalid offset/length passed to read"
 
1129
                                );
 
1130
                        }
 
1131
         
 
1132
                        byte send[] = new byte[len];
 
1133
                        System.arraycopy( b, off, send, 0, len );
 
1134
                        if (debug_write)
 
1135
                        {
 
1136
                                z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+  new String(send) */ );
 
1137
                        }
 
1138
                        if ( fd == 0 ) throw new IOException();
 
1139
        /* hmm this turns out to be a very bad idea
 
1140
                        if ( monThreadisInterrupted == true )
 
1141
                        {
 
1142
                                throw new IOException( "Port has been Closed" );
 
1143
                        }
 
1144
        */
 
1145
                        waitForTheNativeCodeSilly();
 
1146
                        writeArray( send, 0, len, monThreadisInterrupted );
 
1147
                        if( debug_write )
 
1148
                                z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") "  /*+ new String(send)*/ );
 
1149
                }
 
1150
        /**
 
1151
        */
 
1152
                public void flush() throws IOException
 
1153
                {
 
1154
                        if (debug)
 
1155
                                z.reportln( "RXTXPort:SerialOutputStream:flush() enter");
 
1156
                        if( speed == 0 ) return;
 
1157
                        if ( fd == 0 ) throw new IOException();
 
1158
        /* hmm this turns out to be a very bad idea
 
1159
                        if ( monThreadisInterrupted == true )
 
1160
                        {
 
1161
                                return;
 
1162
                                // FIXME Trent this breaks
 
1163
                                //throw new IOException( "flush() Port has been Closed" );
 
1164
                        }
 
1165
        */
 
1166
                        waitForTheNativeCodeSilly();
 
1167
                        /* 
 
1168
                           this is probably good on all OS's but for now
 
1169
                           just sendEvent from java on Sol
 
1170
                        */
 
1171
                        if ( nativeDrain( monThreadisInterrupted ) )
 
1172
                                sendEvent( SerialPortEvent.OUTPUT_BUFFER_EMPTY, true );
 
1173
                        if (debug)
 
1174
                                z.reportln( "RXTXPort:SerialOutputStream:flush() leave");
 
1175
                }
 
1176
        }
 
1177
 
 
1178
        /** Inner class for SerialInputStream */
 
1179
        class SerialInputStream extends InputStream
 
1180
        {
 
1181
        /**
 
1182
        *  @return int the int read
 
1183
        *  @throws IOException
 
1184
        *  @see java.io.InputStream
 
1185
*
 
1186
*timeout threshold       Behavior
 
1187
*------------------------------------------------------------------------
 
1188
*0       0       blocks until 1 byte is available timeout > 0,
 
1189
*                threshold = 0, blocks until timeout occurs, returns -1
 
1190
*                on timeout
 
1191
*>0      >0      blocks until timeout, returns - 1 on timeout, magnitude
 
1192
*                of threshold doesn't play a role.
 
1193
*0       >0      Blocks until 1 byte, magnitude of  threshold doesn't
 
1194
*                play a role
 
1195
        */
 
1196
                public synchronized int read() throws IOException
 
1197
                {
 
1198
                        if (debug_read)
 
1199
                                z.reportln( "RXTXPort:SerialInputStream:read() called");
 
1200
                        if ( fd == 0 ) throw new IOException();
 
1201
                        waitForTheNativeCodeSilly();
 
1202
                        if ( monThreadisInterrupted )
 
1203
                                z.reportln( "+++++++++ read() monThreadisInterrupted" );
 
1204
                        int result = readByte();
 
1205
                        if (debug_read_results)
 
1206
                                z.reportln(  "RXTXPort:SerialInputStrea:read() returns byte = " + result );
 
1207
                        return( result );
 
1208
                }
 
1209
        /**
 
1210
        *  @param b[]
 
1211
        *  @return int  number of bytes read
 
1212
        *  @throws IOException
 
1213
*
 
1214
*timeout threshold       Behavior
 
1215
*------------------------------------------------------------------------
 
1216
*0       0       blocks until 1 byte is available
 
1217
*>0      0       blocks until timeout occurs, returns 0 on timeout
 
1218
*>0      >0      blocks until timeout or reads threshold bytes,
 
1219
                 returns 0 on timeout
 
1220
*0       >0      blocks until reads threshold bytes
 
1221
        */
 
1222
                public synchronized int read( byte b[] ) throws IOException
 
1223
                {
 
1224
                        int result;
 
1225
                        if (debug_read)
 
1226
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + ") called");
 
1227
        /* hmm this turns out to be a very bad idea
 
1228
                        if ( monThreadisInterrupted == true )
 
1229
                        {
 
1230
                                throw new IOException( "Port has been Closed" );
 
1231
                        }
 
1232
        */
 
1233
                        waitForTheNativeCodeSilly();
 
1234
                        result = read( b, 0, b.length);
 
1235
                        if (debug_read_results)
 
1236
                                z.reportln(  "RXTXPort:SerialInputStream:read() returned " + result + " bytes" );
 
1237
                        return( result );
 
1238
                }
 
1239
/*
 
1240
read(byte b[], int, int)
 
1241
Documentation is at http://java.sun.com/products/jdk/1.2/docs/api/java/io/InputStream.html#read(byte[], int, int)
 
1242
*/
 
1243
        /**
 
1244
        *  @param b[]
 
1245
        *  @param off
 
1246
        *  @param len
 
1247
        *  @return int  number of bytes read
 
1248
        *  @throws IOException
 
1249
*
 
1250
*timeout threshold       Behavior
 
1251
*------------------------------------------------------------------------
 
1252
*0       0       blocks until 1 byte is available
 
1253
*>0      0       blocks until timeout occurs, returns 0 on timeout
 
1254
*>0      >0      blocks until timeout or reads threshold bytes,
 
1255
                 returns 0 on timeout
 
1256
*0       >0      blocks until either threshold # of bytes or len bytes,
 
1257
                 whichever was lower.
 
1258
        */
 
1259
                public synchronized int read( byte b[], int off, int len )
 
1260
                        throws IOException
 
1261
                {
 
1262
                        if (debug_read)
 
1263
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
 
1264
                        int result;
 
1265
                        /*
 
1266
                         * Some sanity checks
 
1267
                         */
 
1268
                        if ( fd == 0 )
 
1269
                        {
 
1270
                                z.reportln("+++++++ IOException()\n");
 
1271
                                throw new IOException();
 
1272
                        }
 
1273
 
 
1274
                        if( b==null )
 
1275
                        {
 
1276
                                z.reportln("+++++++ NullPointerException()\n");
 
1277
                                throw new NullPointerException();
 
1278
                        }
 
1279
 
 
1280
                        if( (off < 0) || (len < 0) || (off+len > b.length))
 
1281
                        {
 
1282
                                z.reportln("+++++++ IndexOutOfBoundsException()\n");
 
1283
                                throw new IndexOutOfBoundsException();
 
1284
                        }
 
1285
 
 
1286
                        /*
 
1287
                         * Return immediately if len==0
 
1288
                         */
 
1289
                        if( len==0 ) return 0;
 
1290
 
 
1291
                        /*
 
1292
                         * See how many bytes we should read
 
1293
                         */
 
1294
                        int Minimum = len;
 
1295
 
 
1296
                        if( threshold==0 )
 
1297
                        {
 
1298
                        /*
 
1299
                         * If threshold is disabled, read should return as soon
 
1300
                         * as data are available (up to the amount of available
 
1301
                         * bytes in order to avoid blocking)
 
1302
                         * Read may return earlier depending of the receive time
 
1303
                         * out.
 
1304
                         */
 
1305
                                int a = nativeavailable();
 
1306
                                if( a == 0 )
 
1307
                                        Minimum = 1;
 
1308
                                else
 
1309
                                        Minimum = Math.min( Minimum, a );
 
1310
                        }
 
1311
                        else
 
1312
                        {
 
1313
                        /*
 
1314
                         * Threshold is enabled. Read should return when
 
1315
                         * 'threshold' bytes have been received (or when the
 
1316
                         * receive timeout expired)
 
1317
                         */
 
1318
                                Minimum = Math.min(Minimum, threshold);
 
1319
                        }
 
1320
        /* hmm this turns out to be a very bad idea
 
1321
                        if ( monThreadisInterrupted == true )
 
1322
                        {
 
1323
                                throw new IOException( "Port has been Closed" );
 
1324
                        }
 
1325
        */
 
1326
                        waitForTheNativeCodeSilly();
 
1327
                        result = readArray( b, off, Minimum);
 
1328
                        if (debug_read_results)
 
1329
                                z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes"  /*+ new String(b) */);
 
1330
                        return( result );
 
1331
                }
 
1332
        /**
 
1333
        *  @return int bytes available
 
1334
        *  @throws IOException
 
1335
        */
 
1336
                public synchronized int available() throws IOException
 
1337
                {
 
1338
        /* hmm this turns out to be a very bad idea
 
1339
                        if ( monThreadisInterrupted == true )
 
1340
                        {
 
1341
                                throw new IOException( "Port has been Closed" );
 
1342
                        }
 
1343
        */
 
1344
                        if ( debug_verbose )
 
1345
                                z.reportln( "RXTXPort:available() called" );
 
1346
                        int r = nativeavailable();
 
1347
                        if ( debug_verbose )
 
1348
                                z.reportln( "RXTXPort:available() returning " +
 
1349
                                        r );
 
1350
                        return r;
 
1351
                }
 
1352
        }
 
1353
        /**
 
1354
        */
 
1355
        class MonitorThread extends Thread
 
1356
        {
 
1357
        /** Note: these have to be separate boolean flags because the
 
1358
           SerialPortEvent constants are NOT bit-flags, they are just
 
1359
           defined as integers from 1 to 10  -DPL */
 
1360
                private volatile boolean CTS=false;
 
1361
                private volatile boolean DSR=false;
 
1362
                private volatile boolean RI=false;
 
1363
                private volatile boolean CD=false;
 
1364
                private volatile boolean OE=false;
 
1365
                private volatile boolean PE=false;
 
1366
                private volatile boolean FE=false;
 
1367
                private volatile boolean BI=false;
 
1368
                private volatile boolean Data=false;
 
1369
                private volatile boolean Output=false;
 
1370
 
 
1371
                MonitorThread() 
 
1372
                {
 
1373
                        if (debug)
 
1374
                                z.reportln( "RXTXPort:MontitorThread:MonitorThread()"); 
 
1375
                }
 
1376
        /**
 
1377
        *  run the thread and call the event loop.
 
1378
        */
 
1379
                public void run()
 
1380
                {
 
1381
                        if (debug)
 
1382
                                z.reportln( "RXTXPort:MontitorThread:run()"); 
 
1383
                        monThreadisInterrupted=false;
 
1384
                        eventLoop();
 
1385
 
 
1386
                        if (debug)
 
1387
                                z.reportln( "eventLoop() returned"); 
 
1388
                }
 
1389
                protected void finalize() throws Throwable 
 
1390
                { 
 
1391
                        if (debug)
 
1392
                                z.reportln( "RXTXPort:MonitorThread exiting"); 
 
1393
                }
 
1394
        }
 
1395
        /**
 
1396
        *  A dummy method added so RXTX compiles on Kaffee
 
1397
        *  @deprecated deprecated but used in Kaffe 
 
1398
        */
 
1399
        public void setRcvFifoTrigger(int trigger){};  
 
1400
 
 
1401
/*------------------------  END OF CommAPI -----------------------------*/
 
1402
 
 
1403
        private native static void nativeStaticSetSerialPortParams( String f,
 
1404
                int b, int d, int s, int p )
 
1405
                throws UnsupportedCommOperationException;
 
1406
        private native static boolean nativeStaticSetDSR( String port,
 
1407
                                                        boolean flag )
 
1408
                throws UnsupportedCommOperationException;
 
1409
        private native static boolean nativeStaticSetDTR( String port,
 
1410
                                                        boolean flag )
 
1411
                throws UnsupportedCommOperationException;
 
1412
        private native static boolean nativeStaticSetRTS( String port,
 
1413
                                                        boolean flag )
 
1414
                throws UnsupportedCommOperationException;
 
1415
 
 
1416
        private native static boolean nativeStaticIsDSR( String port )
 
1417
                throws UnsupportedCommOperationException;
 
1418
        private native static boolean nativeStaticIsDTR( String port )
 
1419
                throws UnsupportedCommOperationException;
 
1420
        private native static boolean nativeStaticIsRTS( String port )
 
1421
                throws UnsupportedCommOperationException;
 
1422
        private native static boolean nativeStaticIsCTS( String port )
 
1423
                throws UnsupportedCommOperationException;
 
1424
        private native static boolean nativeStaticIsCD( String port )
 
1425
                throws UnsupportedCommOperationException;
 
1426
        private native static boolean nativeStaticIsRI( String port )
 
1427
                throws UnsupportedCommOperationException;
 
1428
 
 
1429
        private native static int nativeStaticGetBaudRate( String port )
 
1430
                throws UnsupportedCommOperationException;
 
1431
        private native static int nativeStaticGetDataBits( String port )
 
1432
                throws UnsupportedCommOperationException;
 
1433
        private native static int nativeStaticGetParity( String port )
 
1434
                throws UnsupportedCommOperationException;
 
1435
        private native static int nativeStaticGetStopBits( String port )
 
1436
                throws UnsupportedCommOperationException;
 
1437
 
 
1438
 
 
1439
        private native byte nativeGetParityErrorChar( )
 
1440
                throws UnsupportedCommOperationException;
 
1441
        private native boolean nativeSetParityErrorChar( byte b )
 
1442
                throws UnsupportedCommOperationException;
 
1443
        private native byte nativeGetEndOfInputChar( )
 
1444
                throws UnsupportedCommOperationException;
 
1445
        private native boolean nativeSetEndOfInputChar( byte b )
 
1446
                throws UnsupportedCommOperationException;
 
1447
        private native boolean nativeSetUartType(String type, boolean test)
 
1448
                throws UnsupportedCommOperationException;
 
1449
        native String nativeGetUartType()
 
1450
                throws UnsupportedCommOperationException;
 
1451
        private native boolean nativeSetBaudBase(int BaudBase) 
 
1452
                throws UnsupportedCommOperationException;
 
1453
        private native int nativeGetBaudBase() 
 
1454
                throws UnsupportedCommOperationException;
 
1455
        private native boolean nativeSetDivisor(int Divisor)
 
1456
                throws UnsupportedCommOperationException;
 
1457
        private native int nativeGetDivisor()
 
1458
                throws UnsupportedCommOperationException;
 
1459
        private native boolean nativeSetLowLatency()
 
1460
                throws UnsupportedCommOperationException;
 
1461
        private native boolean nativeGetLowLatency()
 
1462
                throws UnsupportedCommOperationException;
 
1463
        private native boolean nativeSetCallOutHangup(boolean NoHup)
 
1464
                throws UnsupportedCommOperationException;
 
1465
        private native boolean nativeGetCallOutHangup()
 
1466
                throws UnsupportedCommOperationException;
 
1467
 
 
1468
        /**
 
1469
        *  Extension to CommAPI
 
1470
        *  This is an extension to CommAPI.  It may not be supported on
 
1471
        *  all operating systems.
 
1472
        *
 
1473
        *  This is only accurate up to 38600 baud currently.
 
1474
        *
 
1475
        *  @param  port the name of the port thats been preopened
 
1476
        *  @return BaudRate on success
 
1477
        *  @throws UnsupportedCommOperationException;
 
1478
        *  This will not behave as expected with custom speeds
 
1479
        *
 
1480
        */
 
1481
        public static int staticGetBaudRate( String port )
 
1482
                throws UnsupportedCommOperationException
 
1483
        {
 
1484
                if ( debug )
 
1485
                        z.reportln( 
 
1486
                                "RXTXPort:staticGetBaudRate( " + port + " )");
 
1487
                return(nativeStaticGetBaudRate( port ));
 
1488
        }
 
1489
        /**
 
1490
        *  Extension to CommAPI
 
1491
        *  This is an extension to CommAPI.  It may not be supported on
 
1492
        *  all operating systems.
 
1493
        *
 
1494
        *  @param  port the name of the port thats been preopened
 
1495
        *  @return DataBits on success
 
1496
        *  @throws UnsupportedCommOperationException;
 
1497
        *
 
1498
        */
 
1499
        public static int staticGetDataBits( String port )
 
1500
                throws UnsupportedCommOperationException
 
1501
        {
 
1502
                if ( debug )
 
1503
                        z.reportln( 
 
1504
                                "RXTXPort:staticGetDataBits( " + port + " )");
 
1505
                return(nativeStaticGetDataBits( port ) );
 
1506
        }
 
1507
 
 
1508
        /**
 
1509
        *  Extension to CommAPI
 
1510
        *  This is an extension to CommAPI.  It may not be supported on
 
1511
        *  all operating systems.
 
1512
        *
 
1513
        *  @param  port the name of the port thats been preopened
 
1514
        *  @return Parity on success
 
1515
        *  @throws UnsupportedCommOperationException;
 
1516
        *
 
1517
        */
 
1518
        public static int staticGetParity( String port )
 
1519
                throws UnsupportedCommOperationException
 
1520
        {
 
1521
                if ( debug )
 
1522
                        z.reportln( 
 
1523
                                "RXTXPort:staticGetParity( " + port + " )");
 
1524
                return( nativeStaticGetParity( port ) );
 
1525
        }
 
1526
 
 
1527
        /**
 
1528
        *  Extension to CommAPI
 
1529
        *  This is an extension to CommAPI.  It may not be supported on
 
1530
        *  all operating systems.
 
1531
        *
 
1532
        *  @param  port the name of the port thats been preopened
 
1533
        *  @return StopBits on success
 
1534
        *  @throws UnsupportedCommOperationException;
 
1535
        *
 
1536
        */
 
1537
        public static int staticGetStopBits( String port )
 
1538
                throws UnsupportedCommOperationException
 
1539
        {
 
1540
                if ( debug )
 
1541
                        z.reportln( 
 
1542
                                "RXTXPort:staticGetStopBits( " + port + " )");
 
1543
                        return(nativeStaticGetStopBits( port ) );
 
1544
        }
 
1545
 
 
1546
        /** 
 
1547
        *  Extension to CommAPI
 
1548
        *  This is an extension to CommAPI.  It may not be supported on
 
1549
        *  all operating systems.
 
1550
        *
 
1551
        *  Set the SerialPort parameters
 
1552
        *  1.5 stop bits requires 5 databits
 
1553
        *  @param  f filename
 
1554
        *  @param  b baudrate
 
1555
        *  @param  d databits
 
1556
        *  @param  s stopbits
 
1557
        *  @param  p parity
 
1558
        *
 
1559
        *  @throws UnsupportedCommOperationException
 
1560
        *  @see gnu.io.UnsupportedCommOperationException
 
1561
        */
 
1562
 
 
1563
        public static void staticSetSerialPortParams( String f, int b, int d,
 
1564
                int s, int p )
 
1565
                throws UnsupportedCommOperationException
 
1566
        {
 
1567
                if ( debug )
 
1568
                        z.reportln( 
 
1569
                                "RXTXPort:staticSetSerialPortParams( " +
 
1570
                                f + " " + b + " " + d + " " + s + " " + p );
 
1571
                nativeStaticSetSerialPortParams( f, b, d, s, p );
 
1572
        }
 
1573
 
 
1574
        /**
 
1575
        *  Extension to CommAPI
 
1576
        *  This is an extension to CommAPI.  It may not be supported on
 
1577
        *  all operating systems.
 
1578
        *
 
1579
        *  Open the port and set DSR.  remove lockfile and do not close
 
1580
        *  This is so some software can appear to set the DSR before 'opening'
 
1581
        *  the port a second time later on.
 
1582
        *
 
1583
        *  @return true on success
 
1584
        *  @throws UnsupportedCommOperationException;
 
1585
        *
 
1586
        */
 
1587
 
 
1588
        public static boolean staticSetDSR( String port, boolean flag )
 
1589
                throws UnsupportedCommOperationException
 
1590
        {
 
1591
                if ( debug )
 
1592
                        z.reportln(  "RXTXPort:staticSetDSR( " + port +
 
1593
                                                " " + flag );
 
1594
                return( nativeStaticSetDSR( port, flag ) );
 
1595
        }
 
1596
 
 
1597
        /**
 
1598
        *  Extension to CommAPI
 
1599
        *  This is an extension to CommAPI.  It may not be supported on
 
1600
        *  all operating systems.
 
1601
        *
 
1602
        *  Open the port and set DTR.  remove lockfile and do not close
 
1603
        *  This is so some software can appear to set the DTR before 'opening'
 
1604
        *  the port a second time later on.
 
1605
        *
 
1606
        *  @return true on success
 
1607
        *  @throws UnsupportedCommOperationException;
 
1608
        *
 
1609
        */
 
1610
 
 
1611
        public static boolean staticSetDTR( String port, boolean flag )
 
1612
                throws UnsupportedCommOperationException
 
1613
        {
 
1614
                if ( debug )
 
1615
                        z.reportln(  "RXTXPort:staticSetDTR( " + port +
 
1616
                                                " " + flag );
 
1617
                return( nativeStaticSetDTR( port, flag ) );
 
1618
        }
 
1619
 
 
1620
        /**
 
1621
        *  Extension to CommAPI
 
1622
        *  This is an extension to CommAPI.  It may not be supported on
 
1623
        *  all operating systems.
 
1624
        *
 
1625
        *  Open the port and set RTS.  remove lockfile and do not close
 
1626
        *  This is so some software can appear to set the RTS before 'opening'
 
1627
        *  the port a second time later on.
 
1628
        *
 
1629
        *  @return none
 
1630
        *  @throws UnsupportedCommOperationException;
 
1631
        *
 
1632
        */
 
1633
 
 
1634
        public static boolean staticSetRTS( String port, boolean flag )
 
1635
                throws UnsupportedCommOperationException
 
1636
        {
 
1637
                if ( debug )
 
1638
                        z.reportln(  "RXTXPort:staticSetRTS( " + port +
 
1639
                                                " " + flag );
 
1640
                return( nativeStaticSetRTS( port, flag ) );
 
1641
        }
 
1642
 
 
1643
        /**
 
1644
        *  Extension to CommAPI
 
1645
        *  This is an extension to CommAPI.  It may not be supported on
 
1646
        *  all operating systems.
 
1647
        *
 
1648
        *  find the fd and return RTS without using a Java open() call
 
1649
        *
 
1650
        *  @param String port
 
1651
        *  @return boolean true if asserted
 
1652
        *  @throws UnsupportedCommOperationException;
 
1653
        *
 
1654
        */
 
1655
 
 
1656
        public static boolean staticIsRTS( String port )
 
1657
                throws UnsupportedCommOperationException
 
1658
        {
 
1659
                if ( debug )
 
1660
                        z.reportln(  "RXTXPort:staticIsRTS( " + port + " )" );
 
1661
                return( nativeStaticIsRTS( port ) );
 
1662
        }
 
1663
        /**
 
1664
        *  Extension to CommAPI
 
1665
        *  This is an extension to CommAPI.  It may not be supported on
 
1666
        *  all operating systems.
 
1667
        *
 
1668
        *  find the fd and return CD without using a Java open() call
 
1669
        *
 
1670
        *  @param String port
 
1671
        *  @return boolean true if asserted
 
1672
        *  @throws UnsupportedCommOperationException;
 
1673
        *
 
1674
        */
 
1675
 
 
1676
        public static boolean staticIsCD( String port )
 
1677
                throws UnsupportedCommOperationException
 
1678
        {
 
1679
                if ( debug )
 
1680
                        z.reportln( "RXTXPort:staticIsCD( " + port + " )" );
 
1681
                return( nativeStaticIsCD( port ) );
 
1682
        }
 
1683
        /**
 
1684
        *  Extension to CommAPI
 
1685
        *  This is an extension to CommAPI.  It may not be supported on
 
1686
        *  all operating systems.
 
1687
        *
 
1688
        *  find the fd and return CTS without using a Java open() call
 
1689
        *
 
1690
        *  @param String port
 
1691
        *  @return boolean true if asserted
 
1692
        *  @throws UnsupportedCommOperationException;
 
1693
        *
 
1694
        */
 
1695
 
 
1696
        public static boolean staticIsCTS( String port )
 
1697
                throws UnsupportedCommOperationException
 
1698
        {
 
1699
                if ( debug )
 
1700
                        z.reportln(  "RXTXPort:staticIsCTS( " + port + " )" );
 
1701
                return( nativeStaticIsCTS( port ) );
 
1702
        }
 
1703
        /**
 
1704
        *  Extension to CommAPI
 
1705
        *  This is an extension to CommAPI.  It may not be supported on
 
1706
        *  all operating systems.
 
1707
        *
 
1708
        *  find the fd and return DSR without using a Java open() call
 
1709
        *
 
1710
        *  @param String port
 
1711
        *  @return boolean true if asserted
 
1712
        *  @throws UnsupportedCommOperationException;
 
1713
        *
 
1714
        */
 
1715
 
 
1716
        public static boolean staticIsDSR( String port )
 
1717
                throws UnsupportedCommOperationException
 
1718
        {
 
1719
                if ( debug )
 
1720
                        z.reportln(  "RXTXPort:staticIsDSR( " + port + " )" );
 
1721
                return( nativeStaticIsDSR( port ) );
 
1722
        }
 
1723
        /**
 
1724
        *  Extension to CommAPI
 
1725
        *  This is an extension to CommAPI.  It may not be supported on
 
1726
        *  all operating systems.
 
1727
        *
 
1728
        *  find the fd and return DTR without using a Java open() call
 
1729
        *
 
1730
        *  @param String port
 
1731
        *  @return boolean true if asserted
 
1732
        *  @throws UnsupportedCommOperationException;
 
1733
        *
 
1734
        */
 
1735
 
 
1736
        public static boolean staticIsDTR( String port )
 
1737
                throws UnsupportedCommOperationException
 
1738
        {
 
1739
                if ( debug )
 
1740
                        z.reportln(  "RXTXPort:staticIsDTR( " + port + " )" );
 
1741
                return( nativeStaticIsDTR( port ) );
 
1742
        }
 
1743
        /**
 
1744
        *  Extension to CommAPI
 
1745
        *  This is an extension to CommAPI.  It may not be supported on
 
1746
        *  all operating systems.
 
1747
        *
 
1748
        *  find the fd and return RI without using a Java open() call
 
1749
        *
 
1750
        *  @param String port
 
1751
        *  @return boolean true if asserted
 
1752
        *  @throws UnsupportedCommOperationException;
 
1753
        *
 
1754
        */
 
1755
 
 
1756
        public static boolean staticIsRI( String port )
 
1757
                throws UnsupportedCommOperationException
 
1758
        {
 
1759
                if ( debug )
 
1760
                        z.reportln(  "RXTXPort:staticIsRI( " + port + " )" );
 
1761
                return( nativeStaticIsRI( port ) );
 
1762
        }
 
1763
 
 
1764
 
 
1765
        /**
 
1766
        *  Extension to CommAPI
 
1767
        *  This is an extension to CommAPI.  It may not be supported on
 
1768
        *  all operating systems.
 
1769
        *  @return int the Parity Error Character
 
1770
        *  @throws UnsupportedCommOperationException;
 
1771
        *
 
1772
        *  Anyone know how to do this in Unix?
 
1773
        */
 
1774
 
 
1775
        public byte getParityErrorChar( )
 
1776
                throws UnsupportedCommOperationException
 
1777
        {
 
1778
                byte ret;
 
1779
                if ( debug )
 
1780
                        z.reportln(  "getParityErrorChar()" );
 
1781
                ret = nativeGetParityErrorChar();
 
1782
                if ( debug )
 
1783
                        z.reportln(  "getParityErrorChar() returns " +
 
1784
                                                ret );
 
1785
                return( ret );
 
1786
        }
 
1787
 
 
1788
        /**
 
1789
        *  Extension to CommAPI
 
1790
        *  This is an extension to CommAPI.  It may not be supported on
 
1791
        *  all operating systems.
 
1792
        *  @param b Parity Error Character
 
1793
        *  @return boolean true on success
 
1794
        *  @throws UnsupportedCommOperationException;
 
1795
        *
 
1796
        *  Anyone know how to do this in Unix?
 
1797
        */
 
1798
 
 
1799
        public boolean setParityErrorChar( byte b )
 
1800
                throws UnsupportedCommOperationException
 
1801
        {
 
1802
                if ( debug )
 
1803
                        z.reportln(  "setParityErrorChar(" + b + ")" );
 
1804
                return( nativeSetParityErrorChar( b ) );
 
1805
        }
 
1806
 
 
1807
        /**
 
1808
        *  Extension to CommAPI
 
1809
        *  This is an extension to CommAPI.  It may not be supported on
 
1810
        *  all operating systems.
 
1811
        *  @return int the End of Input Character
 
1812
        *  @throws UnsupportedCommOperationException;
 
1813
        *
 
1814
        *  Anyone know how to do this in Unix?
 
1815
        */
 
1816
 
 
1817
        public byte getEndOfInputChar( )
 
1818
                throws UnsupportedCommOperationException
 
1819
        {
 
1820
                byte ret;
 
1821
                if ( debug )
 
1822
                        z.reportln(  "getEndOfInputChar()" );
 
1823
                ret = nativeGetEndOfInputChar();
 
1824
                if ( debug )
 
1825
                        z.reportln(  "getEndOfInputChar() returns " +
 
1826
                                                ret );
 
1827
                return( ret );
 
1828
        }
 
1829
 
 
1830
        /**
 
1831
        *  Extension to CommAPI
 
1832
        *  This is an extension to CommAPI.  It may not be supported on
 
1833
        *  all operating systems.
 
1834
        *  @param b End Of Input Character
 
1835
        *  @return boolean true on success
 
1836
        *  @throws UnsupportedCommOperationException;
 
1837
        */
 
1838
 
 
1839
        public boolean setEndOfInputChar( byte b )
 
1840
                throws UnsupportedCommOperationException
 
1841
        {
 
1842
                if ( debug )
 
1843
                        z.reportln(  "setEndOfInputChar(" + b + ")" );
 
1844
                return( nativeSetEndOfInputChar( b ) );
 
1845
        }
 
1846
 
 
1847
        /**
 
1848
        *  Extension to CommAPI
 
1849
        *  This is an extension to CommAPI.  It may not be supported on
 
1850
        *  all operating systems.
 
1851
        *  @param type String representation of the UART type which mayb
 
1852
        *  be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
 
1853
        *  or "16750".
 
1854
        *  @param test boolean flag to determin if the UART should be tested.
 
1855
        *  @return boolean true on success
 
1856
        *  @throws UnsupportedCommOperationException;
 
1857
        */
 
1858
        public boolean setUARTType(String type, boolean test)
 
1859
                throws UnsupportedCommOperationException
 
1860
        {
 
1861
                if ( debug )
 
1862
                        z.reportln(  "RXTXPort:setUARTType()");
 
1863
                return nativeSetUartType(type, test);
 
1864
        }
 
1865
        /**
 
1866
        *  Extension to CommAPI
 
1867
        *  This is an extension to CommAPI.  It may not be supported on
 
1868
        *  all operating systems.
 
1869
        *  @return type String representation of the UART type which mayb
 
1870
        *  be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
 
1871
        *  or "16750".
 
1872
        *  @throws UnsupportedCommOperationException;
 
1873
        */
 
1874
        public String getUARTType() throws UnsupportedCommOperationException
 
1875
        {
 
1876
                return nativeGetUartType();
 
1877
        }
 
1878
 
 
1879
        /**
 
1880
        *  Extension to CommAPI
 
1881
        *  @param int BaudBase The clock frequency divided by 16.  Default
 
1882
        *  BaudBase is 115200.
 
1883
        *  @return boolean true on success
 
1884
        *  @throws UnsupportedCommOperationException
 
1885
        */
 
1886
 
 
1887
        public boolean setBaudBase(int BaudBase)
 
1888
                throws UnsupportedCommOperationException
 
1889
        {
 
1890
                if ( debug )
 
1891
                        z.reportln(  "RXTXPort:setBaudBase()");
 
1892
                return nativeSetBaudBase(BaudBase);
 
1893
        }
 
1894
 
 
1895
        /**
 
1896
        *  Extension to CommAPI
 
1897
        *  @return int BaudBase
 
1898
        *  @throws UnsupportedCommOperationException
 
1899
        */
 
1900
 
 
1901
        public int getBaudBase() throws UnsupportedCommOperationException
 
1902
        {
 
1903
                if ( debug )
 
1904
                        z.reportln(  "RXTXPort:getBaudBase()");
 
1905
                return nativeGetBaudBase();
 
1906
        }
 
1907
 
 
1908
        /**
 
1909
        *  Extension to CommAPI
 
1910
        *  @param int Divisor;
 
1911
        *  @throws UnsupportedCommOperationException
 
1912
        */
 
1913
 
 
1914
        public boolean setDivisor(int Divisor)
 
1915
                throws UnsupportedCommOperationException
 
1916
        {
 
1917
                if ( debug )
 
1918
                        z.reportln(  "RXTXPort:setDivisor()");
 
1919
                return nativeSetDivisor(Divisor);
 
1920
        }
 
1921
 
 
1922
        /**
 
1923
        *  Extension to CommAPI
 
1924
        *  @returns int Divisor;
 
1925
        *  @throws UnsupportedCommOperationException
 
1926
        */
 
1927
 
 
1928
        public int getDivisor() throws UnsupportedCommOperationException
 
1929
        {
 
1930
                if ( debug )
 
1931
                        z.reportln(  "RXTXPort:getDivisor()");
 
1932
                return nativeGetDivisor();
 
1933
        }
 
1934
 
 
1935
        /**
 
1936
        *  Extension to CommAPI
 
1937
        *  returns boolean true on success
 
1938
        *  @throws UnsupportedCommOperationException
 
1939
        */
 
1940
 
 
1941
        public boolean setLowLatency() throws UnsupportedCommOperationException
 
1942
        {
 
1943
                if ( debug )
 
1944
                        z.reportln(  "RXTXPort:setLowLatency()");
 
1945
                return nativeSetLowLatency();
 
1946
        }
 
1947
 
 
1948
        /**
 
1949
        *  Extension to CommAPI
 
1950
        *  returns boolean true on success
 
1951
        *  @throws UnsupportedCommOperationException
 
1952
        */
 
1953
 
 
1954
        public boolean getLowLatency() throws UnsupportedCommOperationException
 
1955
        {
 
1956
                if ( debug )
 
1957
                        z.reportln(  "RXTXPort:getLowLatency()");
 
1958
                return nativeGetLowLatency();
 
1959
        }
 
1960
 
 
1961
        /**
 
1962
        *  Extension to CommAPI
 
1963
        *  returns boolean true on success
 
1964
        *  @throws UnsupportedCommOperationException
 
1965
        */
 
1966
 
 
1967
        public boolean setCallOutHangup(boolean NoHup)
 
1968
                throws UnsupportedCommOperationException
 
1969
        {
 
1970
                if ( debug )
 
1971
                        z.reportln(  "RXTXPort:setCallOutHangup()");
 
1972
                return nativeSetCallOutHangup(NoHup);
 
1973
        }
 
1974
 
 
1975
        /**
 
1976
        *  Extension to CommAPI
 
1977
        *  returns boolean true on success
 
1978
        *  @throws UnsupportedCommOperationException
 
1979
        */
 
1980
 
 
1981
        public boolean getCallOutHangup()
 
1982
                throws UnsupportedCommOperationException
 
1983
        {
 
1984
                if ( debug )
 
1985
                        z.reportln(  "RXTXPort:getCallOutHangup()");
 
1986
                return nativeGetCallOutHangup();
 
1987
        }
 
1988
 
 
1989
/*------------------------  END OF CommAPI Extensions -----------------------*/
 
1990
}