# UartDevice

Summary:[Constants](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#constants)\|[Methods](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#)  

# UartDevice

`
public


interface
UartDevice
`  
`


implements

`[Closeable](https://developer.android.com/reference/java/io/Closeable)`


`

|------------------------------------------|
| com.google.android.things.pio.UartDevice |

|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#)Known Indirect Subclasses [UartDeviceDriver](https://developer.android.com/reference/com/google/android/things/userdriver/pio/UartDeviceDriver) |-----------------------------------------------------------------------------------------------------------------------|-------------------| | [UartDeviceDriver](https://developer.android.com/reference/com/google/android/things/userdriver/pio/UartDeviceDriver) | UART user driver. | ||

<br />

*** ** * ** ***

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()](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#close()). Forgetting to call[close()](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#close())will prevent anyone (including the same process/app) from using the device.

## Summary

|                                                                                                                                                                          ### Constants                                                                                                                                                                          ||
|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [FLUSH_IN](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_IN) [Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has been received but not read.                                                                          |
| `int` | [FLUSH_IN_OUT](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_IN_OUT) [Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has both been received and written.                                                              |
| `int` | [FLUSH_OUT](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_OUT) [Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has been written but not transmitted.                                                                  |
| `int` | [HW_FLOW_CONTROL_AUTO_RTSCTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#HW_FLOW_CONTROL_AUTO_RTSCTS) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setHardwareFlowControl(int))constant used to configure a UART device to use automatic RTS/CTS hardware flow control. |
| `int` | [HW_FLOW_CONTROL_NONE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#HW_FLOW_CONTROL_NONE) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setHardwareFlowControl(int))constant used to configure a UART device to use no hardware flow control.                              |
| `int` | [MODEM_CONTROL_CD](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CD) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data carrier detect.                                                          |
| `int` | [MODEM_CONTROL_CTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CTS) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device clear to send.                                                              |
| `int` | [MODEM_CONTROL_DSR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DSR) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data set ready.                                                             |
| `int` | [MODEM_CONTROL_DTR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DTR) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data terminal ready.                                                        |
| `int` | [MODEM_CONTROL_LE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_LE) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data set ready/Line enable.                                                   |
| `int` | [MODEM_CONTROL_RI](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RI) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device ring.                                                                         |
| `int` | [MODEM_CONTROL_RTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RTS) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device request to send.                                                            |
| `int` | [MODEM_CONTROL_SR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_SR) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device secondary RXD.                                                                |
| `int` | [MODEM_CONTROL_ST](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_ST) [Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device secondary TXD.                                                                |
| `int` | [PARITY_EVEN](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_EVEN) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use even parity.                                                                          |
| `int` | [PARITY_MARK](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_MARK) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use mark parity.                                                                          |
| `int` | [PARITY_NONE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_NONE) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use no parity.                                                                            |
| `int` | [PARITY_ODD](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_ODD) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use odd parity.                                                                             |
| `int` | [PARITY_SPACE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_SPACE) [Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use space parity.                                                                       |

|                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                     ||
|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void`                                                              | ` `[clearModemControl](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#clearModemControl(int))`(int lines) ` Clear selected modem control lines.                                                                                                                                                                                                                                                                                           |
| ` abstract void`                                                              | ` `[close](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#close())`() ` Close and release the device.                                                                                                                                                                                                                                                                                                                                     |
| ` abstract void`                                                              | ` `[flush](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))`(int direction) ` Flush the specified queue for the device.                                                                                                                                                                                                                                                                                                         |
| ` default `[String](https://developer.android.com/reference/java/lang/String) | ` `[getName](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#getName())`() ` Returns the I/O name.                                                                                                                                                                                                                                                                                                                                         |
| ` abstract int`                                                               | ` `[read](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#read(byte[], int))`(byte[] buffer, int length) ` Read data from the device.                                                                                                                                                                                                                                                                                                      |
| ` default void`                                                               | ` `[registerUartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(com.google.android.things.pio.UartDeviceCallback))`(`[UartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDeviceCallback)` callback) ` Registers a callback for interrupts.                                                                                                           |
| ` abstract void`                                                              | ` `[registerUartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(android.os.Handler, com.google.android.things.pio.UartDeviceCallback))`(`[Handler](https://developer.android.com/reference/android/os/Handler.html)` handler, `[UartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDeviceCallback)` callback) ` Registers a callback for interrupts. |
| ` abstract void`                                                              | ` `[sendBreak](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#sendBreak(int))`(int duration_msecs) ` Send a break to the device.                                                                                                                                                                                                                                                                                                          |
| ` abstract void`                                                              | ` `[setBaudrate](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setBaudrate(int))`(int rate) ` Set the device baud rate.                                                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                              | ` `[setDataSize](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setDataSize(int))`(int size) ` Set the device data size.                                                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                              | ` `[setHardwareFlowControl](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setHardwareFlowControl(int))`(int mode) ` Set the hardware flow control mode.                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                              | ` `[setModemControl](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))`(int lines) ` Set selected modem control lines.                                                                                                                                                                                                                                                                                                 |
| ` abstract void`                                                              | ` `[setParity](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))`(int mode) ` Set the device parity mode.                                                                                                                                                                                                                                                                                                                    |
| ` abstract void`                                                              | ` `[setStopBits](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setStopBits(int))`(int bits) ` Set the device stop bits.                                                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                              | ` `[unregisterUartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#unregisterUartDeviceCallback(com.google.android.things.pio.UartDeviceCallback))`(`[UartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDeviceCallback)` callback) ` Unregisters a callback.                                                                                                                    |
| ` abstract int`                                                               | ` `[write](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#write(byte[], int))`(byte[] buffer, int length) ` Write data to the device.                                                                                                                                                                                                                                                                                                     |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#)From interface` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#)From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Constants

### FLUSH_IN

```
int FLUSH_IN
```

[Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has been received but not read.

<br />

Constant Value: 0 (0x00000000)  

### FLUSH_IN_OUT

```
int FLUSH_IN_OUT
```

[Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has both been received and written.

<br />

Constant Value: 2 (0x00000002)  

### FLUSH_OUT

```
int FLUSH_OUT
```

[Queue](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#flush(int))constant used to flush UART data that has been written but not transmitted.

<br />

Constant Value: 1 (0x00000001)  

### HW_FLOW_CONTROL_AUTO_RTSCTS

```
int HW_FLOW_CONTROL_AUTO_RTSCTS
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setHardwareFlowControl(int))constant used to configure a UART device to use automatic RTS/CTS hardware flow control.

<br />

Constant Value: 1 (0x00000001)  

### HW_FLOW_CONTROL_NONE

```
int HW_FLOW_CONTROL_NONE
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setHardwareFlowControl(int))constant used to configure a UART device to use no hardware flow control.

<br />

Constant Value: 0 (0x00000000)  

### MODEM_CONTROL_CD

```
int MODEM_CONTROL_CD
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data carrier detect.

<br />

Constant Value: 64 (0x00000040)  

### MODEM_CONTROL_CTS

```
int MODEM_CONTROL_CTS
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device clear to send.

<br />

Constant Value: 32 (0x00000020)  

### MODEM_CONTROL_DSR

```
int MODEM_CONTROL_DSR
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data set ready.

<br />

Constant Value: 256 (0x00000100)  

### MODEM_CONTROL_DTR

```
int MODEM_CONTROL_DTR
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data terminal ready.

<br />

Constant Value: 2 (0x00000002)  

### MODEM_CONTROL_LE

```
int MODEM_CONTROL_LE
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device data set ready/Line enable.

<br />

Constant Value: 1 (0x00000001)  

### MODEM_CONTROL_RI

```
int MODEM_CONTROL_RI
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device ring.

<br />

Constant Value: 128 (0x00000080)  

### MODEM_CONTROL_RTS

```
int MODEM_CONTROL_RTS
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device request to send.

<br />

Constant Value: 4 (0x00000004)  

### MODEM_CONTROL_SR

```
int MODEM_CONTROL_SR
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device secondary RXD.

<br />

Constant Value: 16 (0x00000010)  

### MODEM_CONTROL_ST

```
int MODEM_CONTROL_ST
```

[Bit](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setModemControl(int))constant used to configure a UART device secondary TXD.

<br />

Constant Value: 8 (0x00000008)  

### PARITY_EVEN

```
int PARITY_EVEN
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use even parity.

<br />

Constant Value: 1 (0x00000001)  

### PARITY_MARK

```
int PARITY_MARK
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use mark parity.

<br />

Constant Value: 3 (0x00000003)  

### PARITY_NONE

```
int PARITY_NONE
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use no parity.

<br />

Constant Value: 0 (0x00000000)  

### PARITY_ODD

```
int PARITY_ODD
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use odd parity.

<br />

Constant Value: 2 (0x00000002)  

### PARITY_SPACE

```
int PARITY_SPACE
```

[Mode](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#setParity(int))constant used to configure a UART device to use space parity.

<br />

Constant Value: 4 (0x00000004)

## Public methods

### clearModemControl

```
void clearModemControl (int lines)
```

Clear selected modem control lines.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `lines` | `int`: The set of lines to clear. Available lines are[MODEM_CONTROL_LE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_LE),[MODEM_CONTROL_DTR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DTR),[MODEM_CONTROL_RTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RTS),[MODEM_CONTROL_ST](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_ST),[MODEM_CONTROL_SR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_SR),[MODEM_CONTROL_CTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CTS),[MODEM_CONTROL_CD](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CD),[MODEM_CONTROL_RI](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RI),[MODEM_CONTROL_DSR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DSR). <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### close

```
void close ()
```

Close and release the device. Must be called in order to make the device available to other users.

<br />

|                                                      Throws                                                      ||
|----------------------------------------------------------------------------|--------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if the UartDevice is already closed. |

### flush

```
void flush (int direction)
```

Flush the specified queue for the device.

<br />

|                                                                                                                                                                                  Parameters                                                                                                                                                                                   ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `direction` | `int`: Queue to flush. One of[FLUSH_IN](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_IN),[FLUSH_OUT](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_OUT),[FLUSH_IN_OUT](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#FLUSH_IN_OUT). <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### getName

```
String getName ()
```

Returns the I/O name.

<br />

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### 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.

<br />

|                                        Parameters                                        ||
|----------|--------------------------------------------------------------------------------|
| `buffer` | `byte`: Buffer to read into. <br />                                            |
| `length` | `int`: Number of bytes to read, may not be larger than the buffer size. <br /> |

|                 Returns                 ||
|-------|----------------------------------|
| `int` | The number of bytes read. <br /> |

|                                                Throws                                                ||
|----------------------------------------------------------------------------|--------------------------|
|                                                                            | IOException              |
|                                                                            | IllegalArgumentException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |                          |

**See also:**

- [write(byte[], int)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#write(byte[], int))  

### registerUartDeviceCallback

```
void registerUartDeviceCallback (UartDeviceCallback callback)
```

Registers a callback for interrupts. Equivalent to[registerUartDeviceCallback(null, callback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(android.os.Handler, com.google.android.things.pio.UartDeviceCallback)).

<br />

|                                Parameters                                ||
|------------|--------------------------------------------------------------|
| `callback` | `UartDeviceCallback`: UartDeviceCallback to register. <br /> |

|                                         Throws                                          ||
|----------------------------------------------------------------------------|-------------|
|                                                                            | IOException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |             |

**See also:**

- [registerUartDeviceCallback(Handler, UartDeviceCallback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(android.os.Handler, com.google.android.things.pio.UartDeviceCallback))
- [unregisterUartDeviceCallback(UartDeviceCallback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#unregisterUartDeviceCallback(com.google.android.things.pio.UartDeviceCallback))  

### registerUartDeviceCallback

```
void registerUartDeviceCallback (Handler handler, 
                UartDeviceCallback callback)
```

Registers a callback for interrupts. The callback will be called when data is ready to read.

<br />

|                                            Parameters                                             ||
|------------|---------------------------------------------------------------------------------------|
| `handler`  | `Handler`: The Handler to run callbacks on, or null to use the current thread. <br /> |
| `callback` | `UartDeviceCallback`: UartDeviceCallback to register. <br />                          |

|                                         Throws                                          ||
|----------------------------------------------------------------------------|-------------|
|                                                                            | IOException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |             |

**See also:**

- [registerUartDeviceCallback(UartDeviceCallback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(com.google.android.things.pio.UartDeviceCallback))
- [unregisterUartDeviceCallback(UartDeviceCallback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#unregisterUartDeviceCallback(com.google.android.things.pio.UartDeviceCallback))  

### sendBreak

```
void sendBreak (int duration_msecs)
```

Send a break to the device.

<br />

|                             Parameters                             ||
|------------------|--------------------------------------------------|
| `duration_msecs` | `int`: Duration of break in milliseconds. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### setBaudrate

```
void setBaudrate (int rate)
```

Set the device baud rate.

<br />

|                   Parameters                    ||
|--------|-----------------------------------------|
| `rate` | `int`: Rate in baud per seconds. <br /> |

|                                                                              Throws                                                                               ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                             | if the requested baudrate is unsupported by the hardware. |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the requested baudrate is negative or zero.            |

### setDataSize

```
void setDataSize (int size)
```

Set the device data size.

<br />

|                Parameters                ||
|--------|----------------------------------|
| `size` | `int`: Data size in bits. <br /> |

|                                                                         Throws                                                                          ||
|--------------------------------------------------------------------------------------------------------|-------------------------------------------------|
|                                                                                                        | IOException                                     |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the requested data size is negative or zero. |
| [IOException](https://developer.android.com/reference/java/io/IOException)                             |                                                 |

### setHardwareFlowControl

```
void setHardwareFlowControl (int mode)
```

Set the hardware flow control mode.

<br />

|                                                                                                                                                        Parameters                                                                                                                                                         ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | `int`: Flow control mode. One of[HW_FLOW_CONTROL_NONE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#HW_FLOW_CONTROL_NONE),[HW_FLOW_CONTROL_AUTO_RTSCTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#HW_FLOW_CONTROL_AUTO_RTSCTS). <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### setModemControl

```
void setModemControl (int lines)
```

Set selected modem control lines.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `lines` | `int`: The set of lines to enable. Available lines are[MODEM_CONTROL_LE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_LE),[MODEM_CONTROL_DTR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DTR),[MODEM_CONTROL_RTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RTS),[MODEM_CONTROL_ST](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_ST),[MODEM_CONTROL_SR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_SR),[MODEM_CONTROL_CTS](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CTS),[MODEM_CONTROL_CD](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_CD),[MODEM_CONTROL_RI](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_RI),[MODEM_CONTROL_DSR](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#MODEM_CONTROL_DSR). <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### setParity

```
void setParity (int mode)
```

Set the device parity mode.

<br />

|                                                                                                                                                                                                                                                                                              Parameters                                                                                                                                                                                                                                                                                               ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | `int`: Parity mode. One of[PARITY_NONE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_NONE),[PARITY_EVEN](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_EVEN),[PARITY_ODD](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_ODD),[PARITY_MARK](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_MARK),[PARITY_SPACE](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#PARITY_SPACE). <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### setStopBits

```
void setStopBits (int bits)
```

Set the device stop bits.

<br />

|                 Parameters                 ||
|--------|------------------------------------|
| `bits` | `int`: Number of stop bits. <br /> |

|                                                                     Throws                                                                      ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------|
|                                                                                                        | IOException                             |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the requested stop bits is negative. |
| [IOException](https://developer.android.com/reference/java/io/IOException)                             |                                         |

### unregisterUartDeviceCallback

```
void unregisterUartDeviceCallback (UartDeviceCallback callback)
```

Unregisters a callback.

<br />

|                                  Parameters                                  ||
|------------|------------------------------------------------------------------|
| `callback` | `UartDeviceCallback`: PioInterruptCallback to unregister. <br /> |

**See also:**

- [registerUartDeviceCallback(Handler, UartDeviceCallback)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#registerUartDeviceCallback(android.os.Handler, com.google.android.things.pio.UartDeviceCallback))  

### 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.

<br />

|                                        Parameters                                         ||
|----------|---------------------------------------------------------------------------------|
| `buffer` | `byte`: Data to write. <br />                                                   |
| `length` | `int`: Number of bytes to write, may not be larger than the buffer size. <br /> |

|                  Returns                   ||
|-------|-------------------------------------|
| `int` | The number of bytes written. <br /> |

|                                                Throws                                                ||
|----------------------------------------------------------------------------|--------------------------|
|                                                                            | IOException              |
|                                                                            | IllegalArgumentException |
| [IOException](https://developer.android.com/reference/java/io/IOException) |                          |

**See also:**

- [read(byte[], int)](https://developer.android.com/reference/com/google/android/things/pio/UartDevice#read(byte[], int))  
-

  ## Interfaces

  - [Gpio](https://developer.android.com/reference/com/google/android/things/pio/Gpio)
  - [GpioCallback](https://developer.android.com/reference/com/google/android/things/pio/GpioCallback)
  - [I2cDevice](https://developer.android.com/reference/com/google/android/things/pio/I2cDevice)
  - [Pwm](https://developer.android.com/reference/com/google/android/things/pio/Pwm)
  - [SpiDevice](https://developer.android.com/reference/com/google/android/things/pio/SpiDevice)
  - [UartDevice](https://developer.android.com/reference/com/google/android/things/pio/UartDevice)
  - [UartDeviceCallback](https://developer.android.com/reference/com/google/android/things/pio/UartDeviceCallback)
-

  ## Classes

  - [PeripheralManager](https://developer.android.com/reference/com/google/android/things/pio/PeripheralManager)