Added in API level 37

SerialPort


class SerialPort
kotlin.Any
   ↳ android.hardware.serial.SerialPort

A class representing a Serial port.

Summary

Constants
static Int

Value returned by getVendorId() and getProductId() if this serial port isn't a USB device.

static Int

For use with requestOpen: write operations on the file will complete according to the requirements of synchronized I/O data integrity completion (while file metadata may not be synchronized).

static Int

For use with requestOpen: when possible, the file is opened in nonblocking mode.

static Int

For use with requestOpen: open for reading only.

static Int

For use with requestOpen: open for reading and writing.

static Int

For use with requestOpen: write operations on the file will complete according to the requirements of synchronized I/O file integrity completion (by contrast with the synchronized I/O data integrity completion provided by FLAG_DATA_SYNC).

static Int

For use with requestOpen: open for writing only.

Public methods
String

Get the device name.

Int

Return the product ID of this serial port if it is a USB device.

Int

Return the vendor ID of this serial port if it is a USB device.

Unit
requestOpen(flags: Int, exclusive: Boolean, executor: Executor, receiver: OutcomeReceiver<SerialPortResponse!, Exception!>)

Request to open the port.

String

Returns a string representation of the object.

Constants

INVALID_ID

Added in API level 37
static val INVALID_ID: Int

Value returned by getVendorId() and getProductId() if this serial port isn't a USB device.

Value: -1

OPEN_FLAG_DATA_SYNC

Added in API level 37
static val OPEN_FLAG_DATA_SYNC: Int

For use with requestOpen: write operations on the file will complete according to the requirements of synchronized I/O data integrity completion (while file metadata may not be synchronized).

Value: 4096

OPEN_FLAG_NONBLOCK

Added in API level 37
static val OPEN_FLAG_NONBLOCK: Int

For use with requestOpen: when possible, the file is opened in nonblocking mode.

Value: 2048

OPEN_FLAG_READ_ONLY

Added in API level 37
static val OPEN_FLAG_READ_ONLY: Int

For use with requestOpen: open for reading only.

Value: 0

OPEN_FLAG_READ_WRITE

Added in API level 37
static val OPEN_FLAG_READ_WRITE: Int

For use with requestOpen: open for reading and writing.

Value: 2

OPEN_FLAG_SYNC

Added in API level 37
static val OPEN_FLAG_SYNC: Int

For use with requestOpen: write operations on the file will complete according to the requirements of synchronized I/O file integrity completion (by contrast with the synchronized I/O data integrity completion provided by FLAG_DATA_SYNC).

Value: 1048576

OPEN_FLAG_WRITE_ONLY

Added in API level 37
static val OPEN_FLAG_WRITE_ONLY: Int

For use with requestOpen: open for writing only.

Value: 1

Public methods

getName

Added in API level 37
fun getName(): String

Get the device name. It is the dev node name under /dev, e.g. ttyUSB0, ttyACM1.

Return
String This value cannot be null.

getProductId

Added in API level 37
fun getProductId(): Int

Return the product ID of this serial port if it is a USB device. Otherwise, it returns INVALID_ID.

getVendorId

Added in API level 37
fun getVendorId(): Int

Return the vendor ID of this serial port if it is a USB device. Otherwise, it returns INVALID_ID.

requestOpen

Added in API level 37
fun requestOpen(
    flags: Int,
    exclusive: Boolean,
    executor: Executor,
    receiver: OutcomeReceiver<SerialPortResponse!, Exception!>
): Unit

Request to open the port.

Exceptions passed to receiver may be

Parameters
flags Int: open flags that define read/write mode and other options.
Value is either 0 or a combination of the following:
exclusive Boolean: whether to request exclusive access to the port, preventing other processes from opening it.
executor Executor: the executor used to run receiver.
This value cannot be null.
receiver OutcomeReceiver<SerialPortResponse!, Exception!>: the outcome receiver.
This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the set of flags is not correct.
java.lang.NullPointerException if any parameters are null.

toString

Added in API level 37
fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.