Class FlinkUART

  • All Implemented Interfaces:
    FlinkDefinitions

    public class FlinkUART
    extends Object
    implements FlinkDefinitions
    The flink UART subdevice realizes an UART function within a flink device. It offers several channels. Each channel has its own baudrate generator together with transmit and receive queues.
    Author:
    Urs Graf
    • Method Detail

      • getInstance

        public static FlinkUART getInstance​(FlinkSubDevice dev,
                                            int uartNr)
        Returns an instance of FlinkUART Interface operating one of the UARTS in the flink UART subdevice.
        Parameters:
        dev - handle to the subdevice
        uartNr - 0 selects UART0, 1 selects UART1, ..
        Returns:
        instance of UART
      • start

        public void start​(int baudRate)

        Initialize and start the flink Universal Asynchronous Receiver Transmitter.

        This method have to be called before using the flink UART! The number of stop bits, the parity mode and number of data bits can't be set. There is always one stop bit. Parity is off. Number of data bits is 8.

        Parameters:
        baudRate - The baud rate. Allowed Range: 64 to 1'000'000 bits/s.
      • reset

        public void reset()
        Resets the UART. All the pending transmissions will be stopped, the buffers will be emptied and the UART will be restarted.
      • write

        public void write​(byte b)
                   throws IOException
        Writes a given byte into the transmit buffer. A call of this method is blocking! If the buffer is full, the method blocks for a short period of time until a small amount of space is available again. After this an IOException is thrown.
        Parameters:
        b - Byte to write.
        Throws:
        IOException - if an error occurs while writing to this stream.
      • write

        public int write​(byte[] buffer)
                  throws IOException
        Writes a given number of bytes into the transmit buffer. A call of this method is not blocking! There will only as many bytes written, which are free in the buffer.
        Parameters:
        buffer - Array of bytes to send.
        Returns:
        the number of bytes written.
        Throws:
        IOException - if an error occurs while writing to this stream.
      • write

        public int write​(byte[] buffer,
                         int off,
                         int count)
                  throws IOException
        Writes a given number of bytes into the transmit buffer. A call of this method is not blocking! There will only as many bytes written, which are free in the buffer.
        Parameters:
        buffer - Array of bytes to send.
        off - Offset to the data which should be sent.
        count - Number of bytes to send.
        Returns:
        the number of bytes written.
        Throws:
        IOException - if an error occurs while writing to this stream.
        NullPointerException - if buffer is null.
        IndexOutOfBoundsException - if off < 0 or count < 0, or if off + count is bigger than the length of buffer.
      • availToRead

        public int availToRead()
        Returns the number of bytes available in the receive buffer.
        Returns:
        number of bytes in the receive buffer.
      • read

        public int read()
                 throws IOException
        Reads one byte from the UART. A call of this method is not blocking!
        Returns:
        byte read.
        Throws:
        IOException - if no byte available.
      • read

        public int read​(byte[] buffer)
                 throws IOException
        Reads the given number of bytes from the UART. A call of this method is not blocking!
        Parameters:
        buffer - Byte array to write the received data.
        Returns:
        the number of bytes read.
        Throws:
        IOException - if no data available.
      • read

        public int read​(byte[] buffer,
                        int off,
                        int count)
                 throws IOException
        Reads the given number of bytes from the UART. A call of this method is not blocking!
        Parameters:
        buffer - Byte aray to write the received data.
        off - Offset in the array to start writing the data.
        count - Length (number of bytes) to read.
        Returns:
        the number of bytes read.
        Throws:
        IOException - if an error occurs while reading from this stream.
        NullPointerException - if buffer is null.
        IndexOutOfBoundsException - if off < 0 or count < 0, or if off + count is bigger than the length of buffer.