ioio.lib.api
Interface Uart

All Superinterfaces:
Closeable

public interface Uart
extends Closeable

An interface for controlling a UART module.

UART is a very common hardware communication protocol, enabling full- duplex, asynchronous point-to-point data transfer. It typically serves for opening consoles or as a basis for higher-level protocols, such as MIDI, RS-232 and RS-485. Uart instances are obtained by calling IOIO.openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity, Uart.StopBits).

The UART protocol is completely symmetric - there is no "master" and "slave" at this layer. Each end may send any number of bytes at arbitrary times, making it very useful for terminals and terminal-controllable devices.

Working with UART is very intuitive - it just provides a standard InputStream and/or OutputStream. Optionally, one could create a read-only or write-only UART instances, by passing null (or INVALID_PIN) for either TX or RX pins.

The instance is alive since its creation. If the connection with the IOIO drops at any point, the instance transitions to a disconnected state, which every attempt to use it (except Closeable.close()) will throw a ConnectionLostException. Whenever Closeable.close() is invoked the instance may no longer be used. Any resources associated with it are freed and can be reused.

Typical usage:

 Uart uart = ioio.openUart(3, 4, 19200, Parity.NONE, StopBits.ONE);
 InputStream in = uart.getInputStream();
 OutputStream out = uart.getOutputStream();
 out.write(new String("Hello").getBytes());
 int i = in.read();  // blocking
 ...
 uart.close();  // free UART module and pins
 

See Also:
IOIO.openUart(DigitalInput.Spec, DigitalOutput.Spec, int, Uart.Parity, Uart.StopBits)

Nested Class Summary
static class Uart.Parity
          Parity-bit mode.
static class Uart.StopBits
          Number of stop-bits.
 
Method Summary
 java.io.InputStream getInputStream()
          Gets the input stream.
 java.io.OutputStream getOutputStream()
          Gets the output stream.
 
Methods inherited from interface ioio.lib.api.Closeable
close
 

Method Detail

getInputStream

java.io.InputStream getInputStream()
Gets the input stream.

Returns:
An input stream.

getOutputStream

java.io.OutputStream getOutputStream()
Gets the output stream.

Returns:
An output stream.