Package purejavacomm

Class SerialPort

    • Field Detail

      • PARITY_ODD

        public static final int PARITY_ODD
        Odd parity scheme. The parity bit is added so there are an odd number of TRUE bits.
        See Also:
        Constant Field Values
      • PARITY_EVEN

        public static final int PARITY_EVEN
        Even parity scheme. The parity bit is added so there are an even number of TRUE bits.
        See Also:
        Constant Field Values
      • PARITY_SPACE

        public static final int PARITY_SPACE
        Space parity scheme.
        See Also:
        Constant Field Values
      • STOPBITS_1_5

        public static final int STOPBITS_1_5
        One and 1/2 stop bits. Some UARTs permit 1-1/2 stop bits only with 5 data bit format, but permit 1 or 2 stop bits with any format.
        See Also:
        Constant Field Values
      • FLOWCONTROL_NONE

        public static final int FLOWCONTROL_NONE
        Flow control off.
        See Also:
        Constant Field Values
      • FLOWCONTROL_RTSCTS_IN

        public static final int FLOWCONTROL_RTSCTS_IN
        RTS/CTS flow control on input.
        See Also:
        Constant Field Values
      • FLOWCONTROL_RTSCTS_OUT

        public static final int FLOWCONTROL_RTSCTS_OUT
        RTS/CTS flow control on output.
        See Also:
        Constant Field Values
      • FLOWCONTROL_XONXOFF_IN

        public static final int FLOWCONTROL_XONXOFF_IN
        XON/XOFF flow control on input.
        See Also:
        Constant Field Values
      • FLOWCONTROL_XONXOFF_OUT

        public static final int FLOWCONTROL_XONXOFF_OUT
        XON/XOFF flow control on output.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SerialPort

        public SerialPort()
    • Method Detail

      • getBaudRate

        public abstract int getBaudRate()
        Returns the currently configured baud rate.
        Returns:
        The currently configured baud rate.
      • getDataBits

        public abstract int getDataBits()
        Returns the currently configured number of data bits.
        Returns:
        The currently configured number of data bits.
      • getFlowControlMode

        public abstract int getFlowControlMode()
        Returns the currently configured flow control mode.
        Returns:
        The currently configured flow control mode.
      • getParity

        public abstract int getParity()
        Returns the currently configured parity setting.
        Returns:
        The currently configured parity setting.
      • getStopBits

        public abstract int getStopBits()
        Returns the currently defined stop bits.
        Returns:
        The currently defined stop bits.
      • isCD

        public abstract boolean isCD()
        Returns the state of the CD (Carrier Detect) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the CD (Carrier Detect) bit.
      • isCTS

        public abstract boolean isCTS()
        Returns the state of the CTS (Clear To Send) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the CTS (Clear To Send) bit.
      • isDSR

        public abstract boolean isDSR()
        Returns the state of the DSR (Data Set Ready) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the DSR (Data Set Ready) bit.
      • isDTR

        public abstract boolean isDTR()
        Returns the state of the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the DTR (Data Terminal Ready) bit.
      • isRI

        public abstract boolean isRI()
        Returns the state of the RI (Ring Indicator) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the RI (Ring Indicator) bit.
      • isRTS

        public abstract boolean isRTS()
        Returns the state of the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
        Returns:
        The state of the RTS (Request To Send) bit.
      • notifyOnBreakInterrupt

        public abstract void notifyOnBreakInterrupt​(boolean enable)
        Expresses interest in receiving notification when there is a break interrupt on the line.
        Parameters:
        enable -
      • notifyOnCarrierDetect

        public abstract void notifyOnCarrierDetect​(boolean enable)
        Expresses interest in receiving notification when the CD (Carrier Detect) bit changes.
        Parameters:
        enable -
      • notifyOnCTS

        public abstract void notifyOnCTS​(boolean enable)
        Expresses interest in receiving notification when the CTS (Clear To Send) bit changes.
        Parameters:
        enable -
      • notifyOnDataAvailable

        public abstract void notifyOnDataAvailable​(boolean enable)
        Expresses interest in receiving notification when input data is available.
        Parameters:
        enable -
      • notifyOnDSR

        public abstract void notifyOnDSR​(boolean enable)
        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.

        Parameters:
        enable -
      • notifyOnFramingError

        public abstract void notifyOnFramingError​(boolean enable)
        Expresses interest in receiving notification when there is a framing error.
        Parameters:
        enable -
      • notifyOnOutputEmpty

        public abstract void notifyOnOutputEmpty​(boolean enable)
        Expresses interest in receiving notification when the output buffer is empty.
        Parameters:
        enable -
      • notifyOnOverrunError

        public abstract void notifyOnOverrunError​(boolean enable)
        Expresses interest in receiving notification when there is an overrun error.
        Parameters:
        enable -
      • notifyOnParityError

        public abstract void notifyOnParityError​(boolean enable)
        Expresses interest in receiving notification when there is a parity error.
        Parameters:
        enable -
      • notifyOnRingIndicator

        public abstract void notifyOnRingIndicator​(boolean enable)
        Expresses interest in receiving notification when the RI (Ring Indicator) bit changes.
        Parameters:
        enable -
      • removeEventListener

        public abstract void removeEventListener()
        Deregisters event listener registered using addEventListener .

        This is done automatically when the port is closed.

      • sendBreak

        public abstract void sendBreak​(int duration)
        Sends a break of duration milliseconds duration.
        Parameters:
        duration - The break duration in milliseconds.
      • setDTR

        public abstract void setDTR​(boolean state)
        Sets or clears the DTR (Data Terminal Ready) signal, if supported by the underlying implementation.
        Parameters:
        state -
      • setRTS

        public abstract void setRTS​(boolean state)
        Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
        Parameters:
        state -
      • setSerialPortParams

        public abstract void setSerialPortParams​(int baudRate,
                                                 int dataBits,
                                                 int stopBits,
                                                 int parity)
                                          throws UnsupportedCommOperationException
        Sets the serial port parameters.

        Default: 9600 baud, 8 data bits, 1 stop bit, no parity.

        Parameters:
        baudRate -
        dataBits -
        stopBits -
        parity -
        Throws:
        UnsupportedCommOperationException
      • getInputStream

        public abstract InputStream getInputStream()
                                            throws IOException
        Returns an input stream. This is the only way to receive data from the communications port. If the port is unidirectional and doesn't support receiving data, then getInputStream returns null. The read behavior of the input stream returned by getInputStream depends on combination of the threshold and timeout values. The behaviors are described in the table below.

        threshold timeout read buffer size read behaviour
        state value state value
        disabled - disabled - n bytes block until minimum one byte of data is available
        enabled m bytes disabled - n bytes block until min(m,n) bytes are available
        disabled - enabled x msec n bytes block for x msec or until any data is available
        enabled m bytes enabled x msec n bytes block for x msec or until min(m,n) bytes are available

        Framing errors may cause the Timeout and Threshold trigger early and to complete the read prematurely without raising an exception.

        Enabling the Timeout OR Threshold with a value a zero is a special case. This causes the underlying driver to poll for incoming data instead being event driven. Otherwise, the behaviour is identical to having both the Timeout and Threshold disabled. Returns: InputStream object that can be used to read from the port Throws: java.io.IOException - if an I/O error occurred.

        Timeout is interpreted as inter character timeout, in other words the timeout will not occur as long as the pause before the first character or between characters is shorter that the timeout value.

        Specified by:
        getInputStream in class CommPort
        Returns:
        An input stream, or null if the port is unidirectional and doesn't support receiving data.
        Throws:
        IOException