gnu.io

Class RXTXPort


public final class RXTXPort
extends SerialPort

An extension of gnu.io.SerialPort
See Also:
SerialPort

Field Summary

protected static boolean
debug
protected static boolean
debug_events
protected static boolean
debug_read
protected static boolean
debug_read_results
protected static boolean
debug_verbose
protected static boolean
debug_write

Constructor Summary

RXTXPort(String name)
Open the named port

Method Summary

int
NativegetReceiveTimeout()
void
addEventListener(SerialPortEventListener lsnr)
boolean
checkMonitorThread()
boolean
clearCommInput()
Extension to CommAPI returns boolean true on success
void
close()
void
disableReceiveFraming()
void
disableReceiveThreshold()
void
disableReceiveTimeout()
void
enableReceiveFraming(int f)
Receive framing control
void
enableReceiveThreshold(int thresh)
void
enableReceiveTimeout(int time)
protected void
finalize()
Finalize the port
int
getBaudBase()
Extension to CommAPI
int
getBaudRate()
boolean
getCallOutHangup()
Extension to CommAPI returns boolean true on success
int
getDataBits()
int
getDivisor()
Extension to CommAPI
byte
getEndOfInputChar()
Extension to CommAPI This is an extension to CommAPI.
int
getFlowControlMode()
int
getInputBufferSize()
InputStream
getInputStream()
get the InputStream
boolean
getLowLatency()
Extension to CommAPI returns boolean true on success
int
getOutputBufferSize()
OutputStream
getOutputStream()
get the OutputStream
int
getParity()
byte
getParityErrorChar()
Extension to CommAPI This is an extension to CommAPI.
int
getReceiveFramingByte()
int
getReceiveThreshold()
int
getReceiveTimeout()
int
getStopBits()
String
getUARTType()
Extension to CommAPI This is an extension to CommAPI.
boolean
isCD()
boolean
isCTS()
boolean
isDSR()
boolean
isDTR()
boolean
isRI()
boolean
isRTS()
boolean
isReceiveFramingEnabled()
boolean
isReceiveThresholdEnabled()
boolean
isReceiveTimeoutEnabled()
protected boolean
nativeDrain(boolean i)
protected int
nativeavailable()
RXTXPort read methods
void
notifyOnBreakInterrupt(boolean enable)
void
notifyOnCTS(boolean enable)
void
notifyOnCarrierDetect(boolean enable)
void
notifyOnDSR(boolean enable)
void
notifyOnDataAvailable(boolean enable)
void
notifyOnFramingError(boolean enable)
void
notifyOnOutputEmpty(boolean enable)
void
notifyOnOverrunError(boolean enable)
void
notifyOnParityError(boolean enable)
void
notifyOnRingIndicator(boolean enable)
protected int
readArray(b[] , int off, int len)
protected int
readByte()
protected int
readTerminatedArray(b[] , int off, int len, t[] )
void
removeEventListener()
Remove the serial port event listener
void
sendBreak(int duration)
Write to the port
boolean
sendEvent(int event, boolean state)
boolean
setBaudBase(int BaudBase)
Extension to CommAPI.
boolean
setCallOutHangup(boolean NoHup)
Extension to CommAPI returns boolean true on success
void
setDTR(boolean state)
boolean
setDivisor(int Divisor)
Extension to CommAPI.
boolean
setEndOfInputChar(byte b)
Extension to CommAPI This is an extension to CommAPI.
void
setFlowControlMode(int flowcontrol)
void
setInputBufferSize(int size)
boolean
setLowLatency()
Extension to CommAPI returns boolean true on success
void
setOutputBufferSize(int size)
boolean
setParityErrorChar(byte b)
Extension to CommAPI This is an extension to CommAPI.
void
setRTS(boolean state)
void
setRcvFifoTrigger(int trigger)
Deprecated. deprecated but used in Kaffe
void
setSerialPortParams(int b, int d, int s, int p)
boolean
setUARTType(String type, boolean test)
Extension to CommAPI This is an extension to CommAPI.
static int
staticGetBaudRate(String port)
Extension to CommAPI This is an extension to CommAPI.
static int
staticGetDataBits(String port)
Extension to CommAPI This is an extension to CommAPI.
static int
staticGetParity(String port)
Extension to CommAPI This is an extension to CommAPI.
static int
staticGetStopBits(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsCD(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsCTS(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsDSR(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsDTR(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsRI(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticIsRTS(String port)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticSetDSR(String port, boolean flag)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticSetDTR(String port, boolean flag)
Extension to CommAPI This is an extension to CommAPI.
static boolean
staticSetRTS(String port, boolean flag)
Extension to CommAPI This is an extension to CommAPI.
static void
staticSetSerialPortParams(String f, int b, int d, int s, int p)
Extension to CommAPI This is an extension to CommAPI.
protected void
waitForTheNativeCodeSilly()
Give the native code a chance to start listening to the hardware or should we say give the native code control of the issue.
protected void
writeArray(b[] , int off, int len, boolean i)
protected void
writeByte(int b, boolean i)

Field Details

debug

protected static final boolean debug
Field Value:
false

debug_events

protected static final boolean debug_events
Field Value:
false

debug_read

protected static final boolean debug_read
Field Value:
false

debug_read_results

protected static final boolean debug_read_results
Field Value:
false

debug_verbose

protected static final boolean debug_verbose
Field Value:
false

debug_write

protected static final boolean debug_write
Field Value:
false

Constructor Details

RXTXPort

public RXTXPort(String name)
            throws PortInUseException
Open the named port
Parameters:
name - the name of the device to open

Method Details

NativegetReceiveTimeout

public int NativegetReceiveTimeout()
Returns:
int the timeout

addEventListener

public void addEventListener(SerialPortEventListener lsnr)
            throws TooManyListenersException

checkMonitorThread

public boolean checkMonitorThread()

clearCommInput

public boolean clearCommInput()
            throws UnsupportedCommOperationException
Extension to CommAPI returns boolean true on success

close

public void close()

disableReceiveFraming

public void disableReceiveFraming()

disableReceiveThreshold

public void disableReceiveThreshold()

disableReceiveTimeout

public void disableReceiveTimeout()

enableReceiveFraming

public void enableReceiveFraming(int f)
            throws UnsupportedCommOperationException
Receive framing control
Parameters:
f - framming

enableReceiveThreshold

public void enableReceiveThreshold(int thresh)
Parameters:
thresh - threshold

enableReceiveTimeout

public void enableReceiveTimeout(int time)
Parameters:
time -

finalize

protected void finalize()
Finalize the port

getBaudBase

public int getBaudBase()
            throws UnsupportedCommOperationException,
                   IOException
Extension to CommAPI
Returns:
BaudBase

getBaudRate

public int getBaudRate()
Returns:
int representing the baudrate This will not behave as expected with custom speeds

getCallOutHangup

public boolean getCallOutHangup()
            throws UnsupportedCommOperationException
Extension to CommAPI returns boolean true on success

getDataBits

public int getDataBits()
Returns:
int representing the databits

getDivisor

public int getDivisor()
            throws UnsupportedCommOperationException,
                   IOException
Extension to CommAPI
Returns:
Divisor;

getEndOfInputChar

public byte getEndOfInputChar()
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Returns:
int the End of Input Character

getFlowControlMode

public int getFlowControlMode()
Returns:
int representing the flowmode

getInputBufferSize

public int getInputBufferSize()

getInputStream

public InputStream getInputStream()
get the InputStream
Returns:
InputStream
See Also:
java.io.InputStream

getLowLatency

public boolean getLowLatency()
            throws UnsupportedCommOperationException
Extension to CommAPI returns boolean true on success

getOutputBufferSize

public int getOutputBufferSize()
Returns:
in the output buffer size

getOutputStream

public OutputStream getOutputStream()
get the OutputStream
Returns:
OutputStream

getParity

public int getParity()
Returns:
int representing the parity

getParityErrorChar

public byte getParityErrorChar()
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Returns:
int the Parity Error Character

getReceiveFramingByte

public int getReceiveFramingByte()
Returns:
int representing the framing byte

getReceiveThreshold

public int getReceiveThreshold()
Returns:
int the recieve threshold

getReceiveTimeout

public int getReceiveTimeout()
Returns:
int the timeout

getStopBits

public int getStopBits()
Returns:
int representing the stopbits

getUARTType

public String getUARTType()
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Returns:
type String representation of the UART type which mayb be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2" or "16750".

isCD

public boolean isCD()
Returns:
boolean true if CD is set

isCTS

public boolean isCTS()
Returns:
boolean true if CTS is set

isDSR

public boolean isDSR()
Returns:
boolean true if DSR is set

isDTR

public boolean isDTR()
Returns:
true if DTR is set

isRI

public boolean isRI()
Returns:
boolean true if RI is set

isRTS

public boolean isRTS()
Returns:
boolean true if RTS is set

isReceiveFramingEnabled

public boolean isReceiveFramingEnabled()
Returns:
true if framing is enabled

isReceiveThresholdEnabled

public boolean isReceiveThresholdEnabled()
Returns:
boolean true if receive threshold is enabled

isReceiveTimeoutEnabled

public boolean isReceiveTimeoutEnabled()
Returns:
boolean true if recieve timeout is enabled

nativeDrain

protected boolean nativeDrain(boolean i)
            throws IOException

nativeavailable

protected int nativeavailable()
            throws IOException
RXTXPort read methods

notifyOnBreakInterrupt

public void notifyOnBreakInterrupt(boolean enable)
Parameters:
enable -

notifyOnCTS

public void notifyOnCTS(boolean enable)
Parameters:
enable -

notifyOnCarrierDetect

public void notifyOnCarrierDetect(boolean enable)
Parameters:
enable -

notifyOnDSR

public void notifyOnDSR(boolean enable)
Parameters:
enable -

notifyOnDataAvailable

public void notifyOnDataAvailable(boolean enable)

notifyOnFramingError

public void notifyOnFramingError(boolean enable)
Parameters:
enable -

notifyOnOutputEmpty

public void notifyOnOutputEmpty(boolean enable)
Parameters:
enable -

notifyOnOverrunError

public void notifyOnOverrunError(boolean enable)
Parameters:
enable -

notifyOnParityError

public void notifyOnParityError(boolean enable)
Parameters:
enable -

notifyOnRingIndicator

public void notifyOnRingIndicator(boolean enable)
Parameters:
enable -

readArray

protected int readArray(b[] ,
                        int off,
                        int len)
            throws IOException

readByte

protected int readByte()
            throws IOException

readTerminatedArray

protected int readTerminatedArray(b[] ,
                                  int off,
                                  int len,
                                  t[] )
            throws IOException

removeEventListener

public void removeEventListener()
Remove the serial port event listener

sendBreak

public void sendBreak(int duration)
Write to the port
Parameters:
duration -

sendEvent

public boolean sendEvent(int event,
                         boolean state)
Parameters:
event -
state -
Returns:
boolean true if the port is closing

setBaudBase

public boolean setBaudBase(int BaudBase)
            throws UnsupportedCommOperationException,
                   IOException
Extension to CommAPI. Set Baud Base to 38600 on Linux and W32 before using.
Parameters:
BaudBase - The clock frequency divided by 16. Default BaudBase is 115200.
Returns:
true on success

setCallOutHangup

public boolean setCallOutHangup(boolean NoHup)
            throws UnsupportedCommOperationException
Extension to CommAPI returns boolean true on success

setDTR

public void setDTR(boolean state)
Parameters:
state -

setDivisor

public boolean setDivisor(int Divisor)
            throws UnsupportedCommOperationException,
                   IOException
Extension to CommAPI. Set Baud Base to 38600 on Linux and W32 before using.
Parameters:
Divisor -

setEndOfInputChar

public boolean setEndOfInputChar(byte b)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
b - End Of Input Character
Returns:
boolean true on success

setFlowControlMode

public void setFlowControlMode(int flowcontrol)
Parameters:
flowcontrol - FLOWCONTROL_NONE is default

setInputBufferSize

public void setInputBufferSize(int size)
Parameters:
size -

setLowLatency

public boolean setLowLatency()
            throws UnsupportedCommOperationException
Extension to CommAPI returns boolean true on success

setOutputBufferSize

public void setOutputBufferSize(int size)
Parameters:
size -

setParityErrorChar

public boolean setParityErrorChar(byte b)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
b - Parity Error Character
Returns:
boolean true on success

setRTS

public void setRTS(boolean state)
Parameters:
state -

setRcvFifoTrigger

public void setRcvFifoTrigger(int trigger)

Deprecated. deprecated but used in Kaffe

A dummy method added so RXTX compiles on Kaffee

setSerialPortParams

public void setSerialPortParams(int b,
                                int d,
                                int s,
                                int p)
            throws UnsupportedCommOperationException

setUARTType

public boolean setUARTType(String type,
                           boolean test)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
type - String representation of the UART type which mayb be "none", "8250", "16450", "16550", "16550A", "16650", "16550V2" or "16750".
test - boolean flag to determin if the UART should be tested.
Returns:
boolean true on success

staticGetBaudRate

public static int staticGetBaudRate(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. This is only accurate up to 38600 baud currently.
Parameters:
port - the name of the port thats been preopened
Returns:
BaudRate on success

staticGetDataBits

public static int staticGetDataBits(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
port - the name of the port thats been preopened
Returns:
DataBits on success

staticGetParity

public static int staticGetParity(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
port - the name of the port thats been preopened
Returns:
Parity on success

staticGetStopBits

public static int staticGetStopBits(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems.
Parameters:
port - the name of the port thats been preopened
Returns:
StopBits on success

staticIsCD

public static boolean staticIsCD(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return CD without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticIsCTS

public static boolean staticIsCTS(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return CTS without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticIsDSR

public static boolean staticIsDSR(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return DSR without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticIsDTR

public static boolean staticIsDTR(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return DTR without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticIsRI

public static boolean staticIsRI(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return RI without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticIsRTS

public static boolean staticIsRTS(String port)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. find the fd and return RTS without using a Java open() call
Parameters:
port -
Returns:
true if asserted

staticSetDSR

public static boolean staticSetDSR(String port,
                                   boolean flag)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. Open the port and set DSR. remove lockfile and do not close This is so some software can appear to set the DSR before 'opening' the port a second time later on.
Returns:
true on success

staticSetDTR

public static boolean staticSetDTR(String port,
                                   boolean flag)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. Open the port and set DTR. remove lockfile and do not close This is so some software can appear to set the DTR before 'opening' the port a second time later on.
Returns:
true on success

staticSetRTS

public static boolean staticSetRTS(String port,
                                   boolean flag)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. Open the port and set RTS. remove lockfile and do not close This is so some software can appear to set the RTS before 'opening' the port a second time later on.
Returns:
none

staticSetSerialPortParams

public static void staticSetSerialPortParams(String f,
                                             int b,
                                             int d,
                                             int s,
                                             int p)
            throws UnsupportedCommOperationException
Extension to CommAPI This is an extension to CommAPI. It may not be supported on all operating systems. Set the SerialPort parameters 1.5 stop bits requires 5 databits
Parameters:
f - filename
b - baudrate
d - databits
s - stopbits
p - parity

waitForTheNativeCodeSilly

protected void waitForTheNativeCodeSilly()
Give the native code a chance to start listening to the hardware or should we say give the native code control of the issue. This is important for applications that flicker the Monitor thread while keeping the port open. In worst case test cases this loops once or twice every time.

writeArray

protected void writeArray(b[] ,
                          int off,
                          int len,
                          boolean i)
            throws IOException

writeByte

protected void writeByte(int b,
                         boolean i)
            throws IOException