gnu.io
Class RXTXPort

java.lang.Object
  extended bygnu.io.CommPort
      extended bygnu.io.SerialPort
          extended bygnu.io.RXTXPort

public class RXTXPort
extends SerialPort

Author:
juangui TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Field Summary
 
Fields inherited from class gnu.io.SerialPort
DATABITS_5, DATABITS_6, DATABITS_7, DATABITS_8, FLOWCONTROL_NONE, FLOWCONTROL_RTSCTS_IN, FLOWCONTROL_RTSCTS_OUT, FLOWCONTROL_XONXOFF_IN, FLOWCONTROL_XONXOFF_OUT, PARITY_EVEN, PARITY_MARK, PARITY_NONE, PARITY_ODD, PARITY_SPACE, STOPBITS_1, STOPBITS_1_5, STOPBITS_2
 
Constructor Summary
RXTXPort(java.lang.String _portName)
          Constructor
 
Method Summary
 void addEventListener(SerialPortEventListener lsnr)
          Registers a SerialPortEventListener object to listen for SerialEvents.
 void close()
          Closes the communications port.
 int getBaudRate()
          Gets the currently configured baud rate.
 int getDataBits()
          Gets the currently configured number of data bits.
 int getFlowControlMode()
          Gets the currently configured flow control mode.
 int getParity()
          Get the currently configured parity setting.
 int getStopBits()
          Gets the currently defined stop bits.
 boolean isCD()
          Gets the state of the CD (Carrier Detect) bit in the UART, if supported by the underlying implementation.
 boolean isCTS()
          Gets the state of the CTS (Clear To Send) bit in the UART, if supported by the underlying implementation.
 boolean isDSR()
          Gets the state of the DSR (Data Set Ready) bit in the UART, if supported by the underlying implementation.
 boolean isDTR()
          Gets the state of the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.
 boolean isRI()
          Gets the state of the RI (Ring Indicator) bit in the UART, if supported by the underlying implementation.
 boolean isRTS()
          Gets the state of the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
 void notifyOnBreakInterrupt(boolean enable)
          Expresses interest in receiving notification when there is a break interrupt on the line.
 void notifyOnCarrierDetect(boolean enable)
          Expresses interest in receiving notification when the CD (Carrier Detect) bit changes.
 void notifyOnCTS(boolean enable)
          Expresses interest in receiving notification when the CTS (Clear To Send) bit changes.
 void notifyOnDataAvailable(boolean enable)
          Expresses interest in receiving notification when input data is available.
 void notifyOnDSR(boolean enable)
          Expresses interest in receiving notification when the DSR (Data Set Ready) bit changes.
 void notifyOnFramingError(boolean enable)
          Expresses interest in receiving notification when there is a framing error.
 void notifyOnOutputEmpty(boolean enable)
          Expresses interest in receiving notification when the output buffer is empty.
 void notifyOnOverrunError(boolean enable)
          Expresses interest in receiving notification when there is an overrun error.
 void notifyOnParityError(boolean enable)
          Expresses interest in receiving notification when there is a parity error.
 void notifyOnRingIndicator(boolean enable)
          Expresses interest in receiving notification when the RI (Ring Indicator) bit changes.
 void removeEventListener()
          Deregisters event listener registered using addEventListener.
 void sendBreak(int millis)
          Sends a break of millis milliseconds duration.
 void setDTR(boolean dtr)
          Sets or clears the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.
 void setFlowControlMode(int flowcontrol)
          Sets the flow control mode.
 void setRTS(boolean rts)
          Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
 void setSerialPortParams(int _baudRate, int _dataBits, int _stopBits, int _parity)
          Sets serial port parameters.
 
Methods inherited from class gnu.io.SerialPort
disableReceiveFraming, disableReceiveThreshold, disableReceiveTimeout, enableReceiveFraming, enableReceiveThreshold, enableReceiveTimeout, getInputBufferSize, getInputStream, getOutputBufferSize, getOutputStream, getReceiveFramingByte, getReceiveThreshold, getReceiveTimeout, isReceiveFramingEnabled, isReceiveThresholdEnabled, isReceiveTimeoutEnabled, setInputBufferSize, setOutputBufferSize, setRcvFifoTrigger
 
Methods inherited from class gnu.io.CommPort
getName, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RXTXPort

public RXTXPort(java.lang.String _portName)
         throws PortInUseException
Constructor

