Class RxTxSerialPort

    • Constructor Detail

      • RxTxSerialPort

        public RxTxSerialPort​(gnu.io.SerialPort sp)
        Constructor.
        Parameters:
        sp - the underlying serial port implementation
    • Method Detail

      • getInputStream

        public @Nullable InputStream getInputStream()
                                             throws IOException
        Description copied from interface: SerialPort
        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 behaviour of the input stream returned by getInputStream depends on combination of the threshold and timeout values. The possible behaviours are described in the table below: | Threshold .........| Timeout ........ | Read Buffer Size | Read Behaviour | | State ...| Value ..| State ...| Value | | disabled | - ......| disabled | - ....| n bytes .........| block until any data is available | enabled .| m bytes | disabled | - ....| n bytes .........| block until min(m,n) bytes are available | disabled | - ......| enabled .| x ms .| n bytes .........| block for x ms or until any data is available | enabled .| m bytes | enabled .| x ms .| n bytes .........| block for x ms or until min(m,n) bytes are available

        Note, however, that framing errors may cause the Timeout and Threshold values to complete 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. *

        Specified by:
        getInputStream in interface SerialPort
        Returns:
        the input stream or null
        Throws:
        IOException - on I/O error
      • getOutputStream

        public @Nullable OutputStream getOutputStream()
                                               throws IOException
        Description copied from interface: SerialPort
        Returns an output stream.

        This is the only way to send data to the communications port. If the port is unidirectional and doesn't support sending data, then getOutputStream returns null.

        Specified by:
        getOutputStream in interface SerialPort
        Returns:
        the output stream or null
        Throws:
        IOException - on I/O error
      • addEventListener

        public void addEventListener​(SerialPortEventListener listener)
                              throws TooManyListenersException
        Description copied from interface: 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. Only one listener per SerialPort is allowed. 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.

        Specified by:
        addEventListener in interface SerialPort
        Parameters:
        listener - the listener
        Throws:
        TooManyListenersException - if too many listeners has been added
      • notifyOnDataAvailable

        public void notifyOnDataAvailable​(boolean enable)
        Description copied from interface: SerialPort
        Enable / disable the notification for 'data available'.
        Specified by:
        notifyOnDataAvailable in interface SerialPort
        Parameters:
        enable - true if the notification should be enabled
      • notifyOnBreakInterrupt

        public void notifyOnBreakInterrupt​(boolean enable)
        Description copied from interface: SerialPort
        Enable / disable the notification on break interrupt.
        Specified by:
        notifyOnBreakInterrupt in interface SerialPort
        Parameters:
        enable - true if the notification should be enabled
      • notifyOnFramingError

        public void notifyOnFramingError​(boolean enable)
        Description copied from interface: SerialPort
        Enable / disable the notification on framing error.
        Specified by:
        notifyOnFramingError in interface SerialPort
        Parameters:
        enable - true if the notification should be enabled
      • notifyOnOverrunError

        public void notifyOnOverrunError​(boolean enable)
        Description copied from interface: SerialPort
        Enable / disable the notification on overrun error.
        Specified by:
        notifyOnOverrunError in interface SerialPort
        Parameters:
        enable - true if the notification should be enabled
      • notifyOnParityError

        public void notifyOnParityError​(boolean enable)
        Description copied from interface: SerialPort
        Enable / disable the notification on parity error.
        Specified by:
        notifyOnParityError in interface SerialPort
        Parameters:
        enable - true if the notification should be enabled
      • setRTS

        public void setRTS​(boolean enable)
        Description copied from interface: SerialPort
        Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation.
        Specified by:
        setRTS in interface SerialPort
        Parameters:
        enable - true rts is set, false if rts cleared
      • enableReceiveTimeout

        public void enableReceiveTimeout​(int timeout)
                                  throws UnsupportedCommOperationException
        Description copied from interface: SerialPort
        Enables the receive timeout.

        When the receive timeout condition becomes true, a read from the input stream for this port will return immediately.

        Specified by:
        enableReceiveTimeout in interface SerialPort
        Parameters:
        timeout - the timeout (milliseconds), must be greater or equal to zero
        Throws:
        UnsupportedCommOperationException - if the operation is not supported
      • getName

        public String getName()
        Description copied from interface: SerialPort
        Retrieves the name of the serial port.
        Specified by:
        getName in interface SerialPort
        Returns:
        the name of the serial port