UartDevice
  public
  
  
  
  interface
  UartDevice
  
  
      implements
      
        Closeable
      
  
  
| com.google.android.things.pio.UartDevice | 
| 
          
  
     | 
    
Controls a UART device.
 Opening a UART device takes ownership of it for the whole system, preventing anyone else from
 opening/accessing this device until you call close(). Forgetting to call close()
 will prevent anyone (including the same process/app) from using the device.
Summary
Constants | |
|---|---|
int | 
        
          FLUSH_IN
          
  | 
    
int | 
        
          FLUSH_IN_OUT
          
  | 
    
int | 
        
          FLUSH_OUT
          
  | 
    
int | 
        
          HW_FLOW_CONTROL_AUTO_RTSCTS
          
  | 
    
int | 
        
          HW_FLOW_CONTROL_NONE
          
  | 
    
int | 
        
          MODEM_CONTROL_CD
          
  | 
    
int | 
        
          MODEM_CONTROL_CTS
          
  | 
    
int | 
        
          MODEM_CONTROL_DSR
          
  | 
    
int | 
        
          MODEM_CONTROL_DTR
          
  | 
    
int | 
        
          MODEM_CONTROL_LE
          
  | 
    
int | 
        
          MODEM_CONTROL_RI
          
  | 
    
int | 
        
          MODEM_CONTROL_RTS
          
  | 
    
int | 
        
          MODEM_CONTROL_SR
          
  | 
    
int | 
        
          MODEM_CONTROL_ST
          
  | 
    
int | 
        
          PARITY_EVEN
          
  | 
    
int | 
        
          PARITY_MARK
          
  | 
    
int | 
        
          PARITY_NONE
          
  | 
    
int | 
        
          PARITY_ODD
          
  | 
    
int | 
        
          PARITY_SPACE
          
  | 
    
Public methods | |
|---|---|
        abstract
        
        
        
        
        void
     | 
  
    
      
      clearModemControl(int lines)
      
      
        Clear selected modem control lines.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      close()
      
      
        Close and release the device.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      flush(int direction)
      
      
        Flush the specified queue for the device.  | 
  
        
        default
        
        
        
        String
     | 
  
    
      
      getName()
      
      
        Returns the I/O name.  | 
  
        abstract
        
        
        
        
        int
     | 
  
    
      
      read(byte[] buffer, int length)
      
      
        Read data from the device.  | 
  
        
        default
        
        
        
        void
     | 
  
    
      
      registerUartDeviceCallback(UartDeviceCallback callback)
      
      
        Registers a callback for interrupts.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      registerUartDeviceCallback(Handler handler, UartDeviceCallback callback)
      
      
        Registers a callback for interrupts.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      sendBreak(int duration_msecs)
      
      
        Send a break to the device.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setBaudrate(int rate)
      
      
        Set the device baud rate.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setDataSize(int size)
      
      
        Set the device data size.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setHardwareFlowControl(int mode)
      
      
        Set the hardware flow control mode.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setModemControl(int lines)
      
      
        Set selected modem control lines.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setParity(int mode)
      
      
        Set the device parity mode.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      setStopBits(int bits)
      
      
        Set the device stop bits.  | 
  
        abstract
        
        
        
        
        void
     | 
  
    
      
      unregisterUartDeviceCallback(UartDeviceCallback callback)
      
      
        Unregisters a callback.  | 
  
        abstract
        
        
        
        
        int
     | 
  
    
      
      write(byte[] buffer, int length)
      
      
        Write data to the device.  | 
  
Inherited methods | |
|---|---|
  
    
  
    java.io.Closeable
  
 | |
  
    
  
    java.lang.AutoCloseable
  
 | |
Constants
FLUSH_IN
int FLUSH_IN
Queue constant used to flush UART data that has been received but not
 read.
Constant Value: 0 (0x00000000)
FLUSH_IN_OUT
int FLUSH_IN_OUT
Queue constant used to flush UART data that has both been received and
 written.
Constant Value: 2 (0x00000002)
FLUSH_OUT
int FLUSH_OUT
Queue constant used to flush UART data that has been written but not
 transmitted.
