public class SerialPort extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DATABITS_7
DATABITS_7
|
static int |
DATABITS_8
DATABITS_8
|
static int |
FLOWCONTROL_NONE
FLOWCONTROL_NONE
|
static int |
FLOWCONTROL_RTSCTS_IN
FLOWCONTROL_RTSCTS_IN
|
static int |
FLOWCONTROL_RTSCTS_OUT
FLOWCONTROL_RTSCTS_OUT
|
static int |
FLOWCONTROL_XONXOFF_IN
FLOWCONTROL_XONXOFF_IN
|
static int |
FLOWCONTROL_XONXOFF_OUT
FLOWCONTROL_XONXOFF_OUT
|
static int |
PARITY_EVEN
PARITY_EVEN
|
static int |
PARITY_NONE
PARITY_NONE
|
static int |
PARITY_ODD
PARITY_ODD
|
static int |
SPEED_110
SPEED_110
|
static int |
SPEED_115200
SPEED_115200
|
static int |
SPEED_1200
SPEED_1200
|
static int |
SPEED_128000
SPEED_128000
|
static int |
SPEED_14400
SPEED_14400
|
static int |
SPEED_150
SPEED_150
|
static int |
SPEED_19200
SPEED_19200
|
static int |
SPEED_2400
SPEED_2400
|
static int |
SPEED_250000
SPEED_250000
|
static int |
SPEED_28800
SPEED_28800
|
static int |
SPEED_300
SPEED_300
|
static int |
SPEED_31250
SPEED_31250
|
static int |
SPEED_38400
SPEED_38400
|
static int |
SPEED_4800
SPEED_4800
|
static int |
SPEED_56000
SPEED_56000
|
static int |
SPEED_57600
SPEED_57600
|
static int |
SPEED_600
SPEED_600
|
static int |
SPEED_9600
SPEED_9600
|
static int |
STDAUX
STDAUX
|
static int |
STDCOM
STDCOM
|
static int |
STOPBITS_1
STOPBITS_1
|
static int |
STOPBITS_2
STOPBITS_2
|
Modifier | Constructor and Description |
---|---|
protected |
SerialPort(int port)
Initializer used only when instantiating AUXSerialPort.class and COMSerialPort.class.
|
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(SerialPortEventListener eventListener)
Adds an event listener for the port.
|
void |
close()
Closes the serial port and associated streams.
|
void |
disableReceiveFraming()
Disables the ports receive framing.
|
void |
disableReceiveThreshold()
Disables the ports receive threshold.
|
void |
disableReceiveTimeout()
Disables the ports receive timeout.
|
void |
enableReceiveFraming(int framingByte) |
void |
enableReceiveThreshold(int thresh)
Enables the ports receive threshold.
|
void |
enableReceiveTimeout(int rcvTimeout)
Enables the ports receive timeout.
|
int |
getBaudRate()
Returns the ports current baud rate in bits per second.
|
int |
getDataBits()
Returns the ports current the data bit (word size) setting.
|
int |
getFlowControlMode()
Returns the ports current flow control mode.
|
int |
getInputBufferSize()
Returns the ports input buffer size.
|
SerialInputStream |
getInputStream()
Returns the InputStream associated with this port.
|
int |
getOutputBufferSize()
Returns the ports current output buffer size.
|
SerialOutputStream |
getOutputStream()
Returns the OutputStream associated with this port.
|
int |
getParity()
Returns the ports current parity setting.
|
int |
getReceiveFramingByte()
Returns the ports receive framing byte.
|
int |
getReceiveThreshold()
Returns the ports threshold enable state.
|
int |
getReceiveTimeout()
Returns the ports current receive timeout.
|
int |
getStopBits()
Returns the ports current stop bits setting.
|
boolean |
isReceiveFramingEnabled()
Returns the ports receive framing enable state.
|
boolean |
isReceiveThresholdEnabled()
Returns the ports threshold enable state.
|
boolean |
isReceiveTimeoutEnabled()
Returns the ports receive timeout enable state.
|
void |
notifyOnBreakInterrupt(boolean enable)
Requests notification when break interrupt occurs.
|
void |
notifyOnCTS(boolean enable)
Requests notification when CTS changes state.
|
void |
notifyOnDataAvailable(boolean enable)
Requests notification when data is available to read.
|
void |
notifyOnFramingError(boolean enable)
Requests notification when framing error occurs.
|
void |
notifyOnOutputEmpty(boolean enable)
Requests notification when output buffer is empty.
|
void |
notifyOnOverrunError(boolean enable)
Requests notification when overrun error occurs.
|
void |
notifyOnParityError(boolean enable)
Requests notification when parity error occurs.
|
void |
open()
A serial port must be opened in order to gain access to its streams.
|
void |
removeEventListener()
Removes an event listener.
|
void |
sendBreak(int millis)
Creates a serial Break condition for the defined period in milliseconds.
|
void |
setBitParameters(int dataBits,
int stopBits,
int parity) |
void |
setFlowControlMode(int flow)
Sets the ports flow control mode.
|
void |
setInputBufferSize(int size)
Sets the ports input buffer size.
|
void |
setOutputBufferSize(int size)
Sets the ports output buffer size.
|
void |
setSerialPortParams(int baudRate,
int dataBits,
int stopBits,
int parity) |
public static final int STDCOM
public static final int STDAUX
public static final int SPEED_110
public static final int SPEED_150
public static final int SPEED_300
public static final int SPEED_600
public static final int SPEED_1200
public static final int SPEED_2400
public static final int SPEED_4800
public static final int SPEED_9600
public static final int SPEED_14400
public static final int SPEED_19200
public static final int SPEED_28800
public static final int SPEED_31250
public static final int SPEED_38400
public static final int SPEED_56000
public static final int SPEED_57600
public static final int SPEED_115200
public static final int SPEED_128000
public static final int SPEED_250000
public static final int DATABITS_7
public static final int DATABITS_8
public static final int STOPBITS_1
public static final int STOPBITS_2
public static final int PARITY_NONE
public static final int PARITY_ODD
public static final int PARITY_EVEN
public static final int FLOWCONTROL_NONE
public static final int FLOWCONTROL_RTSCTS_IN
public static final int FLOWCONTROL_RTSCTS_OUT
public static final int FLOWCONTROL_XONXOFF_IN
public static final int FLOWCONTROL_XONXOFF_OUT
protected SerialPort(int port)
port
- Defines serial port (COM = 4, AUX = 6).IllegalArgumentException
- when the parameter is not recognized.public void open() throws PortInUseException, IOException
PortInUseException
- when this or another process already has control of this resourceIOException
- if a stream cannot be createdpublic void close()
public void setSerialPortParams(int baudRate, int dataBits, int stopBits, int parity) throws UnsupportedCommOperationException
baudRate
- ?dataBits
- ?stopBits
- ?parity
- ?UnsupportedCommOperationException
- ?public int getBaudRate()
public void setBitParameters(int dataBits, int stopBits, int parity) throws UnsupportedCommOperationException
dataBits
- ?stopBits
- ?parity
- ?UnsupportedCommOperationException
- ?public int getDataBits()
public int getStopBits()
public int getParity()
public SerialInputStream getInputStream() throws IOException
IOException
- if the stream is not availableIllegalStateException
- if the port is not openpublic SerialOutputStream getOutputStream() throws IOException
IOException
- if the stream is not availableIllegalStateException
- if the port is not openpublic void setFlowControlMode(int flow) throws UnsupportedCommOperationException
flow
- ?UnsupportedCommOperationException
- ?IllegalStateException
- if the port is not openpublic int getFlowControlMode()
setFlowControlMode(int flow)
public void sendBreak(int millis)
millis
- desired duration of the break in millisecondsIllegalStateException
- if the port is not openpublic void addEventListener(SerialPortEventListener eventListener) throws TooManyListenersException
eventListener
- listener class to be installedIllegalStateException
- if the port is not openTooManyListenersException
- if the maximum number of listeners has
been installedpublic void removeEventListener()
public void notifyOnDataAvailable(boolean enable)
enable
- set to true to enablepublic void notifyOnOutputEmpty(boolean enable)
enable
- set to true to enablepublic void notifyOnCTS(boolean enable)
enable
- set to true to enablepublic void notifyOnOverrunError(boolean enable)
enable
- set to true to enablepublic void notifyOnParityError(boolean enable)
enable
- set to true to enablepublic void notifyOnFramingError(boolean enable)
enable
- set to true to enablepublic void notifyOnBreakInterrupt(boolean enable)
enable
- set to true to enablepublic void enableReceiveThreshold(int thresh) throws UnsupportedCommOperationException
thresh
- - Desired read thresholdUnsupportedCommOperationException
- if thresh < 0IllegalStateException
- if the InputStream is not accessablepublic void disableReceiveThreshold()
public boolean isReceiveThresholdEnabled()
javax.comm.SerialPort
.public int getReceiveThreshold()
public void enableReceiveTimeout(int rcvTimeout) throws UnsupportedCommOperationException
rcvTimeout
- timeout in millisecondsUnsupportedCommOperationException
- if rcvTimeout < 0IllegalStateException
- if the port is closedpublic void disableReceiveTimeout()
IllegalStateException
- if the port is closedpublic boolean isReceiveTimeoutEnabled()
public int getReceiveTimeout()
public void enableReceiveFraming(int framingByte) throws UnsupportedCommOperationException
framingByte
- ?UnsupportedCommOperationException
- ?public void disableReceiveFraming()
public boolean isReceiveFramingEnabled()
public int getReceiveFramingByte()
public void setInputBufferSize(int size)
size
- number of bytes to use for the input receive bufferpublic int getInputBufferSize()
public void setOutputBufferSize(int size)
size
- number of bytes to use for the output transmit bufferpublic int getOutputBufferSize()