public class SerialPortManager
extends java.lang.Object
Unless noted, all serial API methods require the
com.digi.android.permission.SERIAL
permission. If your application
does not have this permission it will not have access to any serial port
service feature.
SerialPort
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ERROR_INVALID_BAUDRATE |
static java.lang.String |
ERROR_INVALID_DATABITS |
static java.lang.String |
ERROR_INVALID_FLOWCONTROL |
static java.lang.String |
ERROR_INVALID_PARITY |
static java.lang.String |
ERROR_INVALID_STOPBITS |
static java.lang.String |
ERROR_INVALID_TIMEOUT |
Constructor and Description |
---|
SerialPortManager(android.content.Context context)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
listSerialPorts()
Lists all the available serial ports.
|
SerialPort |
openSerialPort(java.lang.String port)
Opens and returns a
SerialPort object with the given port name
and the following default parameters:
Baud rate: 9600
Data bits: 8
Stop bits: 1
Parity: none
Flow control: none
Read timeout: 3000 ms
|
SerialPort |
openSerialPort(java.lang.String port,
int baudRate,
int dataBits,
int stopBits,
int parity,
int flowControl,
int readTimeout)
Opens and returns a
SerialPort object with the given port name
and serial port parameters. |
SerialPort |
openSerialPort(java.lang.String port,
SerialPortParameters serialPortParameters)
Opens and returns a
SerialPort object with the given port name
and serial port parameters. |
public static final java.lang.String ERROR_INVALID_TIMEOUT
public static final java.lang.String ERROR_INVALID_BAUDRATE
public static final java.lang.String ERROR_INVALID_DATABITS
public static final java.lang.String ERROR_INVALID_STOPBITS
public static final java.lang.String ERROR_INVALID_PARITY
public static final java.lang.String ERROR_INVALID_FLOWCONTROL
public SerialPortManager(android.content.Context context)
SerialPortManager
using
the given application context.
The SerialPortManager
allows you to create and open serial
ports using one of the following methods: openSerialPort(String)
,
openSerialPort(String, int, int, int, int, int, int)
, or
openSerialPort(String, SerialPortParameters)
.
context
- Android application context.java.lang.NullPointerException
- If context == null
.listSerialPorts()
,
openSerialPort(String)
,
openSerialPort(String, SerialPortParameters)
,
openSerialPort(String, int, int, int, int, int, int)
public SerialPort openSerialPort(java.lang.String port) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException
SerialPort
object with the given port name
and the following default parameters:
port
- Port name.NoSuchPortException
- If the given port does not exist.java.lang.NullPointerException
- If port == null
.PortInUseException
- If the given port is in use.UnsupportedCommOperationException
- If an error occurs when setting
the default serial port
parameters.listSerialPorts()
,
openSerialPort(String, SerialPortParameters)
,
openSerialPort(String, int, int, int, int, int, int)
,
SerialPort
public SerialPort openSerialPort(java.lang.String port, int baudRate, int dataBits, int stopBits, int parity, int flowControl, int readTimeout) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException
SerialPort
object with the given port name
and serial port parameters.port
- Port name.baudRate
- Baud rate.dataBits
- Data bits, one of SerialPort.DATABITS_5
,
SerialPort.DATABITS_6
,
SerialPort.DATABITS_7
, and
SerialPort.DATABITS_8
.stopBits
- Stop bits, one of SerialPort.STOPBITS_1
,
SerialPort.STOPBITS_2
, and
SerialPort.STOPBITS_1_5
.parity
- Parity, one of SerialPort.PARITY_NONE
,
SerialPort.PARITY_ODD
,
SerialPort.PARITY_EVEN
,
SerialPort.PARITY_MARK
, and
SerialPort.PARITY_SPACE
.flowControl
- Flow control, one of
SerialPort.FLOWCONTROL_NONE
,
SerialPort.FLOWCONTROL_RTSCTS_IN
,
SerialPort.FLOWCONTROL_RTSCTS_OUT
,
SerialPort.FLOWCONTROL_XONXOFF_IN
, and
SerialPort.FLOWCONTROL_XONXOFF_OUT
.readTimeout
- Read timeout.java.lang.IllegalArgumentException
- If baudRate < 0
or
if dataBits < 0
or
if stopBits < 0
or
if parity < 0
or
if flowControl < 0
or
if readTimeout < 0
.NoSuchPortException
- If the given port does not exist.java.lang.NullPointerException
- If port == null
.PortInUseException
- If the given port is in use.UnsupportedCommOperationException
- If the serial port parameters
are invalid.listSerialPorts()
,
openSerialPort(String)
,
openSerialPort(String, SerialPortParameters)
,
SerialPort
,
SerialPort.DATABITS_5
,
SerialPort.DATABITS_6
,
SerialPort.DATABITS_7
,
SerialPort.DATABITS_8
,
SerialPort.FLOWCONTROL_NONE
,
SerialPort.FLOWCONTROL_RTSCTS_IN
,
SerialPort.FLOWCONTROL_RTSCTS_OUT
,
SerialPort.FLOWCONTROL_XONXOFF_IN
,
SerialPort.FLOWCONTROL_XONXOFF_OUT
,
SerialPort.PARITY_EVEN
,
SerialPort.PARITY_MARK
,
SerialPort.PARITY_NONE
,
SerialPort.PARITY_ODD
,
SerialPort.PARITY_SPACE
,
SerialPort.STOPBITS_1
,
SerialPort.STOPBITS_1_5
,
SerialPort.STOPBITS_2
public SerialPort openSerialPort(java.lang.String port, SerialPortParameters serialPortParameters) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException
SerialPort
object with the given port name
and serial port parameters.port
- Port name.serialPortParameters
- Serial port parameters.NoSuchPortException
- If the given port does not exist.java.lang.NullPointerException
- If port == null
or
if serialPortParameters == null
.PortInUseException
- If the given port is in use.UnsupportedCommOperationException
- If the serial port parameters
are invalid.listSerialPorts()
,
openSerialPort(String)
,
openSerialPort(String, int, int, int, int, int, int)
,
SerialPort
,
SerialPortParameters
public java.lang.String[] listSerialPorts()