Constant Value: 1 (0x00000001)
HW_FLOW_CONTROL_AUTO_RTSCTS
int HW_FLOW_CONTROL_AUTO_RTSCTS
Mode constant used to configure a UART device to use
 automatic RTS/CTS hardware flow control.
Constant Value: 1 (0x00000001)
HW_FLOW_CONTROL_NONE
int HW_FLOW_CONTROL_NONE
Mode constant used to configure a UART device to use no
 hardware flow control.
Constant Value: 0 (0x00000000)
MODEM_CONTROL_CD
int MODEM_CONTROL_CD
Bit constant used to configure a UART device
 data carrier detect.
Constant Value: 64 (0x00000040)
MODEM_CONTROL_CTS
int MODEM_CONTROL_CTS
Bit constant used to configure a UART device
 clear to send.
Constant Value: 32 (0x00000020)
MODEM_CONTROL_DSR
int MODEM_CONTROL_DSR
Bit constant used to configure a UART device
 data set ready.
Constant Value: 256 (0x00000100)
MODEM_CONTROL_DTR
int MODEM_CONTROL_DTR
Bit constant used to configure a UART device
 data terminal ready.
Constant Value: 2 (0x00000002)
MODEM_CONTROL_LE
int MODEM_CONTROL_LE
Bit constant used to configure a UART device
 data set ready/Line enable.
Constant Value: 1 (0x00000001)
MODEM_CONTROL_RI
int MODEM_CONTROL_RI
Bit constant used to configure a UART device
 ring.
Constant Value: 128 (0x00000080)
MODEM_CONTROL_RTS
int MODEM_CONTROL_RTS
Bit constant used to configure a UART device
 request to send.
Constant Value: 4 (0x00000004)
MODEM_CONTROL_SR
int MODEM_CONTROL_SR
Bit constant used to configure a UART device
 secondary RXD.
Constant Value: 16 (0x00000010)
MODEM_CONTROL_ST
int MODEM_CONTROL_ST
Bit constant used to configure a UART device
 secondary TXD.
Constant Value: 8 (0x00000008)
PARITY_EVEN
int PARITY_EVEN
Mode constant used to configure a UART device to use even parity.
Constant Value: 1 (0x00000001)
PARITY_MARK
int PARITY_MARK
Mode constant used to configure a UART device to use mark parity.
Constant Value: 3 (0x00000003)
PARITY_NONE
int PARITY_NONE
Mode constant used to configure a UART device to use no parity.
Constant Value: 0 (0x00000000)
PARITY_ODD
int PARITY_ODD
Mode constant used to configure a UART device to use odd parity.
Constant Value: 2 (0x00000002)
PARITY_SPACE
int PARITY_SPACE
Mode constant used to configure a UART device to use space parity.
Constant Value: 4 (0x00000004)
Public methods
clearModemControl
void clearModemControl (int lines)
Clear selected modem control lines.
| Parameters | |
|---|---|
lines | 
        
          int: The set of lines to clear. Available lines are MODEM_CONTROL_LE,
 MODEM_CONTROL_DTR, MODEM_CONTROL_RTS, MODEM_CONTROL_ST, MODEM_CONTROL_SR, MODEM_CONTROL_CTS, MODEM_CONTROL_CD, MODEM_CONTROL_RI, MODEM_CONTROL_DSR. | 
      
| Throws | |
|---|---|
IOException | 
          |
close
void close ()
Close and release the device. Must be called in order to make the device available to other users.
| Throws | |
|---|---|
IOException | 
          if the UartDevice is already closed. | 
flush
void flush (int direction)
Flush the specified queue for the device.
| Parameters | |
|---|---|
direction | 
        
          int: Queue to flush. One of FLUSH_IN, FLUSH_OUT, FLUSH_IN_OUT. | 
      
| Throws | |
|---|---|
IOException | 
          |
read
int read (byte[] buffer, 
                int length)Read data from the device. This call is non-blocking and may read fewer than bytes than requested. If no data is ready, this will return 0.
| Parameters | |
|---|---|
buffer | 
        
          byte: Buffer to read into. | 
      
length | 
        
          int: Number of bytes to read, may not be larger than the buffer size. | 
      
| Returns | |
|---|---|
int | 
        The number of bytes read. | 
