java.lang.Object | |
↳ | com.digi.android.serial.SerialPort |
Represents a serial port to communicate with.
To obtain an instance of the serial port and open it you have to use one
of the following methods: SerialPortManager.openSerialPort(String)
,
SerialPortManager.openSerialPort(String, int, int, int, int, int, int)
,
or SerialPortManager.openSerialPort(String, SerialPortParameters)
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DATABITS_5 | 5 data bits: .DATABITS_5 . |
|||||||||
int | DATABITS_6 | 6 data bits: .DATABITS_6 . |
|||||||||
int | DATABITS_7 | 7 data bits: .DATABITS_7 . |
|||||||||
int | DATABITS_8 | 8 data bits: .DATABITS_8 . |
|||||||||
int | DEFAULT_READ_TIMEOUT | Default read timeout: .DEFAULT_READ_TIMEOUT milliseconds. |
|||||||||
int | FLOWCONTROL_NONE | No flow control: .FLOWCONTROL_NONE . |
|||||||||
int | FLOWCONTROL_RTSCTS_IN | Hardware flow control (input): .FLOWCONTROL_RTSCTS_IN . |
|||||||||
int | FLOWCONTROL_RTSCTS_OUT | Hardware flow control (output): .FLOWCONTROL_RTSCTS_OUT . |
|||||||||
int | FLOWCONTROL_XONXOFF_IN | Xon/Xoff flow control (input): .FLOWCONTROL_XONXOFF_IN . |
|||||||||
int | FLOWCONTROL_XONXOFF_OUT | Xon/Xoff flow control (output): .FLOWCONTROL_XONXOFF_OUT . |
|||||||||
int | PARITY_EVEN | Parity even: .PARITY_EVEN . |
|||||||||
int | PARITY_MARK | Parity mark: .PARITY_MARK . |
|||||||||
int | PARITY_NONE | Parity none: .PARITY_NONE . |
|||||||||
int | PARITY_ODD | Parity odd: .PARITY_ODD . |
|||||||||
int | PARITY_SPACE | Parity space: .PARITY_SPACE . |
|||||||||
int | STOPBITS_1 | 1 stop bit: .STOPBITS_1 . |
|||||||||
int | STOPBITS_1_5 | 1.5 stop bits: .STOPBITS_1_5 . |
|||||||||
int | STOPBITS_2 | 2 stop bits: .STOPBITS_2 . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes the communications port.
| |||||||||||
Disables receive threshold.
| |||||||||||
Disables receive timeout.
| |||||||||||
Enables receive threshold, if this feature is supported by the driver.
| |||||||||||
Enables receive timeout, if this feature is supported by the driver.
| |||||||||||
Returns the baud base value.
| |||||||||||
Returns the configured baud rate.
| |||||||||||
Returns the configured data bits.
| |||||||||||
Returns the divisor value.
| |||||||||||
Returns the end of input character.
| |||||||||||
Returns the configured flow control.
| |||||||||||
Returns the input buffer size.
| |||||||||||
Returns the connection interface input stream to read data from.
| |||||||||||
Returns the serial port name.
| |||||||||||
Returns the output buffer size.
| |||||||||||
Returns the connection interface output stream to write data to.
| |||||||||||
Returns the configured parity.
| |||||||||||
Returns the parity error character.
| |||||||||||
Returns the integer value of the receive threshold.
| |||||||||||
Returns the integer value of the receive timeout.
| |||||||||||
Returns the configured stop bits.
| |||||||||||
Returns the state of the CD line.
| |||||||||||
Returns the state of the CTS line.
| |||||||||||
Returns the state of the DSR line.
| |||||||||||
Returns the state of the DTR line.
| |||||||||||
Returns the state of the RI line.
| |||||||||||
Returns the state of the RTS line.
| |||||||||||
Checks if receive threshold is enabled.
| |||||||||||
Checks if receive timeout is enabled.
| |||||||||||
Sets whether the listener should be notified on break interrupt.
| |||||||||||
Sets whether the listener should be notified on CTS.
| |||||||||||
Sets whether the listener should be notified on carrier detect.
| |||||||||||
Sets whether the listener should be notified on DSR.
| |||||||||||
Sets whether the listener should be notified on data available.
| |||||||||||
Sets whether the listener should be notified on framing error.
| |||||||||||
Sets whether the listener should be notified on output empty.
| |||||||||||
Sets whether the listener should be notified on overrun error.
| |||||||||||
Sets whether the listener should be notified on parity error.
| |||||||||||
Sets whether the listener should be notified on ring indicator.
| |||||||||||
Attempts to read the given amount of bytes from the serial port.
| |||||||||||
Registers the given listener to be notified when a serial port event
occurs.
| |||||||||||
Sends a break signal to the serial port with the given duration
(in milliseconds).
| |||||||||||
Sets the baud base value.
| |||||||||||
Sets the state of the DTR.
| |||||||||||
Sets the divisor value.
| |||||||||||
Sets the end of input character.
| |||||||||||
Sets the input buffer size.
| |||||||||||
Sets the output buffer size.
| |||||||||||
Sets the parity error character.
| |||||||||||
Sets the new parameters of the serial port.
| |||||||||||
Sets the state of the RTS line.
| |||||||||||
Unregisters the configured serial port event listener.
| |||||||||||
Attempts to write the given amount of bytes to the serial port.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Default read timeout: .DEFAULT_READ_TIMEOUT
milliseconds.
No flow control: .FLOWCONTROL_NONE
.
Hardware flow control (input): .FLOWCONTROL_RTSCTS_IN
.
Hardware flow control (output): .FLOWCONTROL_RTSCTS_OUT
.
Xon/Xoff flow control (input): .FLOWCONTROL_XONXOFF_IN
.
Xon/Xoff flow control (output): .FLOWCONTROL_XONXOFF_OUT
.
Closes the communications port.
The application must call this method when it is done with the port.
Disables receive threshold.
Disables receive timeout.
Enables receive threshold, if this feature is supported by the driver.
When the receive threshold condition becomes true, a read
from
the input stream for this port will return immediately.
This is an advisory method which the driver may not implement. By default, receive threshold is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveThreshold(int)
method and then
calling the isReceiveThresholdEnabled()
method. If it returns
false
, then receive threshold is not supported by the driver.
Parameters | |
---|---|
thresh |
int : When this many bytes are in the input buffer, return
immediately from read . |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
Enables receive timeout, if this feature is supported by the driver.
When the receive timeout condition becomes true, a read
from the
input stream for this port will return immediately.
This is an advisory method which the driver may not implement. By default, receive timeout is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveTimeout(int)
method and then
calling the isReceiveTimeoutEnabled()
method. If it returns
false
, then receive timeout is not supported by the driver.
Parameters | |
---|---|
time |
int : When this many milliseconds have elapsed, return immediately
from read , regardless of bytes in input buffer. |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
Returns the baud base value.
Returns | |
---|---|
int |
Baud base. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Returns the configured baud rate.
Returns | |
---|---|
int |
Baud rate. |
Returns the configured data bits.
Returns | |
---|---|
int |
Data bits. |
Returns the divisor value.
Returns | |
---|---|
int |
Divisor. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Returns the end of input character.
Returns | |
---|---|
byte |
The End of Input Character. |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Returns the configured flow control.
Returns | |
---|---|
int |
Flow control. |
Returns the input buffer size.
Returns | |
---|---|
int |
Input buffer size currently in use in bytes. |
See also:
Returns the connection interface input stream to read data from.
Returns | |
---|---|
InputStream |
The connection interface input stream to read data from. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
See also:
Returns the serial port name.
Returns | |
---|---|
String |
The serial port name. |
Returns the output buffer size.
Returns | |
---|---|
int |
Output buffer size currently in use in bytes. |
See also:
Returns the connection interface output stream to write data to.
Returns | |
---|---|
OutputStream |
The connection interface output stream to write data to. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
See also:
Returns the configured parity.
Returns | |
---|---|
int |
Parity. |
Returns the parity error character.
Returns | |
---|---|
byte |
The Parity Error Character. |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Returns the integer value of the receive threshold.
Returns | |
---|---|
int |
Number of bytes for receive threshold. |
Returns the integer value of the receive timeout.
Returns | |
---|---|
int |
Number of milliseconds in receive timeout. |
Returns the configured stop bits.
Returns | |
---|---|
int |
Stop bits. |
Returns the state of the CD line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Returns the state of the CTS line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Returns the state of the DSR line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Returns the state of the DTR line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Returns the state of the RI line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Returns the state of the RTS line.
Returns | |
---|---|
boolean |
true if the line is high, false otherwise. |
Checks if receive threshold is enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveThreshold(int)
method and then
calling the isReceiveThresholdEnabled()
method. If it returns
false
, then receive threshold is not supported by the driver.
Returns | |
---|---|
boolean |
true if the receive threshold is enabled, false
otherwise. |
Checks if receive timeout is enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveTimeout(int)
method and then
calling the isReceiveTimeoutEnabled()
method. If it returns
false
, then receive timeout is not supported by the driver.
Returns | |
---|---|
boolean |
true if the receive timeout is enabled, false
otherwise. |
Sets whether the listener should be notified on break interrupt.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on CTS.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on carrier detect.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on DSR.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on data available.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on framing error.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on output empty.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on overrun error.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on parity error.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Sets whether the listener should be notified on ring indicator.
Parameters | |
---|---|
enable |
boolean : true to notify. |
Attempts to read the given amount of bytes from the serial port.
Parameters | |
---|---|
buffer |
byte : Byte array to store read data. |
numBytes |
int : Number of bytes to read. |
Returns | |
---|---|
int |
The number of read bytes. |
Throws | |
---|---|
IllegalArgumentException |
If numBytes < 1 or
if numBytes > buffer.length . |
IOException |
If an I/O error occurs. |
See also:
Registers the given listener to be notified when a serial port event occurs.
Note that you can only register one listener.
Parameters | |
---|---|
listener |
ISerialPortEventListener : Serial port event listener. |
Throws | |
---|---|
TooManyListenersException |
If you register more than one listener. |
Sends a break signal to the serial port with the given duration (in milliseconds).
Parameters | |
---|---|
duration |
int : Duration of the break signal in milliseconds.
|
Sets the baud base value.
Parameters | |
---|---|
baudBase |
int : The clock frequency divided by 16. Default
BaudBase is 115200. |
Returns | |
---|---|
boolean |
true on success. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Sets the divisor value.
Parameters | |
---|---|
divisor |
int : Divisor. |
Returns | |
---|---|
boolean |
true on success. |
Throws | |
---|---|
IOException |
If an I/O error occurs. |
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Sets the end of input character.
Parameters | |
---|---|
b |
byte : End Of Input Character. |
Returns | |
---|---|
boolean |
true on success. |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Sets the input buffer size.
Parameters | |
---|---|
size |
int : Size of the input buffer in bytes. |
See also:
Sets the output buffer size.
Parameters | |
---|---|
size |
int : Size of the output buffer in bytes. |
See also:
Sets the parity error character.
Parameters | |
---|---|
b |
byte : Parity Error Character. |
Returns | |
---|---|
boolean |
true on success. |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Sets the new parameters of the serial port.
Parameters | |
---|---|
baudRate |
int : Baud rate. |
dataBits |
int : Data bits, one of DATABITS_5 , DATABITS_6 ,
DATABITS_7 , and DATABITS_8 . |
stopBits |
int : Stop bits, one of STOPBITS_1 , STOPBITS_2 ,
and STOPBITS_1_5 . |
parity |
int : Parity, one of PARITY_NONE , PARITY_ODD ,
PARITY_EVEN , PARITY_MARK , and
PARITY_SPACE . |
flowControl |
int : Flow control, one of FLOWCONTROL_NONE ,
FLOWCONTROL_RTSCTS_IN ,
FLOWCONTROL_RTSCTS_OUT ,
FLOWCONTROL_XONXOFF_IN , and
FLOWCONTROL_XONXOFF_OUT . Use an "|" to combine
them, e.g. FLOWCONTROL_RTSCTS_IN | FLOWCONTROL_RTSCTS_OUT . |
Throws | |
---|---|
UnsupportedCommOperationException |
If the operation is not supported by the driver. |
See also:
Returns | |
---|---|
String |
Unregisters the configured serial port event listener.
Attempts to write the given amount of bytes to the serial port.
Parameters | |
---|---|
data |
byte : Data to write. |
numBytes |
int : Number of bytes to write. |
Throws | |
---|---|
IllegalArgumentException |
If numBytes < 1 or
if numBytes > data.length . |
IOException |
If an I/O error occurs. |
See also: