Class UART

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class UART
    extends java.lang.Object
    implements java.io.Closeable
    This class provides low level access to a UART device.
    Author:
    andy
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  UART.UARTInputStream
      internal class that provides an InputStream interface to a UART
      protected class  UART.UARTOutputStream
      internal class that provides an OutputStream interface to a UART
    • Constructor Summary

      Constructors 
      Constructor Description
      UART​(Port port)
      Create a UART device attached to the specified port.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.io.InputStream getInputStream()
      Return the InputStream associated with this device.
      java.io.OutputStream getOutputStream()
      Return the OutputStream associated with this device.
      int read​(byte[] buffer, int offset, int len)
      Read bytes from the device.
      void setBitRate​(int rate)
      Set the bit rate to be used by the UART
      int write​(byte[] buffer, int offset, int len)
      Write bytes to the device.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • inputStream

        protected java.io.InputStream inputStream
      • outputStream

        protected java.io.OutputStream outputStream
    • Constructor Detail

      • UART

        public UART​(Port port)
        Create a UART device attached to the specified port.
        Parameters:
        port -
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • setBitRate

        public void setBitRate​(int rate)
        Set the bit rate to be used by the UART
        Parameters:
        rate -
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int len)
        Read bytes from the device. The read is non blocking and will return a count of 0 if no bytes are available to read.
        Parameters:
        buffer - buffer to read the bytes into
        offset - first position that bytes will be read into
        len - maximum number of bytes to read
        Returns:
        actual number of bytes read
      • write

        public int write​(byte[] buffer,
                         int offset,
                         int len)
        Write bytes to the device. The write is non blocking and will return 0 if it is not possible to write to the device.
        Parameters:
        buffer - buffer to write from
        offset - offset of first byte to be written
        len - number of bytes to try and write
        Returns:
        number of bytes actually written
      • getInputStream

        public java.io.InputStream getInputStream()
        Return the InputStream associated with this device.
        Returns:
        the InputStream that can be used to read from the UART
      • getOutputStream

        public java.io.OutputStream getOutputStream()
        Return the OutputStream associated with this device.
        Returns:
        the OutputStream that can be used to write to the UART