Parameters:
_portName -
Throws:
PortInUseException
Method Detail

close

public void close()
Closes the communications port. The application must call close when it is done with the port. Notification of this ownership change will be propagated to all classes registered using addPortOwnershipListener.

Overrides:
close in class CommPort

getBaudRate

public int getBaudRate()
Description copied from class: SerialPort
Gets the currently configured baud rate.

Specified by:
getBaudRate in class SerialPort
Returns:
integer value indicating the baud rate

getDataBits

public int getDataBits()
Description copied from class: SerialPort
Gets the currently configured number of data bits.

Specified by:
getDataBits in class SerialPort
Returns:
integer that can be equal to DATABITS_5, DATABITS_6, DATABITS_7, or DATABITS_8

getStopBits

public int getStopBits()
Description copied from class: SerialPort
Gets the currently defined stop bits.

Specified by:
getStopBits in class SerialPort
Returns:
integer that can be equal to STOPBITS_1, STOPBITS_2, or STOPBITS_1_5

getParity

public int getParity()
Description copied from class: SerialPort
Get the currently configured parity setting.

Specified by:
getParity in class SerialPort
Returns:
integer that can be equal to PARITY_NONE, PARITY_ODD, PARITY_EVEN, PARITY_MARK or PARITY_SPACE.

sendBreak

public void sendBreak(int millis)
Description copied from class: SerialPort
Sends a break of millis milliseconds duration. Note that it may not be possible to time the duration of the break under certain Operating Systems. Hence this parameter is advisory.

Specified by:
sendBreak in class SerialPort
Parameters:
millis - - duration of break to send

setFlowControlMode

public void setFlowControlMode(int flowcontrol)
                        throws UnsupportedCommOperationException
Description copied from class: SerialPort
Sets the flow control mode.

Specified by:
setFlowControlMode in class SerialPort
Parameters:
flowcontrol - - control Can be a bitmask combination of - FLOWCONTROL_NONE: no flow control - FLOWCONTROL_RTSCTS_IN: RTS/CTS (hardware) flow control for input - FLOWCONTROL_RTSCTS_OUT: RTS/CTS (hardware) flow control for output - FLOWCONTROL_XONXOFF_IN: XON/XOFF (software) flow control for input - FLOWCONTROL_XONXOFF_OUT: XON/XOFF (software) flow control for output
Throws:
UnsupportedCommOperationException - - if any of the flow control mode was not supported by the underline OS, or if input and output flow control are set to different values, i.e. one hardware and one software. The flow control mode will revert to the value before the call was made.

getFlowControlMode

public int getFlowControlMode()
Description copied from class: SerialPort
Gets the currently configured flow control mode.

Specified by:
getFlowControlMode in class SerialPort
Returns:
an integer bitmask of the modes FLOWCONTROL_NONE, FLOWCONTROL_RTSCTS_IN, FLOWCONTROL_RTSCTS_OUT, FLOWCONTROL_XONXOFF_IN, and FLOWCONTROL_XONXOFF_OUT.

setSerialPortParams

public void setSerialPortParams(int _baudRate,
                                int _dataBits,
                                int _stopBits,
                                int _parity)
                         throws UnsupportedCommOperationException
Sets serial port parameters.

Specified by:
setSerialPortParams in class SerialPort
Parameters:
_baudRate - - If the baudrate passed in by the application is unsupported by the driver, the driver will throw an UnsupportedCommOperationException
_dataBits - - One of the following constants: - DATABITS_5: 5 bits - DATABITS_6: 6 bits - DATABITS_7: 7 bits - DATABITS_8: 8 bits
_stopBits - - One of the following constants: - STOPBITS_1: 1 stop bit - STOPBITS_2: 2 stop bits - STOPBITS_1_5: 1.5 stop bits
_parity - - One of the following constants: - PARITY_NONE: no parity - PARITY_ODD: odd parity - PARITY_EVEN: even parity - PARITY_MARK: mark parity - PARITY_SPACE: space parity
Throws:
UnsupportedCommOperationException - - if any of the above parameters are specified incorrectly. All four of the parameters will revert to the values before the call was made. DEFAULT: 9600 baud, 8 data bits, 1 stop bit, no parity

setDTR

public void setDTR(boolean dtr)
Description copied from class: SerialPort
Sets or clears the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.

Specified by:
setDTR in class SerialPort
Parameters:
dtr - - true: set DTR - false: clear DTR

