UartDevice

public class UartDevice
extends Object implements Closeable

java.lang.Object
   ↳ com.google.android.things.pio.UartDevice


Controls an UART device. Opening an 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

Queue constant used to flush UART data that has been received but not read.

int FLUSH_IN_OUT

Queue constant used to flush UART data that has both been received and written.

int FLUSH_OUT

Queue constant used to flush UART data that has been written but not transmitted.

int HW_FLOW_CONTROL_AUTO_RTSCTS

Mode constant used to configure a UART device to use automatic RTS/CTS hardware flow control.

int HW_FLOW_CONTROL_NONE

Mode constant used to configure a UART device to use no hardware flow control.

int MODEM_CONTROL_CD

Bit constant used to configure a UART device data carrier detect.

int MODEM_CONTROL_CTS

Bit constant used to configure a UART device clear to send.

int MODEM_CONTROL_DSR

Bit constant used to configure a UART device data set ready.

int MODEM_CONTROL_DTR

Bit constant used to configure a UART device data terminal ready.

int MODEM_CONTROL_LE

Bit constant used to configure a UART device data set ready/Line enable.

int MODEM_CONTROL_RI

Bit constant used to configure a UART device ring.

int MODEM_CONTROL_RTS

Bit constant used to configure a UART device request to send.

int MODEM_CONTROL_SR

Bit constant used to configure a UART device secondary RXD.

int MODEM_CONTROL_ST

Bit constant used to configure a UART device secondary TXD.

int PARITY_EVEN

Mode constant used to configure a UART device to use even parity.

int PARITY_MARK

Mode constant used to configure a UART device to use mark parity.

int PARITY_NONE

Mode constant used to configure a UART device to use no parity.

int PARITY_ODD

Mode constant used to configure a UART device to use odd parity.

int PARITY_SPACE

Mode constant used to configure a UART device to use space parity.

Public methods

void clearModemControl(int lines)

Clear selected modem control lines.

void close()

Close and release the device.

void flush(int direction)

Flush the specified queue for the device.

int read(byte[] buffer, int length)

Read data from the device.

void registerUartDeviceCallback(UartDeviceCallback callback, Handler handler)

Registers a callback for interrupts.

final void registerUartDeviceCallback(UartDeviceCallback callback)

Registers a callback for interrupts.

void sendBreak(int duration_msecs)

Send a break to the device.

void setBaudrate(int rate)

Set the device baud rate.

void setDataSize(int size)

Set the device data size.

void setHardwareFlowControl(int mode)

Set the hardware flow control mode.

void setModemControl(int lines)

Set selected modem control lines.

void setParity(int mode)

Set the device parity mode.

void setStopBits(int bits)

Set the device stop bits.

void unregisterUartDeviceCallback(UartDeviceCallback callback)

Unregisters a callback.

int write(byte[] buffer, int length)

Write data to the device.

Inherited methods

From class java.lang.Object
From interface java.io.Closeable
From interface 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

</div>

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

</div>

close

</div>

void close ()

Close and release the device.

Must be called in order to make the device available to other users.</p>

Throws
IOException if the UartDevice is already closed.

</div>

flush

</div>

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

</div>

read

</div>

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.</p>

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:

  • write(byte[], int)

</div>

registerUartDeviceCallback

</div>

void registerUartDeviceCallback (UartDeviceCallback callback,
                Handler handler)

Registers a callback for interrupts.

The callback will be called when data is ready to read.</p>

Parameters
callback UartDeviceCallback: UartDeviceCallback to register.
handler Handler: The Handler to run callbacks on, or null to use the current thread.
Throws
IOException
IOException

See also:

  • registerUartDeviceCallback(UartDeviceCallback)
  • unregisterUartDeviceCallback(UartDeviceCallback)

</div>

registerUartDeviceCallback

</div>

void registerUartDeviceCallback (UartDeviceCallback callback)

Registers a callback for interrupts.

Equivalent to registerUartDeviceCallback(callback, null).</p>

Parameters
callback UartDeviceCallback: UartDeviceCallback to register.
Throws
IOException
IOException

See also:

  • registerUartDeviceCallback(UartDeviceCallback, Handler)
  • unregisterUartDeviceCallback(UartDeviceCallback)

</div>

sendBreak

</div>

void sendBreak (int duration_msecs)

Send a break to the device.

Parameters
duration_msecs int: Duration of break in milliseconds.
Throws
IOException

</div>

setBaudrate

</div>

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.

</div>

setDataSize

</div>

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

</div>

setHardwareFlowControl

</div>

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

</div>

setModemControl

</div>

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

</div>

setParity

</div>

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

</div>

setStopBits

</div>

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

</div>

unregisterUartDeviceCallback

</div>

void unregisterUartDeviceCallback (UartDeviceCallback callback)

Unregisters a callback.

Parameters
callback UartDeviceCallback: PioInterruptCallback to unregister.

See also:

  • registerUartDeviceCallback(UartDeviceCallback, Handler)

</div>

write

</div>

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.</p>

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:

  • read(byte[], int)

</div>

results matching ""

    No results matching ""