| Throws | |
|---|---|
 | 
          IOException | 
 | 
          IllegalArgumentException | 
IOException | 
          |
See also:
registerUartDeviceCallback
void registerUartDeviceCallback (UartDeviceCallback callback)
Registers a callback for interrupts.
 Equivalent to registerUartDeviceCallback(null, callback).
| Parameters | |
|---|---|
callback | 
        
          UartDeviceCallback: UartDeviceCallback to register. | 
      
| Throws | |
|---|---|
 | 
          IOException | 
IOException | 
          |
registerUartDeviceCallback
void registerUartDeviceCallback (Handler handler, UartDeviceCallback callback)
Registers a callback for interrupts. The callback will be called when data is ready to read.
| Parameters | |
|---|---|
handler | 
        
          Handler: The Handler to run callbacks on, or null to use the current thread. | 
      
callback | 
        
          UartDeviceCallback: UartDeviceCallback to register. | 
      
| Throws | |
|---|---|
 | 
          IOException | 
IOException | 
          |
sendBreak
void sendBreak (int duration_msecs)
Send a break to the device.
| Parameters | |
|---|---|
duration_msecs | 
        
          int: Duration of break in milliseconds. | 
      
| Throws | |
|---|---|
IOException | 
          |
setBaudrate
void setBaudrate (int rate)
Set the device baud rate.
| Parameters | |
|---|---|
rate | 
        
          int: Rate in baud per seconds. | 
      
| Throws | |
|---|---|
IOException | 
          if the requested baudrate is unsupported by the hardware. | 
IllegalArgumentException | 
          if the requested baudrate is negative or zero. | 
setDataSize
void setDataSize (int size)
Set the device data size.
| Parameters | |
|---|---|
size | 
        
          int: Data size in bits. | 
      
| Throws | |
|---|---|
 | 
          IOException | 
IllegalArgumentException | 
          if the requested data size is negative or zero. | 
IOException | 
          |
setHardwareFlowControl
void setHardwareFlowControl (int mode)
Set the hardware flow control mode.
| Parameters | |
|---|---|
mode | 
        
          int: Flow control mode. One of HW_FLOW_CONTROL_NONE, HW_FLOW_CONTROL_AUTO_RTSCTS. | 
      
| Throws | |
|---|---|
IOException | 
          |
setModemControl
void setModemControl (int lines)
Set selected modem control lines.
| Parameters | |
|---|---|
lines | 
        
          int: The set of lines to enable. Available lines are MODEM_CONTROL_LE,
 MODEM_CONTROL_DTR, MODEM_CONTROL_RTS, MODEM_CONTROL_ST, MODEM_CONTROL_SR, MODEM_CONTROL_CTS, MODEM_CONTROL_CD, MODEM_CONTROL_RI, MODEM_CONTROL_DSR. | 
      
| Throws | |
|---|---|
IOException | 
          |
setParity
void setParity (int mode)
Set the device parity mode.
| Parameters | |
|---|---|
mode | 
        
          int: Parity mode. One of PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK, PARITY_SPACE. | 
      
| Throws | |
|---|---|
IOException | 
          |
setStopBits
void setStopBits (int bits)
Set the device stop bits.
| Parameters | |
|---|---|
bits | 
        
          int: Number of stop bits. | 
      
| Throws | |
|---|---|
 | 
          IOException | 
IllegalArgumentException | 
          if the requested stop bits is negative. | 
IOException | 
          |
unregisterUartDeviceCallback
void unregisterUartDeviceCallback (UartDeviceCallback callback)
Unregisters a callback.
| Parameters | |
|---|---|
callback | 
        
          UartDeviceCallback: PioInterruptCallback to unregister. | 
      
write
int write (byte[] buffer, 
                int length)Write data to the device. This call is non-blocking and may write fewer bytes than requested. If no data can be written, this will return 0.
| Parameters | |
|---|---|
buffer | 
        
          byte: Data to write. | 
      
length | 
        
          int: Number of bytes to write, may not be larger than the buffer size. | 
      
| Returns | |
|---|---|
int | 
        The number of bytes written. | 
| Throws | |
|---|---|
 | 
          IOException | 
 | 
          IllegalArgumentException | 
IOException | 
          |
See also:
Interfaces
Classes