SerialPort
class SerialPort
| kotlin.Any | |
| ↳ | android.hardware.serial.SerialPort |
A class representing a Serial port.
Summary
| Constants | |
|---|---|
| static Int |
Value returned by |
| static Int |
For use with |
| static Int |
For use with |
| static Int |
For use with |
| static Int |
For use with |
| static Int |
For use with |
| static Int |
For use with |
| Public methods | |
|---|---|
| String |
getName()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 |
toString()Returns a string representation of the object. |
Constants
INVALID_ID
static val INVALID_ID: Int
Value returned by getVendorId() and getProductId() if this serial port isn't a USB device.
Value: -1OPEN_FLAG_DATA_SYNC
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: 4096OPEN_FLAG_NONBLOCK
static val OPEN_FLAG_NONBLOCK: Int
For use with requestOpen: when possible, the file is opened in nonblocking mode.
Value: 2048OPEN_FLAG_READ_ONLY
static val OPEN_FLAG_READ_ONLY: Int
For use with requestOpen: open for reading only.
Value: 0OPEN_FLAG_READ_WRITE
static val OPEN_FLAG_READ_WRITE: Int
For use with requestOpen: open for reading and writing.
Value: 2OPEN_FLAG_SYNC
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: 1048576OPEN_FLAG_WRITE_ONLY
static val OPEN_FLAG_WRITE_ONLY: Int
For use with requestOpen: open for writing only.
Value: 1Public methods
getName
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
fun getProductId(): Int
Return the product ID of this serial port if it is a USB device. Otherwise, it returns INVALID_ID.
getVendorId
fun getVendorId(): Int
Return the vendor ID of this serial port if it is a USB device. Otherwise, it returns INVALID_ID.
requestOpen
fun requestOpen(
flags: Int,
exclusive: Boolean,
executor: Executor,
receiver: OutcomeReceiver<SerialPortResponse!, Exception!>
): Unit
Request to open the port.
Exceptions passed to receiver may be
-
IllegalStateExceptionif the port is not found. -
IOExceptionif the port cannot be opened. -
SecurityExceptionif the user rejects the open request.
| 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
fun toString(): String
Returns a string representation of the object.
| Return | |
|---|---|
String |
a string representation of the object. |