|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.util.Errorable
ewe.io.BasicStreamObject
ewe.io.StreamObject
ewe.io.SerialPort
SerialPort accesses a device's or PC's serial port.
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. If the open attempt is successful, a call to isOpen() will return true and the port will remain open until close() is called. If close() is never called, the port will be closed when the object is garbage collected.
Use the SerialPort as you would any other Stream. It is fully asynchronous.
| Field Summary | |
static int |
EVENPARITY
|
static int |
HARDWARE_FLOW_CONTROL
|
static int |
MARKPARITY
|
static int |
NO_FLOW_CONTROL
|
static int |
NOPARITY
|
static int |
ODDPARITY
|
static int |
SOFTWARE_FLOW_CONTROL
|
static int |
SPACEPARITY
|
| Fields inherited from class ewe.io.StreamObject |
napIterations, napTime, READWRITE_CLOSED, READWRITE_ERROR, READWRITE_WOULDBLOCK |
| Fields inherited from class ewe.io.BasicStreamObject |
closed |
| Fields inherited from class ewe.util.Errorable |
error |
| Fields inherited from interface ewe.io.StreamCanPause |
PAUSE_UNTIL_CAN_READ, PAUSE_UNTIL_CAN_WRITE, PAUSE_UNTIL_CLOSED, PAUSE_UNTIL_FLUSHED |
| Constructor Summary | |
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. |
|
| Method Summary | |
static boolean |
canOpen(String name)
Checks if a port with the specified name (e.g. |
boolean |
close()
Closes the port. |
static String[] |
enumerateAvailablePorts()
Enumerate all available Comm ports. |
void |
finalize()
Writes to the port. |
boolean |
flushStream()
This is non-blocking. |
boolean |
isOpen()
Returns true if the port is open and false otherwise. |
void |
kill()
This forceably closes the serial port, even if there is data pending to be sent. |
int |
nonBlockingRead(byte[] buf,
int start,
int count)
This is the non-blocking read operation. |
int |
nonBlockingWrite(byte[] buf,
int start,
int count)
This is the non-blocking write operation. |
int |
pauseUntilReady(int type,
int time)
|
boolean |
setFlowControl(int type)
Selects different flow control - hardware, software (XON/XOFF) or none. |
| Methods inherited from class ewe.io.StreamObject |
closeStream, doRead, doWrite, flush, nap, nap, read, readAByte, readBytes, readBytes, write, writeAByte, writeBytes, writeBytes |
| Methods inherited from class ewe.io.BasicStreamObject |
getException, getName, read, read, throwIOException, toInputStream, toOutputStream, toStream, write, write |
| Methods inherited from class ewe.util.Errorable |
returnError, returnError, returnError |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, toString |
| Field Detail |
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 SOFTWARE_FLOW_CONTROL
public static final int HARDWARE_FLOW_CONTROL
public static final int NO_FLOW_CONTROL
| Constructor Detail |
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)
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 bitssetFlowControl(int)
public SerialPort(String name,
int baudRate,
int bits,
int parity,
int stopBits)
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 bitssetFlowControl(int)
public SerialPort(int number,
int baudRate)
public SerialPort(String name,
int baudRate)
| Method Detail |
public boolean close()
close in interface BasicStreamclose in class StreamObjectpublic boolean isOpen()
isOpen in interface BasicStreamisOpen in class StreamObjectpublic boolean setFlowControl(int type)
type - HARDWARE_FLOW_CONTROL or SOFTWARE_FLOW_CONTROL or both or NO_FLOW_CONTROL.public static String[] enumerateAvailablePorts()
public static boolean canOpen(String name)
name - The name of the serial port.
public int nonBlockingRead(byte[] buf,
int start,
int count)
StreamObjectThe default StreamObject implementation of this uses the single byte read() method.
nonBlockingRead in interface BasicStreamnonBlockingRead in class StreamObjectbuf - Destination byte array to hold incoming data.start - Starting index in buff for incoming data.count - Maximum number of bytes to read - should never be zero.
public int nonBlockingWrite(byte[] buf,
int start,
int count)
StreamObjectThe default StreamObject implementation of this uses the single byte write() method.
nonBlockingWrite in interface BasicStreamnonBlockingWrite in class StreamObjectbuf - Source byte array holding data to be written.start - Starting index in buff for data to be written.count - Number of bytes to write - should never be zero.
public int pauseUntilReady(int type,
int time)
pauseUntilReady in interface StreamCanPause
public boolean flushStream()
throws IOException
BasicStream
flushStream in interface BasicStreamIOExceptionpublic void finalize()
finalize in class Object
public void kill()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||