SerialPort
public
final
class
SerialPort
extends Object
| java.lang.Object | |
| ↳ | android.hardware.serial.SerialPort |
A class representing a Serial port.
Summary
Constants | |
|---|---|
int |
INVALID_ID
Value returned by |
int |
OPEN_FLAG_DATA_SYNC
For use with |
int |
OPEN_FLAG_NONBLOCK
For use with |
int |
OPEN_FLAG_READ_ONLY
For use with |
int |
OPEN_FLAG_READ_WRITE
For use with |
int |
OPEN_FLAG_SYNC
For use with |
int |
OPEN_FLAG_WRITE_ONLY
For use with |
Public methods | |
|---|---|
String
|
getName()
Get the device name. |
int
|
getProductId()
Return the product ID of this serial port if it is a USB device. |
int
|
getVendorId()
Return the vendor ID of this serial port if it is a USB device. |
void
|
requestOpen(int flags, boolean exclusive, Executor executor, OutcomeReceiver<SerialPortResponse, Exception> receiver)
Request to open the port. |
String
|
toString()
Returns a string representation of the object. |
Inherited methods | |
|---|---|
Constants
INVALID_ID
public static final int INVALID_ID
Value returned by getVendorId() and getProductId() if this
serial port isn't a USB device.
Constant Value: -1 (0xffffffff)
OPEN_FLAG_DATA_SYNC
public static final int OPEN_FLAG_DATA_SYNC
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): 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).
Constant Value: 4096 (0x00001000)
OPEN_FLAG_NONBLOCK
public static final int OPEN_FLAG_NONBLOCK
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): when possible, the file is opened in nonblocking mode.
Constant Value: 2048 (0x00000800)
OPEN_FLAG_READ_ONLY
public static final int OPEN_FLAG_READ_ONLY
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): open for reading only.
Constant Value: 0 (0x00000000)
OPEN_FLAG_READ_WRITE
public static final int OPEN_FLAG_READ_WRITE
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): open for reading and writing.
Constant Value: 2 (0x00000002)
OPEN_FLAG_SYNC
public static final int OPEN_FLAG_SYNC
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): 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).
Constant Value: 1048576 (0x00100000)
OPEN_FLAG_WRITE_ONLY
public static final int OPEN_FLAG_WRITE_ONLY
For use with requestOpen(int, boolean, Executor, OutcomeReceiver): open for writing only.
Constant Value: 1 (0x00000001)
Public methods
getName
public String getName ()
Get the device name. It is the dev node name under /dev, e.g. ttyUSB0, ttyACM1.
| Returns | |
|---|---|
String |
This value cannot be null. |
getProductId
public int getProductId ()
Return the product ID of this serial port if it is a USB device. Otherwise, it
returns INVALID_ID.
| Returns | |
|---|---|
int |
|
getVendorId
public int getVendorId ()
Return the vendor ID of this serial port if it is a USB device. Otherwise, it
returns INVALID_ID.
| Returns | |
|---|---|
int |
|
requestOpen
public void requestOpen (int flags,
boolean exclusive,
Executor executor,
OutcomeReceiver<SerialPortResponse, Exception> receiver)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: the outcome receiver.
This value cannot be null. |
| Throws | |
|---|---|
IllegalArgumentException |
if the set of flags is not correct. |
NullPointerException |
if any parameters are null. |
toString
public String toString ()
Returns a string representation of the object.
| Returns | |
|---|---|
String |
a string representation of the object. |