Class SerialConnection
java.lang.Object
|
+--SerialConnection
- All Implemented Interfaces:
- java.util.EventListener, javax.comm.SerialPortEventListener
- Direct Known Subclasses:
- Bird
- public class SerialConnection
- extends java.lang.Object
- implements javax.comm.SerialPortEventListener
A class that handles the details of a serial connection.
Constructor Summary |
SerialConnection()
Creates a SerialConnection object. |
SerialConnection(java.lang.String name)
Creates a Serial Connection with specified name |
SerialConnection(java.lang.String name,
java.lang.String portName)
Creates a Serial Connection with the Specified name. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
portList
static java.util.Enumeration portList
outStream
private java.io.OutputStream outStream
inStream
private java.io.InputStream inStream
portId
private javax.comm.CommPortIdentifier portId
serialPort
private javax.comm.SerialPort serialPort
portName
private java.lang.String portName
appName
private java.lang.String appName
timeout
private final int timeout
baudRate
private final int baudRate
open
private boolean open
listener
private SerialConnectionListener listener
SerialConnection
public SerialConnection()
- Creates a SerialConnection object. Defaults to opening COM3.
SerialConnection
public SerialConnection(java.lang.String name)
- Creates a Serial Connection with specified name
- Parameters:
name
- is the name of this serial connection.
SerialConnection
public SerialConnection(java.lang.String name,
java.lang.String portName)
- Creates a Serial Connection with the Specified name.
- Parameters:
name
- is the name for this serial port.portName
- is the name of the port that will be opened.
openConnection
public void openConnection()
- Attempts to open a serial connection and streams using the parameters
in the SerialParameters object. If it is unsuccesfull at any step it
returns the port to a closed state, throws a
SerialConnectionException
, and returns.
Gives a timeout of 30 seconds on the portOpen to allow other applications
to reliquish the port if have it open and no longer need it.
writeByte
public void writeByte(byte data)
writeByte
public void writeByte(int data)
setSerialConnectionListener
public void setSerialConnectionListener(SerialConnectionListener l)
getSerialConectionListener
public SerialConnectionListener getSerialConectionListener()
closeConnection
public void closeConnection()
- Close the port and clean up associated elements.
isOpen
public boolean isOpen()
- Reports the open status of the port.
- Returns:
- true if port is open, false if port is closed.
serialEvent
public void serialEvent(javax.comm.SerialPortEvent ev)
- Data available at the serial port.
This event will be generated once when new data arrive at the serial
port. Even if the user doesn't read the data, it won't be generated
again until next time new data arrive.
- Specified by:
serialEvent
in interface javax.comm.SerialPortEventListener