1
/*-------------------------------------------------------------------------
2
| RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
3
| RXTX is a native interface to serial ports in java.
4
| Copyright 1997-2008 by Trent Jarvi tjarvi@qbang.org and others who
5
| actually wrote it. See individual source files for more information.
7
| A copy of the LGPL v 2.1 may be found at
8
| http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is
9
| here for your convenience.
11
| This library is free software; you can redistribute it and/or
12
| modify it under the terms of the GNU Lesser General Public
13
| License as published by the Free Software Foundation; either
14
| version 2.1 of the License, or (at your option) any later version.
16
| This library is distributed in the hope that it will be useful,
17
| but WITHOUT ANY WARRANTY; without even the implied warranty of
18
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
| Lesser General Public License for more details.
21
| An executable that contains no derivative of any portion of RXTX, but
22
| is designed to work with RXTX by being dynamically linked with it,
23
| is considered a "work that uses the Library" subject to the terms and
24
| conditions of the GNU Lesser General Public License.
26
| The following has been added to the RXTX License to remove
27
| any confusion about linking to RXTX. We want to allow in part what
28
| section 5, paragraph 2 of the LGPL does not permit in the special
29
| case of linking over a controlled interface. The intent is to add a
30
| Java Specification Request or standards body defined interface in the
31
| future as another exception but one is not currently available.
33
| http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
35
| As a special exception, the copyright holders of RXTX give you
36
| permission to link RXTX with independent modules that communicate with
37
| RXTX solely through the Sun Microsytems CommAPI interface version 2,
38
| regardless of the license terms of these independent modules, and to copy
39
| and distribute the resulting combined work under terms of your choice,
40
| provided that every copy of the combined work is accompanied by a complete
41
| copy of the source code of RXTX (the version of RXTX used to produce the
42
| combined work), being distributed under the terms of the GNU Lesser General
43
| Public License plus this exception. An independent module is a
44
| module which is not derived from or based on RXTX.
46
| Note that people who make modified versions of RXTX are not obligated
47
| to grant this special exception for their modified versions; it is
48
| their choice whether to do so. The GNU Lesser General Public License
49
| gives permission to release a modified version without this exception; this
50
| exception also makes it possible to release a modified version which
51
| carries forward this exception.
53
| You should have received a copy of the GNU Lesser General Public
54
| License along with this library; if not, write to the Free
55
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56
| All trademarks belong to their respective owners.
57
--------------------------------------------------------------------------*/
59
import java.io.InputStream;
60
import java.io.OutputStream;
61
import java.io.IOException;
62
import java.util.TooManyListenersException;
63
import java.lang.Math;
66
* An extension of gnu.io.SerialPort
67
* @see gnu.io.SerialPort
70
final public class RXTXPort extends SerialPort
72
/* I had a report that some JRE's complain when MonitorThread
73
tries to access private variables
76
protected final static boolean debug = false;
77
protected final static boolean debug_read = false;
78
protected final static boolean debug_read_results = false;
79
protected final static boolean debug_write = false;
80
protected final static boolean debug_events = false;
81
protected final static boolean debug_verbose = false;
83
private static Zystem z;
89
} catch ( Exception e ) {}
92
z.reportln( "RXTXPort {}");
93
System.loadLibrary( "rxtxSerial" );
97
/** Initialize the native library */
98
private native static void Initialize();
99
boolean MonitorThreadAlive=false;
102
* Open the named port
103
* @param name the name of the device to open
104
* @throws PortInUseException
105
* @see gnu.io.SerialPort
107
public RXTXPort( String name ) throws PortInUseException
110
z.reportln( "RXTXPort:RXTXPort("+name+") called");
112
commapi/javadocs/API_users_guide.html specifies that whenever
113
an application tries to open a port in use by another application
114
the PortInUseException will be thrown
116
I know some didnt like it this way but I'm not sure how to avoid
117
it. We will just be writing to a bogus fd if we catch the
126
MonitorThreadLock = true;
127
monThread = new MonitorThread();
129
waitForTheNativeCodeSilly();
130
MonitorThreadAlive=true;
131
// } catch ( PortInUseException e ){}
132
timeout = -1; /* default disabled timeout */
134
z.reportln( "RXTXPort:RXTXPort("+name+") returns with fd = " +
137
private native synchronized int open( String name )
138
throws PortInUseException;
141
/* dont close the file while accessing the fd */
143
Object IOLockedMutex = new Object();
145
/** File descriptor */
148
/** a pointer to the event info structure used to share information
149
between threads so write threads can send output buffer empty
150
from a pthread if need be.
152
long for 64 bit pointers.
155
/** pid for lock files */
159
static boolean dsrFlag = false;
162
private final SerialOutputStream out = new SerialOutputStream();
164
* get the OutputStream
165
* @return OutputStream
167
public OutputStream getOutputStream()
170
z.reportln( "RXTXPort:getOutputStream() called and returning");
175
private final SerialInputStream in = new SerialInputStream();
177
* get the InputStream
178
* @return InputStream
179
* @see java.io.InputStream
181
public InputStream getInputStream()
184
z.reportln( "RXTXPort:getInputStream() called and returning");
189
* Set the SerialPort parameters
190
* 1.5 stop bits requires 5 databits
195
* @throws UnsupportedCommOperationException
196
* @see gnu.io.UnsupportedCommOperationException
198
* If speed is not a predifined speed it is assumed to be
199
* the actual speed desired.
201
private native int nativeGetParity( int fd );
202
private native int nativeGetFlowControlMode( int fd );
203
public synchronized void setSerialPortParams( int b, int d, int s,
205
throws UnsupportedCommOperationException
208
z.reportln( "RXTXPort:setSerialPortParams(" +
209
b + " " + d + " " + s + " " + p + ") called");
210
if ( nativeSetSerialPortParams( b, d, s, p ) )
211
throw new UnsupportedCommOperationException(
212
"Invalid Parameter" );
214
if( s== STOPBITS_1_5 ) dataBits = DATABITS_5;
218
z.reportln( "RXTXPort:setSerialPortParams(" +
219
b + " " + d + " " + s + " " + p +
224
* Set the native serial port parameters
225
* If speed is not a predifined speed it is assumed to be
226
* the actual speed desired.
228
private native boolean nativeSetSerialPortParams( int speed,
229
int dataBits, int stopBits, int parity )
230
throws UnsupportedCommOperationException;
232
/** Line speed in bits-per-second */
233
private int speed=9600;
235
* @return int representing the baudrate
236
* This will not behave as expected with custom speeds
238
public int getBaudRate()
241
z.reportln( "RXTXPort:getBaudRate() called and returning " + speed);
245
/** Data bits port parameter */
246
private int dataBits=DATABITS_8;
248
* @return int representing the databits
250
public int getDataBits()
253
z.reportln( "RXTXPort:getDataBits() called and returning " + dataBits);
257
/** Stop bits port parameter */
258
private int stopBits=SerialPort.STOPBITS_1;
260
* @return int representing the stopbits
262
public int getStopBits()
265
z.reportln( "RXTXPort:getStopBits() called and returning " + stopBits);
269
/** Parity port parameter */
270
private int parity= SerialPort.PARITY_NONE;
272
* @return int representing the parity
274
public int getParity()
277
z.reportln( "RXTXPort:getParity() called and returning " + parity );
283
private int flowmode = SerialPort.FLOWCONTROL_NONE;
285
* @param flowcontrol FLOWCONTROL_NONE is default
286
* @see gnu.io.SerialPort#FLOWCONTROL_NONE
288
public void setFlowControlMode( int flowcontrol )
291
z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) called");
292
if(monThreadisInterrupted)
295
z.reportln( "RXTXPort:setFlowControlMode MonThread is Interrupeted returning" );
299
setflowcontrol( flowcontrol );
301
catch( IOException e )
306
flowmode=flowcontrol;
308
z.reportln( "RXTXPort:setFlowControlMode( " + flowcontrol + " ) returning");
311
* @return int representing the flowmode
313
public int getFlowControlMode()
316
z.reportln( "RXTXPort:getFlowControlMode() returning " + flowmode );
319
native void setflowcontrol( int flowcontrol ) throws IOException;
323
linux/drivers/char/n_hdlc.c? FIXME
327
* Receive framing control
329
* @throws UnsupportedCommOperationException
331
public void enableReceiveFraming( int f )
332
throws UnsupportedCommOperationException
335
z.reportln( "RXTXPort:enableReceiveFramming() throwing exception");
336
throw new UnsupportedCommOperationException( "Not supported" );
340
public void disableReceiveFraming()
343
z.reportln( "RXTXPort:disableReceiveFramming() called and returning (noop)");
346
* @return true if framing is enabled
348
public boolean isReceiveFramingEnabled()
351
z.reportln( "RXTXPort:isReceiveFrammingEnabled() called and returning " + false );
355
* @return int representing the framing byte
357
public int getReceiveFramingByte()
360
z.reportln( "RXTXPort:getReceiveFrammingByte() called and returning " + 0 );
365
/** Receive timeout control */
369
* @return int the timeout
371
public native int NativegetReceiveTimeout();
373
* @return bloolean true if recieve timeout is enabled
375
private native boolean NativeisReceiveTimeoutEnabled();
381
private native void NativeEnableReceiveTimeoutThreshold(int time,
382
int threshold,int InputBuffer);
385
public void disableReceiveTimeout()
388
z.reportln( "RXTXPort:disableReceiveTimeout() called");
390
NativeEnableReceiveTimeoutThreshold( timeout , threshold, InputBuffer );
392
z.reportln( "RXTXPort:disableReceiveTimeout() returning");
397
public void enableReceiveTimeout( int time )
400
z.reportln( "RXTXPort:enableReceiveTimeout() called");
404
NativeEnableReceiveTimeoutThreshold( time , threshold,
409
throw new IllegalArgumentException
411
"Unexpected negative timeout value"
415
z.reportln( "RXTXPort:enableReceiveTimeout() returning");
418
* @return boolean true if recieve timeout is enabled
420
public boolean isReceiveTimeoutEnabled()
423
z.reportln( "RXTXPort:isReceiveTimeoutEnabled() called and returning " + NativeisReceiveTimeoutEnabled() );
424
return( NativeisReceiveTimeoutEnabled() );
427
* @return int the timeout
429
public int getReceiveTimeout()
432
z.reportln( "RXTXPort:getReceiveTimeout() called and returning " + NativegetReceiveTimeout() );
433
return(NativegetReceiveTimeout( ));
436
/** Receive threshold control */
438
private int threshold = 0;
441
* @param thresh threshold
443
public void enableReceiveThreshold( int thresh )
446
z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) called");
450
NativeEnableReceiveTimeoutThreshold(timeout, threshold,
453
else /* invalid thresh */
455
throw new IllegalArgumentException
457
"Unexpected negative threshold value"
461
z.reportln( "RXTXPort:enableReceiveThreshold( " + thresh + " ) returned");
465
public void disableReceiveThreshold()
468
z.reportln( "RXTXPort:disableReceiveThreshold() called and returning");
469
enableReceiveThreshold(0);
472
* @return int the recieve threshold
474
public int getReceiveThreshold()
477
z.reportln( "RXTXPort:getReceiveThreshold() called and returning " + threshold);
481
* @return boolean true if receive threshold is enabled
483
public boolean isReceiveThresholdEnabled()
486
z.reportln( "RXTXPort:isReceiveThresholdEnable() called and returning" + (threshold > 0) );
490
/** Input/output buffers */
491
/** FIXME I think this refers to
492
FOPEN(3)/SETBUF(3)/FREAD(3)/FCLOSE(3)
495
These are native stubs...
497
private int InputBuffer=0;
498
private int OutputBuffer=0;
502
public void setInputBufferSize( int size )
505
z.reportln( "RXTXPort:setInputBufferSize( " +
508
throw new IllegalArgumentException
510
"Unexpected negative buffer size value"
512
else InputBuffer=size;
514
z.reportln( "RXTXPort:setInputBufferSize( " +
515
size + ") returning");
519
public int getInputBufferSize()
522
z.reportln( "RXTXPort:getInputBufferSize() called and returning " + InputBuffer );
528
public void setOutputBufferSize( int size )
531
z.reportln( "RXTXPort:setOutputBufferSize( " +
534
throw new IllegalArgumentException
536
"Unexpected negative buffer size value"
538
else OutputBuffer=size;
540
z.reportln( "RXTXPort:setOutputBufferSize( " +
541
size + ") returned");
545
* @return in the output buffer size
547
public int getOutputBufferSize()
550
z.reportln( "RXTXPort:getOutputBufferSize() called and returning " + OutputBuffer );
551
return(OutputBuffer);
554
/* =================== cleaned messages to here */
557
* Line status methods
560
* @return true if DTR is set
562
public native boolean isDTR();
566
public native void setDTR( boolean state );
570
public native void setRTS( boolean state );
571
private native void setDSR( boolean state );
573
* @return boolean true if CTS is set
575
public native boolean isCTS();
577
* @return boolean true if DSR is set
579
public native boolean isDSR();
581
* @return boolean true if CD is set
583
public native boolean isCD();
585
* @return boolean true if RI is set
587
public native boolean isRI();
589
* @return boolean true if RTS is set
591
public native boolean isRTS();
598
public native void sendBreak( int duration );
599
protected native void writeByte( int b, boolean i ) throws IOException;
600
protected native void writeArray( byte b[], int off, int len, boolean i )
602
protected native boolean nativeDrain( boolean i ) throws IOException;
604
/** RXTXPort read methods */
605
protected native int nativeavailable() throws IOException;
606
protected native int readByte() throws IOException;
607
protected native int readArray( byte b[], int off, int len )
609
protected native int readTerminatedArray( byte b[], int off, int len, byte t[] )
613
/** Serial Port Event listener */
614
private SerialPortEventListener SPEventListener;
616
/** Thread to monitor data */
617
private MonitorThread monThread;
619
/** Process SerialPortEvents */
620
native void eventLoop();
623
* @return boolean true if monitor thread is interrupted
625
boolean monThreadisInterrupted=true;
626
private native void interruptEventLoop( );
627
public boolean checkMonitorThread()
630
z.reportln( "RXTXPort:checkMonitorThread()");
631
if(monThread != null)
635
"monThreadisInterrupted = " +
636
monThreadisInterrupted );
637
return monThreadisInterrupted;
640
z.reportln( "monThread is null " );
647
* @return boolean true if the port is closing
649
public boolean sendEvent( int event, boolean state )
652
z.report( "RXTXPort:sendEvent(");
653
/* Let the native side know its time to die */
655
if ( fd == 0 || SPEventListener == null || monThread == null)
662
case SerialPortEvent.DATA_AVAILABLE:
664
z.reportln( "DATA_AVAILABLE " +
665
monThread.Data + ")" );
667
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
670
"OUTPUT_BUFFER_EMPTY " +
671
monThread.Output + ")" );
673
case SerialPortEvent.CTS:
676
monThread.CTS + ")" );
678
case SerialPortEvent.DSR:
681
monThread.Output + ")" );
683
case SerialPortEvent.RI:
686
monThread.RI + ")" );
688
case SerialPortEvent.CD:
691
monThread.CD + ")" );
693
case SerialPortEvent.OE:
696
monThread.OE + ")" );
698
case SerialPortEvent.PE:
701
monThread.PE + ")" );
703
case SerialPortEvent.FE:
706
monThread.FE + ")" );
708
case SerialPortEvent.BI:
711
monThread.BI + ")" );
715
z.reportln( "XXXXXXXXXXXXXX " +
719
if( debug_events && debug_verbose )
720
z.reportln( " checking flags " );
724
case SerialPortEvent.DATA_AVAILABLE:
725
if( monThread.Data ) break;
727
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
728
if( monThread.Output ) break;
730
case SerialPortEvent.CTS:
731
if( monThread.CTS ) break;
733
case SerialPortEvent.DSR:
734
if( monThread.DSR ) break;
736
case SerialPortEvent.RI:
737
if( monThread.RI ) break;
739
case SerialPortEvent.CD:
740
if( monThread.CD ) break;
742
case SerialPortEvent.OE:
743
if( monThread.OE ) break;
745
case SerialPortEvent.PE:
746
if( monThread.PE ) break;
748
case SerialPortEvent.FE:
749
if( monThread.FE ) break;
751
case SerialPortEvent.BI:
752
if( monThread.BI ) break;
755
System.err.println( "unknown event: " + event);
758
if( debug_events && debug_verbose )
759
z.reportln( " getting event" );
760
SerialPortEvent e = new SerialPortEvent(this, event, !state,
762
if( debug_events && debug_verbose )
763
z.reportln( " sending event" );
764
if(monThreadisInterrupted)
767
z.reportln( " sendEvent return" );
770
if( SPEventListener != null )
772
SPEventListener.serialEvent( e );
775
if( debug_events && debug_verbose )
776
z.reportln( " sendEvent return" );
778
if (fd == 0 || SPEventListener == null || monThread == null)
789
* Add an event listener
790
* @param lsnr SerialPortEventListener
791
* @throws TooManyListenersException
794
boolean MonitorThreadLock = true;
796
public void addEventListener(
797
SerialPortEventListener lsnr ) throws TooManyListenersException
799
/* Don't let and notification requests happen until the
804
z.reportln( "RXTXPort:addEventListener()");
805
if( SPEventListener != null )
807
throw new TooManyListenersException();
809
SPEventListener = lsnr;
810
if( !MonitorThreadAlive )
812
MonitorThreadLock = true;
813
monThread = new MonitorThread();
815
waitForTheNativeCodeSilly();
816
MonitorThreadAlive=true;
819
z.reportln( "RXTXPort:Interrupt=false");
822
* Remove the serial port event listener
824
public void removeEventListener()
827
z.reportln( "RXTXPort:removeEventListener() called");
828
waitForTheNativeCodeSilly();
829
//if( monThread != null && monThread.isAlive() )
830
if( monThreadisInterrupted == true )
832
z.reportln( " RXTXPort:removeEventListener() already interrupted");
834
SPEventListener = null;
837
else if( monThread != null && monThread.isAlive() )
840
z.reportln( " RXTXPort:Interrupt=true");
841
monThreadisInterrupted=true;
843
Notify all threads in this PID that something is up
844
They will call back to see if its their thread
845
using isInterrupted().
848
z.reportln( " RXTXPort:calling interruptEventLoop");
849
interruptEventLoop( );
852
z.reportln( " RXTXPort:calling monThread.join()");
855
// wait a reasonable moment for the death of the monitor thread
856
monThread.join(3000);
857
} catch (InterruptedException ex) {
858
// somebody called interrupt() on us (ie wants us to abort)
859
// we dont propagate InterruptedExceptions so lets re-set the flag
860
Thread.currentThread().interrupt();
864
if ( debug && monThread.isAlive() )
866
z.reportln( " MonThread is still alive!");
872
SPEventListener = null;
873
MonitorThreadLock = false;
874
MonitorThreadAlive=false;
875
monThreadisInterrupted=true;
876
z.reportln( "RXTXPort:removeEventListener() returning");
879
* Give the native code a chance to start listening to the hardware
880
* or should we say give the native code control of the issue.
882
* This is important for applications that flicker the Monitor
883
* thread while keeping the port open.
884
* In worst case test cases this loops once or twice every time.
887
protected void waitForTheNativeCodeSilly()
889
while( MonitorThreadLock )
893
} catch( Exception e ) {}
899
private native void nativeSetEventFlag( int fd, int event,
901
public void notifyOnDataAvailable( boolean enable )
904
z.reportln( "RXTXPort:notifyOnDataAvailable( " +
907
waitForTheNativeCodeSilly();
909
MonitorThreadLock = true;
910
nativeSetEventFlag( fd, SerialPortEvent.DATA_AVAILABLE,
912
monThread.Data = enable;
913
MonitorThreadLock = false;
919
public void notifyOnOutputEmpty( boolean enable )
922
z.reportln( "RXTXPort:notifyOnOutputEmpty( " +
924
waitForTheNativeCodeSilly();
925
MonitorThreadLock = true;
926
nativeSetEventFlag( fd, SerialPortEvent.OUTPUT_BUFFER_EMPTY,
928
monThread.Output = enable;
929
MonitorThreadLock = false;
935
public void notifyOnCTS( boolean enable )
938
z.reportln( "RXTXPort:notifyOnCTS( " +
940
waitForTheNativeCodeSilly();
941
MonitorThreadLock = true;
942
nativeSetEventFlag( fd, SerialPortEvent.CTS, enable );
943
monThread.CTS = enable;
944
MonitorThreadLock = false;
949
public void notifyOnDSR( boolean enable )
952
z.reportln( "RXTXPort:notifyOnDSR( " +
954
waitForTheNativeCodeSilly();
955
MonitorThreadLock = true;
956
nativeSetEventFlag( fd, SerialPortEvent.DSR, enable );
957
monThread.DSR = enable;
958
MonitorThreadLock = false;
963
public void notifyOnRingIndicator( boolean enable )
966
z.reportln( "RXTXPort:notifyOnRingIndicator( " +
968
waitForTheNativeCodeSilly();
969
MonitorThreadLock = true;
970
nativeSetEventFlag( fd, SerialPortEvent.RI, enable );
971
monThread.RI = enable;
972
MonitorThreadLock = false;
977
public void notifyOnCarrierDetect( boolean enable )
980
z.reportln( "RXTXPort:notifyOnCarrierDetect( " +
982
waitForTheNativeCodeSilly();
983
MonitorThreadLock = true;
984
nativeSetEventFlag( fd, SerialPortEvent.CD, enable );
985
monThread.CD = enable;
986
MonitorThreadLock = false;
991
public void notifyOnOverrunError( boolean enable )
994
z.reportln( "RXTXPort:notifyOnOverrunError( " +
996
waitForTheNativeCodeSilly();
997
MonitorThreadLock = true;
998
nativeSetEventFlag( fd, SerialPortEvent.OE, enable );
999
monThread.OE = enable;
1000
MonitorThreadLock = false;
1005
public void notifyOnParityError( boolean enable )
1008
z.reportln( "RXTXPort:notifyOnParityError( " +
1010
waitForTheNativeCodeSilly();
1011
MonitorThreadLock = true;
1012
nativeSetEventFlag( fd, SerialPortEvent.PE, enable );
1013
monThread.PE = enable;
1014
MonitorThreadLock = false;
1019
public void notifyOnFramingError( boolean enable )
1022
z.reportln( "RXTXPort:notifyOnFramingError( " +
1024
waitForTheNativeCodeSilly();
1025
MonitorThreadLock = true;
1026
nativeSetEventFlag( fd, SerialPortEvent.FE, enable );
1027
monThread.FE = enable;
1028
MonitorThreadLock = false;
1033
public void notifyOnBreakInterrupt( boolean enable )
1036
z.reportln( "RXTXPort:notifyOnBreakInterrupt( " +
1038
waitForTheNativeCodeSilly();
1039
MonitorThreadLock = true;
1040
nativeSetEventFlag( fd, SerialPortEvent.BI, enable );
1041
monThread.BI = enable;
1042
MonitorThreadLock = false;
1045
/** Close the port */
1046
private native void nativeClose( String name );
1049
boolean closeLock = false;
1052
synchronized (this) {
1054
z.reportln( "RXTXPort:close( " + this.name + " )");
1056
while( IOLocked > 0 )
1059
z.reportln("IO is locked " + IOLocked);
1062
} catch( InterruptedException ie ) {
1063
// somebody called interrupt() on us
1064
// we obbey and return without without closing the socket
1065
Thread.currentThread().interrupt();
1070
// we set the closeLock after the above check because we might
1071
// have returned without proceeding
1072
if( closeLock ) return;
1078
z.reportln( "RXTXPort:close detected bad File Descriptor" );
1084
z.reportln( "RXTXPort:close( " + this.name + " ) setting monThreadisInterrupted");
1085
if ( ! monThreadisInterrupted )
1087
removeEventListener();
1090
z.reportln( "RXTXPort:close( " + this.name + " ) calling nativeClose");
1091
nativeClose( this.name );
1093
z.reportln( "RXTXPort:close( " + this.name + " ) calling super.close");
1098
z.reportln( "RXTXPort:close( " + this.name + " ) leaving");
1102
/** Finalize the port */
1103
protected void finalize()
1106
z.reportln( "RXTXPort:finalize()");
1110
z.reportln( "RXTXPort:calling close()");
1116
/** Inner class for SerialOutputStream */
1117
class SerialOutputStream extends OutputStream
1121
* @throws IOException
1123
public void write( int b ) throws IOException
1126
z.reportln( "RXTXPort:SerialOutputStream:write(int)");
1127
if( speed == 0 ) return;
1128
if ( monThreadisInterrupted == true )
1132
synchronized (IOLockedMutex) {
1136
waitForTheNativeCodeSilly();
1139
throw new IOException();
1141
writeByte( b, monThreadisInterrupted );
1143
z.reportln( "Leaving RXTXPort:SerialOutputStream:write( int )");
1145
synchronized (IOLockedMutex) {
1152
* @throws IOException
1154
public void write( byte b[] ) throws IOException
1158
z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + b.length + ") "/* + new String(b)*/ );
1160
if( speed == 0 ) return;
1161
if ( monThreadisInterrupted == true )
1165
if ( fd == 0 ) throw new IOException();
1166
synchronized (IOLockedMutex) {
1170
waitForTheNativeCodeSilly();
1171
writeArray( b, 0, b.length, monThreadisInterrupted );
1173
z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" +b.length +")");
1175
synchronized(IOLockedMutex) {
1185
* @throws IOException
1187
public void write( byte b[], int off, int len )
1190
if( speed == 0 ) return;
1191
if( off + len > b.length )
1193
throw new IndexOutOfBoundsException(
1194
"Invalid offset/length passed to read"
1198
byte send[] = new byte[len];
1199
System.arraycopy( b, off, send, 0, len );
1202
z.reportln( "Entering RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+ new String(send) */ );
1204
if ( fd == 0 ) throw new IOException();
1205
if ( monThreadisInterrupted == true )
1209
synchronized (IOLockedMutex) {
1214
waitForTheNativeCodeSilly();
1215
writeArray( send, 0, len, monThreadisInterrupted );
1217
z.reportln( "Leaving RXTXPort:SerialOutputStream:write(" + send.length + " " + off + " " + len + " " +") " /*+ new String(send)*/ );
1219
synchronized (IOLockedMutex) {
1226
public void flush() throws IOException
1229
z.reportln( "RXTXPort:SerialOutputStream:flush() enter");
1230
if( speed == 0 ) return;
1231
if ( fd == 0 ) throw new IOException();
1232
if ( monThreadisInterrupted == true )
1235
z.reportln( "RXTXPort:SerialOutputStream:flush() Leaving Interrupted");
1238
synchronized(IOLockedMutex) {
1243
waitForTheNativeCodeSilly();
1245
this is probably good on all OS's but for now
1246
just sendEvent from java on Sol
1248
if ( nativeDrain( monThreadisInterrupted ) )
1249
sendEvent( SerialPortEvent.OUTPUT_BUFFER_EMPTY, true );
1251
z.reportln( "RXTXPort:SerialOutputStream:flush() leave");
1255
synchronized (IOLockedMutex) {
1262
/** Inner class for SerialInputStream */
1263
class SerialInputStream extends InputStream
1266
* @return int the int read
1267
* @throws IOException
1268
* @see java.io.InputStream
1270
*timeout threshold Behavior
1271
*------------------------------------------------------------------------
1272
*0 0 blocks until 1 byte is available timeout > 0,
1273
* threshold = 0, blocks until timeout occurs, returns -1
1275
*>0 >0 blocks until timeout, returns - 1 on timeout, magnitude
1276
* of threshold doesn't play a role.
1277
*0 >0 Blocks until 1 byte, magnitude of threshold doesn't
1280
public synchronized int read() throws IOException
1283
z.reportln( "RXTXPort:SerialInputStream:read() called");
1284
if ( fd == 0 ) throw new IOException();
1285
if ( monThreadisInterrupted )
1287
z.reportln( "+++++++++ read() monThreadisInterrupted" );
1289
synchronized (IOLockedMutex) {
1293
if (debug_read_results)
1294
z.reportln( "RXTXPort:SerialInputStream:read() L" );
1295
waitForTheNativeCodeSilly();
1296
if (debug_read_results)
1297
z.reportln( "RXTXPort:SerialInputStream:read() N" );
1298
int result = readByte();
1299
if (debug_read_results)
1300
//z.reportln( "RXTXPort:SerialInputStream:read() returns byte = " + result );
1301
z.reportln( "RXTXPort:SerialInputStream:read() returns" );
1306
synchronized (IOLockedMutex) {
1313
* @return int number of bytes read
1314
* @throws IOException
1316
*timeout threshold Behavior
1317
*------------------------------------------------------------------------
1318
*0 0 blocks until 1 byte is available
1319
*>0 0 blocks until timeout occurs, returns 0 on timeout
1320
*>0 >0 blocks until timeout or reads threshold bytes,
1321
returns 0 on timeout
1322
*0 >0 blocks until reads threshold bytes
1324
public synchronized int read( byte b[] ) throws IOException
1328
z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + ") called");
1329
if ( monThreadisInterrupted == true )
1333
synchronized (IOLockedMutex) {
1338
waitForTheNativeCodeSilly();
1339
result = read( b, 0, b.length);
1340
if (debug_read_results)
1341
z.reportln( "RXTXPort:SerialInputStream:read() returned " + result + " bytes" );
1346
synchronized (IOLockedMutex) {
1352
read(byte b[], int, int)
1353
Documentation is at http://java.sun.com/products/jdk/1.2/docs/api/java/io/InputStream.html#read(byte[], int, int)
1359
* @return int number of bytes read
1360
* @throws IOException
1362
*timeout threshold Behavior
1363
*------------------------------------------------------------------------
1364
*0 0 blocks until 1 byte is available
1365
*>0 0 blocks until timeout occurs, returns 0 on timeout
1366
*>0 >0 blocks until timeout or reads threshold bytes,
1367
returns 0 on timeout
1368
*0 >0 blocks until either threshold # of bytes or len bytes,
1369
whichever was lower.
1371
public synchronized int read( byte b[], int off, int len )
1375
z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1378
* Some sanity checks
1383
z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
1384
z.reportln("+++++++ IOException()\n");
1385
throw new IOException();
1390
z.reportln("+++++++ NullPointerException()\n");
1392
z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
1393
throw new NullPointerException();
1396
if( (off < 0) || (len < 0) || (off+len > b.length))
1398
z.reportln("+++++++ IndexOutOfBoundsException()\n");
1400
z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1401
throw new IndexOutOfBoundsException();
1405
* Return immediately if len==0
1410
z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1414
* See how many bytes we should read
1421
* If threshold is disabled, read should return as soon
1422
* as data are available (up to the amount of available
1423
* bytes in order to avoid blocking)
1424
* Read may return earlier depending of the receive time
1427
int a = nativeavailable();
1431
Minimum = Math.min( Minimum, a );
1436
* Threshold is enabled. Read should return when
1437
* 'threshold' bytes have been received (or when the
1438
* receive timeout expired)
1440
Minimum = Math.min(Minimum, threshold);
1442
if ( monThreadisInterrupted == true )
1445
z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
1448
synchronized (IOLockedMutex) {
1453
waitForTheNativeCodeSilly();
1454
result = readArray( b, off, Minimum);
1455
if (debug_read_results)
1456
z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes" /*+ new String(b) */);
1461
synchronized (IOLockedMutex) {
1472
* @return int number of bytes read
1473
* @throws IOException
1475
We are trying to catch the terminator in the native code
1476
Right now it is assumed that t[] is an array of 2 bytes.
1478
if the read encounters the two bytes, it will return and the
1479
array will contain the terminator. Otherwise read behavior should
1480
be the same as read( b[], off, len ). Timeouts have not been well
1484
public synchronized int read( byte b[], int off, int len, byte t[] )
1488
z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") called" /*+ new String(b) */ );
1491
* Some sanity checks
1496
z.reportln( "RXTXPort:SerialInputStream:read() fd == 0");
1497
z.reportln("+++++++ IOException()\n");
1498
throw new IOException();
1503
z.reportln("+++++++ NullPointerException()\n");
1505
z.reportln( "RXTXPort:SerialInputStream:read() b == 0");
1506
throw new NullPointerException();
1509
if( (off < 0) || (len < 0) || (off+len > b.length))
1511
z.reportln("+++++++ IndexOutOfBoundsException()\n");
1513
z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1514
throw new IndexOutOfBoundsException();
1518
* Return immediately if len==0
1523
z.reportln( "RXTXPort:SerialInputStream:read() off < 0 ..");
1527
* See how many bytes we should read
1534
* If threshold is disabled, read should return as soon
1535
* as data are available (up to the amount of available
1536
* bytes in order to avoid blocking)
1537
* Read may return earlier depending of the receive time
1540
int a = nativeavailable();
1544
Minimum = Math.min( Minimum, a );
1549
* Threshold is enabled. Read should return when
1550
* 'threshold' bytes have been received (or when the
1551
* receive timeout expired)
1553
Minimum = Math.min(Minimum, threshold);
1555
if ( monThreadisInterrupted == true )
1558
z.reportln( "RXTXPort:SerialInputStream:read() Interrupted");
1561
synchronized (IOLockedMutex) {
1566
waitForTheNativeCodeSilly();
1567
result = readTerminatedArray( b, off, Minimum, t );
1568
if (debug_read_results)
1569
z.reportln( "RXTXPort:SerialInputStream:read(" + b.length + " " + off + " " + len + ") returned " + result + " bytes" /*+ new String(b) */);
1574
synchronized (IOLockedMutex) {
1580
* @return int bytes available
1581
* @throws IOException
1583
public synchronized int available() throws IOException
1585
if ( monThreadisInterrupted == true )
1589
if ( debug_verbose )
1590
z.reportln( "RXTXPort:available() called" );
1591
synchronized (IOLockedMutex) {
1596
int r = nativeavailable();
1597
if ( debug_verbose )
1598
z.reportln( "RXTXPort:available() returning " +
1604
synchronized (IOLockedMutex) {
1612
class MonitorThread extends Thread
1614
/** Note: these have to be separate boolean flags because the
1615
SerialPortEvent constants are NOT bit-flags, they are just
1616
defined as integers from 1 to 10 -DPL */
1617
private volatile boolean CTS=false;
1618
private volatile boolean DSR=false;
1619
private volatile boolean RI=false;
1620
private volatile boolean CD=false;
1621
private volatile boolean OE=false;
1622
private volatile boolean PE=false;
1623
private volatile boolean FE=false;
1624
private volatile boolean BI=false;
1625
private volatile boolean Data=false;
1626
private volatile boolean Output=false;
1631
z.reportln( "RXTXPort:MontitorThread:MonitorThread()");
1634
* run the thread and call the event loop.
1639
z.reportln( "RXTXPort:MontitorThread:run()");
1640
monThreadisInterrupted=false;
1643
z.reportln( "eventLoop() returned");
1645
protected void finalize() throws Throwable
1648
z.reportln( "RXTXPort:MonitorThread exiting");
1652
* A dummy method added so RXTX compiles on Kaffee
1653
* @deprecated deprecated but used in Kaffe
1655
public void setRcvFifoTrigger(int trigger){};
1657
/*------------------------ END OF CommAPI -----------------------------*/
1659
private native static void nativeStaticSetSerialPortParams( String f,
1660
int b, int d, int s, int p )
1661
throws UnsupportedCommOperationException;
1662
private native static boolean nativeStaticSetDSR( String port,
1664
throws UnsupportedCommOperationException;
1665
private native static boolean nativeStaticSetDTR( String port,
1667
throws UnsupportedCommOperationException;
1668
private native static boolean nativeStaticSetRTS( String port,
1670
throws UnsupportedCommOperationException;
1672
private native static boolean nativeStaticIsDSR( String port )
1673
throws UnsupportedCommOperationException;
1674
private native static boolean nativeStaticIsDTR( String port )
1675
throws UnsupportedCommOperationException;
1676
private native static boolean nativeStaticIsRTS( String port )
1677
throws UnsupportedCommOperationException;
1678
private native static boolean nativeStaticIsCTS( String port )
1679
throws UnsupportedCommOperationException;
1680
private native static boolean nativeStaticIsCD( String port )
1681
throws UnsupportedCommOperationException;
1682
private native static boolean nativeStaticIsRI( String port )
1683
throws UnsupportedCommOperationException;
1685
private native static int nativeStaticGetBaudRate( String port )
1686
throws UnsupportedCommOperationException;
1687
private native static int nativeStaticGetDataBits( String port )
1688
throws UnsupportedCommOperationException;
1689
private native static int nativeStaticGetParity( String port )
1690
throws UnsupportedCommOperationException;
1691
private native static int nativeStaticGetStopBits( String port )
1692
throws UnsupportedCommOperationException;
1695
private native byte nativeGetParityErrorChar( )
1696
throws UnsupportedCommOperationException;
1697
private native boolean nativeSetParityErrorChar( byte b )
1698
throws UnsupportedCommOperationException;
1699
private native byte nativeGetEndOfInputChar( )
1700
throws UnsupportedCommOperationException;
1701
private native boolean nativeSetEndOfInputChar( byte b )
1702
throws UnsupportedCommOperationException;
1703
private native boolean nativeSetUartType(String type, boolean test)
1704
throws UnsupportedCommOperationException;
1705
native String nativeGetUartType()
1706
throws UnsupportedCommOperationException;
1707
private native boolean nativeSetBaudBase(int BaudBase)
1708
throws UnsupportedCommOperationException;
1709
private native int nativeGetBaudBase()
1710
throws UnsupportedCommOperationException;
1711
private native boolean nativeSetDivisor(int Divisor)
1712
throws UnsupportedCommOperationException;
1713
private native int nativeGetDivisor()
1714
throws UnsupportedCommOperationException;
1715
private native boolean nativeSetLowLatency()
1716
throws UnsupportedCommOperationException;
1717
private native boolean nativeGetLowLatency()
1718
throws UnsupportedCommOperationException;
1719
private native boolean nativeSetCallOutHangup(boolean NoHup)
1720
throws UnsupportedCommOperationException;
1721
private native boolean nativeGetCallOutHangup()
1722
throws UnsupportedCommOperationException;
1723
private native boolean nativeClearCommInput()
1724
throws UnsupportedCommOperationException;
1727
* Extension to CommAPI
1728
* This is an extension to CommAPI. It may not be supported on
1729
* all operating systems.
1731
* This is only accurate up to 38600 baud currently.
1733
* @param port the name of the port thats been preopened
1734
* @return BaudRate on success
1735
* @throws UnsupportedCommOperationException;
1736
* This will not behave as expected with custom speeds
1739
public static int staticGetBaudRate( String port )
1740
throws UnsupportedCommOperationException
1744
"RXTXPort:staticGetBaudRate( " + port + " )");
1745
return(nativeStaticGetBaudRate( port ));
1748
* Extension to CommAPI
1749
* This is an extension to CommAPI. It may not be supported on
1750
* all operating systems.
1752
* @param port the name of the port thats been preopened
1753
* @return DataBits on success
1754
* @throws UnsupportedCommOperationException;
1757
public static int staticGetDataBits( String port )
1758
throws UnsupportedCommOperationException
1762
"RXTXPort:staticGetDataBits( " + port + " )");
1763
return(nativeStaticGetDataBits( port ) );
1767
* Extension to CommAPI
1768
* This is an extension to CommAPI. It may not be supported on
1769
* all operating systems.
1771
* @param port the name of the port thats been preopened
1772
* @return Parity on success
1773
* @throws UnsupportedCommOperationException;
1776
public static int staticGetParity( String port )
1777
throws UnsupportedCommOperationException
1781
"RXTXPort:staticGetParity( " + port + " )");
1782
return( nativeStaticGetParity( port ) );
1786
* Extension to CommAPI
1787
* This is an extension to CommAPI. It may not be supported on
1788
* all operating systems.
1790
* @param port the name of the port thats been preopened
1791
* @return StopBits on success
1792
* @throws UnsupportedCommOperationException;
1795
public static int staticGetStopBits( String port )
1796
throws UnsupportedCommOperationException
1800
"RXTXPort:staticGetStopBits( " + port + " )");
1801
return(nativeStaticGetStopBits( port ) );
1805
* Extension to CommAPI
1806
* This is an extension to CommAPI. It may not be supported on
1807
* all operating systems.
1809
* Set the SerialPort parameters
1810
* 1.5 stop bits requires 5 databits
1817
* @throws UnsupportedCommOperationException
1818
* @see gnu.io.UnsupportedCommOperationException
1821
public static void staticSetSerialPortParams( String f, int b, int d,
1823
throws UnsupportedCommOperationException
1827
"RXTXPort:staticSetSerialPortParams( " +
1828
f + " " + b + " " + d + " " + s + " " + p );
1829
nativeStaticSetSerialPortParams( f, b, d, s, p );
1833
* Extension to CommAPI
1834
* This is an extension to CommAPI. It may not be supported on
1835
* all operating systems.
1837
* Open the port and set DSR. remove lockfile and do not close
1838
* This is so some software can appear to set the DSR before 'opening'
1839
* the port a second time later on.
1841
* @return true on success
1842
* @throws UnsupportedCommOperationException;
1846
public static boolean staticSetDSR( String port, boolean flag )
1847
throws UnsupportedCommOperationException
1850
z.reportln( "RXTXPort:staticSetDSR( " + port +
1852
return( nativeStaticSetDSR( port, flag ) );
1856
* Extension to CommAPI
1857
* This is an extension to CommAPI. It may not be supported on
1858
* all operating systems.
1860
* Open the port and set DTR. remove lockfile and do not close
1861
* This is so some software can appear to set the DTR before 'opening'
1862
* the port a second time later on.
1864
* @return true on success
1865
* @throws UnsupportedCommOperationException;
1869
public static boolean staticSetDTR( String port, boolean flag )
1870
throws UnsupportedCommOperationException
1873
z.reportln( "RXTXPort:staticSetDTR( " + port +
1875
return( nativeStaticSetDTR( port, flag ) );
1879
* Extension to CommAPI
1880
* This is an extension to CommAPI. It may not be supported on
1881
* all operating systems.
1883
* Open the port and set RTS. remove lockfile and do not close
1884
* This is so some software can appear to set the RTS before 'opening'
1885
* the port a second time later on.
1888
* @throws UnsupportedCommOperationException;
1892
public static boolean staticSetRTS( String port, boolean flag )
1893
throws UnsupportedCommOperationException
1896
z.reportln( "RXTXPort:staticSetRTS( " + port +
1898
return( nativeStaticSetRTS( port, flag ) );
1902
* Extension to CommAPI
1903
* This is an extension to CommAPI. It may not be supported on
1904
* all operating systems.
1906
* find the fd and return RTS without using a Java open() call
1909
* @return true if asserted
1910
* @throws UnsupportedCommOperationException;
1914
public static boolean staticIsRTS( String port )
1915
throws UnsupportedCommOperationException
1918
z.reportln( "RXTXPort:staticIsRTS( " + port + " )" );
1919
return( nativeStaticIsRTS( port ) );
1922
* Extension to CommAPI
1923
* This is an extension to CommAPI. It may not be supported on
1924
* all operating systems.
1926
* find the fd and return CD without using a Java open() call
1929
* @return true if asserted
1930
* @throws UnsupportedCommOperationException;
1934
public static boolean staticIsCD( String port )
1935
throws UnsupportedCommOperationException
1938
z.reportln( "RXTXPort:staticIsCD( " + port + " )" );
1939
return( nativeStaticIsCD( port ) );
1942
* Extension to CommAPI
1943
* This is an extension to CommAPI. It may not be supported on
1944
* all operating systems.
1946
* find the fd and return CTS without using a Java open() call
1949
* @return true if asserted
1950
* @throws UnsupportedCommOperationException;
1954
public static boolean staticIsCTS( String port )
1955
throws UnsupportedCommOperationException
1958
z.reportln( "RXTXPort:staticIsCTS( " + port + " )" );
1959
return( nativeStaticIsCTS( port ) );
1962
* Extension to CommAPI
1963
* This is an extension to CommAPI. It may not be supported on
1964
* all operating systems.
1966
* find the fd and return DSR without using a Java open() call
1969
* @return true if asserted
1970
* @throws UnsupportedCommOperationException;
1974
public static boolean staticIsDSR( String port )
1975
throws UnsupportedCommOperationException
1978
z.reportln( "RXTXPort:staticIsDSR( " + port + " )" );
1979
return( nativeStaticIsDSR( port ) );
1982
* Extension to CommAPI
1983
* This is an extension to CommAPI. It may not be supported on
1984
* all operating systems.
1986
* find the fd and return DTR without using a Java open() call
1989
* @return true if asserted
1990
* @throws UnsupportedCommOperationException;
1994
public static boolean staticIsDTR( String port )
1995
throws UnsupportedCommOperationException
1998
z.reportln( "RXTXPort:staticIsDTR( " + port + " )" );
1999
return( nativeStaticIsDTR( port ) );
2002
* Extension to CommAPI
2003
* This is an extension to CommAPI. It may not be supported on
2004
* all operating systems.
2006
* find the fd and return RI without using a Java open() call
2009
* @return true if asserted
2010
* @throws UnsupportedCommOperationException;
2014
public static boolean staticIsRI( String port )
2015
throws UnsupportedCommOperationException
2018
z.reportln( "RXTXPort:staticIsRI( " + port + " )" );
2019
return( nativeStaticIsRI( port ) );
2024
* Extension to CommAPI
2025
* This is an extension to CommAPI. It may not be supported on
2026
* all operating systems.
2027
* @return int the Parity Error Character
2028
* @throws UnsupportedCommOperationException;
2030
* Anyone know how to do this in Unix?
2033
public byte getParityErrorChar( )
2034
throws UnsupportedCommOperationException
2038
z.reportln( "getParityErrorChar()" );
2039
ret = nativeGetParityErrorChar();
2041
z.reportln( "getParityErrorChar() returns " +
2047
* Extension to CommAPI
2048
* This is an extension to CommAPI. It may not be supported on
2049
* all operating systems.
2050
* @param b Parity Error Character
2051
* @return boolean true on success
2052
* @throws UnsupportedCommOperationException;
2054
* Anyone know how to do this in Unix?
2057
public boolean setParityErrorChar( byte b )
2058
throws UnsupportedCommOperationException
2061
z.reportln( "setParityErrorChar(" + b + ")" );
2062
return( nativeSetParityErrorChar( b ) );
2066
* Extension to CommAPI
2067
* This is an extension to CommAPI. It may not be supported on
2068
* all operating systems.
2069
* @return int the End of Input Character
2070
* @throws UnsupportedCommOperationException;
2072
* Anyone know how to do this in Unix?
2075
public byte getEndOfInputChar( )
2076
throws UnsupportedCommOperationException
2080
z.reportln( "getEndOfInputChar()" );
2081
ret = nativeGetEndOfInputChar();
2083
z.reportln( "getEndOfInputChar() returns " +
2089
* Extension to CommAPI
2090
* This is an extension to CommAPI. It may not be supported on
2091
* all operating systems.
2092
* @param b End Of Input Character
2093
* @return boolean true on success
2094
* @throws UnsupportedCommOperationException;
2097
public boolean setEndOfInputChar( byte b )
2098
throws UnsupportedCommOperationException
2101
z.reportln( "setEndOfInputChar(" + b + ")" );
2102
return( nativeSetEndOfInputChar( b ) );
2106
* Extension to CommAPI
2107
* This is an extension to CommAPI. It may not be supported on
2108
* all operating systems.
2109
* @param type String representation of the UART type which mayb
2110
* be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2112
* @param test boolean flag to determin if the UART should be tested.
2113
* @return boolean true on success
2114
* @throws UnsupportedCommOperationException;
2116
public boolean setUARTType(String type, boolean test)
2117
throws UnsupportedCommOperationException
2120
z.reportln( "RXTXPort:setUARTType()");
2121
return nativeSetUartType(type, test);
2124
* Extension to CommAPI
2125
* This is an extension to CommAPI. It may not be supported on
2126
* all operating systems.
2127
* @return type String representation of the UART type which mayb
2128
* be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2"
2130
* @throws UnsupportedCommOperationException;
2132
public String getUARTType() throws UnsupportedCommOperationException
2134
return nativeGetUartType();
2138
* Extension to CommAPI. Set Baud Base to 38600 on Linux and W32
2140
* @param BaudBase The clock frequency divided by 16. Default
2141
* BaudBase is 115200.
2142
* @return true on success
2143
* @throws UnsupportedCommOperationException, IOException
2146
public boolean setBaudBase(int BaudBase)
2147
throws UnsupportedCommOperationException,
2151
z.reportln( "RXTXPort:setBaudBase()");
2152
return nativeSetBaudBase(BaudBase);
2156
* Extension to CommAPI
2158
* @throws UnsupportedCommOperationException, IOException
2161
public int getBaudBase() throws UnsupportedCommOperationException,
2165
z.reportln( "RXTXPort:getBaudBase()");
2166
return nativeGetBaudBase();
2170
* Extension to CommAPI. Set Baud Base to 38600 on Linux and W32
2173
* @throws UnsupportedCommOperationException, IOException
2176
public boolean setDivisor(int Divisor)
2177
throws UnsupportedCommOperationException, IOException
2180
z.reportln( "RXTXPort:setDivisor()");
2181
return nativeSetDivisor(Divisor);
2185
* Extension to CommAPI
2187
* @throws UnsupportedCommOperationException, IOException
2190
public int getDivisor() throws UnsupportedCommOperationException,
2194
z.reportln( "RXTXPort:getDivisor()");
2195
return nativeGetDivisor();
2199
* Extension to CommAPI
2200
* returns boolean true on success
2201
* @throws UnsupportedCommOperationException
2204
public boolean setLowLatency() throws UnsupportedCommOperationException
2207
z.reportln( "RXTXPort:setLowLatency()");
2208
return nativeSetLowLatency();
2212
* Extension to CommAPI
2213
* returns boolean true on success
2214
* @throws UnsupportedCommOperationException
2217
public boolean getLowLatency() throws UnsupportedCommOperationException
2220
z.reportln( "RXTXPort:getLowLatency()");
2221
return nativeGetLowLatency();
2225
* Extension to CommAPI
2226
* returns boolean true on success
2227
* @throws UnsupportedCommOperationException
2230
public boolean setCallOutHangup(boolean NoHup)
2231
throws UnsupportedCommOperationException
2234
z.reportln( "RXTXPort:setCallOutHangup()");
2235
return nativeSetCallOutHangup(NoHup);
2239
* Extension to CommAPI
2240
* returns boolean true on success
2241
* @throws UnsupportedCommOperationException
2244
public boolean getCallOutHangup()
2245
throws UnsupportedCommOperationException
2248
z.reportln( "RXTXPort:getCallOutHangup()");
2249
return nativeGetCallOutHangup();
2253
* Extension to CommAPI
2254
* returns boolean true on success
2255
* @throws UnsupportedCommOperationException
2258
public boolean clearCommInput()
2259
throws UnsupportedCommOperationException
2262
z.reportln( "RXTXPort:clearCommInput()");
2263
return nativeClearCommInput();
2266
/*------------------------ END OF CommAPI Extensions -----------------------*/