isDTR

public boolean isDTR()
Description copied from class: SerialPort
Gets the state of the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.

Specified by:
isDTR in class SerialPort
Returns:

setRTS

public void setRTS(boolean rts)
Description copied from class: SerialPort
Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.

Specified by:
setRTS in class SerialPort
Parameters:
rts - - true: set RTS - false: clear RTS

isRTS

public boolean isRTS()
Description copied from class: SerialPort
Gets the state of the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.

Specified by:
isRTS in class SerialPort
Returns:

isCTS

public boolean isCTS()
Description copied from class: SerialPort
Gets the state of the CTS (Clear To Send) bit in the UART, if supported by the underlying implementation.

Specified by:
isCTS in class SerialPort
Returns:

isDSR

public boolean isDSR()
Description copied from class: SerialPort
Gets the state of the DSR (Data Set Ready) bit in the UART, if supported by the underlying implementation.

Specified by:
isDSR in class SerialPort
Returns:

isRI

public boolean isRI()
Description copied from class: SerialPort
Gets the state of the RI (Ring Indicator) bit in the UART, if supported by the underlying implementation.

Specified by:
isRI in class SerialPort
Returns:

isCD

public boolean isCD()
Description copied from class: SerialPort
Gets the state of the CD (Carrier Detect) bit in the UART, if supported by the underlying implementation.

Specified by:
isCD in class SerialPort
Returns:

addEventListener

public void addEventListener(SerialPortEventListener lsnr)
                      throws java.util.TooManyListenersException
Description copied from class: SerialPort
Registers a SerialPortEventListener object to listen for SerialEvents. Interest in specific events may be expressed using the notifyOnXXX calls. The serialEvent method of SerialPortEventListener will be called with a SerialEvent object describing the event. The current implementation only allows one listener per SerialPort. Once a listener is registered, subsequent call attempts to addEventListener will throw a TooManyListenersException without effecting the listener already registered. All the events received by this listener are generated by one dedicated thread that belongs to the SerialPort object. After the port is closed, no more event will be generated. Another call to open() of the port's CommPortIdentifier object will return a new CommPort object, and the lsnr has to be added again to the new CommPort object to receive event from this port.

Specified by:
addEventListener in class SerialPort
Parameters:
lsnr - - The SerialPortEventListener object whose serialEvent method will be called with a SerialEvent describing the event.
Throws:
java.util.TooManyListenersException - - If an initial attempt to attach a listener succeeds, subsequent attempts will throw TooManyListenersException without effecting the first listener.

removeEventListener

public void removeEventListener()
Description copied from class: SerialPort
Deregisters event listener registered using addEventListener. This is done automatically at port close.

Specified by:
removeEventListener in class SerialPort

notifyOnDataAvailable

public void notifyOnDataAvailable(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when input data is available. This may be used to drive asynchronous input. When data is available in the input buffer, this event is propagated to the listener registered using addEventListener.

Specified by:
notifyOnDataAvailable in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnOutputEmpty

public void notifyOnOutputEmpty(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when the output buffer is empty. This may be used to drive asynchronous output. When the output buffer becomes empty, this event is propagated to the listener registered using addEventListener. The event will be generated after a write is completed, when the system buffer becomes empty again. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnOutputEmpty in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnCTS

public void notifyOnCTS(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when the CTS (Clear To Send) bit changes. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnCTS in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnDSR

public void notifyOnDSR(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when the DSR (Data Set Ready) bit changes. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnDSR in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnRingIndicator

public void notifyOnRingIndicator(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when the RI (Ring Indicator) bit changes. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnRingIndicator in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnCarrierDetect

public void notifyOnCarrierDetect(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when the CD (Carrier Detect) bit changes. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnCarrierDetect in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnOverrunError

public void notifyOnOverrunError(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when there is an overrun error. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnOverrunError in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnParityError

public void notifyOnParityError(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when there is a parity error. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnParityError in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnFramingError

public void notifyOnFramingError(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when there is a framing error. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnFramingError in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification

notifyOnBreakInterrupt

public void notifyOnBreakInterrupt(boolean enable)
Description copied from class: SerialPort
Expresses interest in receiving notification when there is a break interrupt on the line. This notification is hardware dependent and may not be supported by all implementations.

Specified by:
notifyOnBreakInterrupt in class SerialPort
Parameters:
enable - - true: enable notification - false: disable notification