public class SerialPort extends Object
Serial port access under Java on a PC requires the Dynamic Link Library java_ewe.dll
When a serial port is created, an attempt is made to open the port.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FLOW_CONTROL |
static int |
EVENPARITY |
static int |
HARDWARE_FLOW_CONTROL |
static int |
MARKPARITY |
static int |
NO_FLOW_CONTROL |
static int |
NOPARITY |
static int |
ODDPARITY |
static int |
PURGE_ALL |
static int |
PURGE_RX_ABORT |
static int |
PURGE_RX_CLEAR |
static int |
PURGE_TX_ABORT |
static int |
PURGE_TX_CLEAR |
static int |
SOFTWARE_FLOW_CONTROL |
static int |
SPACEPARITY |
Constructor and Description |
---|
SerialPort(int number,
int baudRate)
Open a serial port with settings of 8 bits, no parity and 1 stop bit.
|
SerialPort(int number,
int baudRate,
int bits,
int parity,
int stopBits)
Opens a serial port.
|
SerialPort(SerialPortSpecs options)
Create a new open SerialPort.
|
SerialPort(String name,
int baudRate)
Open a serial port with settings of 8 bits, no parity and 1 stop bit.
|
SerialPort(String name,
int baudRate,
int bits,
int parity,
int stopBits)
Opens a serial port.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
canOpen(String name) |
void |
close()
Closes the port.
|
static String[] |
enumerateAvailablePorts()
Enumerate all available Comm ports.
|
protected void |
finalize()
This method (when overriden), will be called when the VM determines that the Object can be
garbage collected.
|
InputStream |
getInputStream() |
static int |
getMaxPortNumber()
Port numbers go from 1 to the maximum available on the running computer.
|
OutputStream |
getOutputStream() |
boolean |
isInputShutdown() |
boolean |
isOutputShutdown() |
void |
kill()
This does a purge() and close() on the port, even if there is data pending to be sent.
|
static String |
portNumberToName(int portNumber)
Port numbers go from 1 to the maximum available on the running computer.
|
void |
purge(int purgeType) |
boolean |
setFlowControl(int type)
Selects different flow control - hardware, software (XON/XOFF) or none.
|
void |
shutdownInput() |
void |
shutdownOutput() |
public static final int NOPARITY
public static final int ODDPARITY
public static final int EVENPARITY
public static final int MARKPARITY
public static final int SPACEPARITY
public static final int DEFAULT_FLOW_CONTROL
public static final int SOFTWARE_FLOW_CONTROL
public static final int HARDWARE_FLOW_CONTROL
public static final int NO_FLOW_CONTROL
public static final int PURGE_ALL
public static final int PURGE_RX_ABORT
public static final int PURGE_RX_CLEAR
public static final int PURGE_TX_ABORT
public static final int PURGE_TX_CLEAR
public SerialPort(SerialPortSpecs options) throws IOException
options
- The options for the opening the Serial Port.IOException
- if the Serial Port could not be opened successfully.public SerialPort(int number, int baudRate, int bits, int parity, int stopBits) throws IOException
On Windows devices, port numbers map to COM port numbers. For example, serial port 2 maps to "COM2:".
Here is an example of opening serial port COM2: on a Windows device:
SerialPort port = new SerialPort(2, 57600, 8, SerialPort.NOPARITY, 1);No serial XON/XOFF flow control (commonly called software flow control) is used and RTS/CTS flow control (commonly called hardware flow control) is turn on by default on all platforms but Windows CE.
number
- port numberbaudRate
- baud ratebits
- bits per char [5 to 8]parity
- NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITYstopBits
- number of stop bitsIOException
setFlowControl(int)
public SerialPort(String name, int baudRate, int bits, int parity, int stopBits) throws IOException
Here is an example of opening serial port COM2: on a Windows device:
SerialPort port = new SerialPort("COM2:", 57600, 8, SerialPort.NOPARITY, 1);No serial XON/XOFF flow control (commonly called software flow control) is used and RTS/CTS flow control (commonly called hardware flow control) is turn on by default on all platforms but Windows CE.
name
- port name - e.g. "COM1:" on Win32/WinCE systems.baudRate
- baud ratebits
- bits per char [5 to 8]parity
- NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITYstopBits
- number of stop bitsIOException
setFlowControl(int)
public SerialPort(int number, int baudRate) throws IOException
IOException
public SerialPort(String name, int baudRate) throws IOException
IOException
public static boolean canOpen(String name)
public void close() throws IOException
IOException
public static int getMaxPortNumber()
public static String portNumberToName(int portNumber)
public boolean setFlowControl(int type)
type
- HARDWARE_FLOW_CONTROL or SOFTWARE_FLOW_CONTROL or both or NO_FLOW_CONTROL.public static String[] enumerateAvailablePorts()
protected void finalize() throws Throwable
Object
The finalize() method of a Class is only called if it overrides finalize() - the finalize() method java.lang.Object is never called by the Eve VM.
public void purge(int purgeType) throws IOException
IOException
public void kill() throws IOException
IOException
public OutputStream getOutputStream() throws IOException
IOException
public void shutdownOutput() throws IOException
IOException
public boolean isOutputShutdown()
public InputStream getInputStream() throws IOException
IOException
public void shutdownInput() throws IOException
IOException
public boolean isInputShutdown()