dea.hc
Class SerialConnection

java.lang.Object
  extended bydea.hc.SerialConnection
All Implemented Interfaces:
CommPortOwnershipListener, java.util.EventListener, SerialPortEventListener

public class SerialConnection
extends java.lang.Object
implements SerialPortEventListener, CommPortOwnershipListener

A class that handles the details of a serial connection. Reads from one TextArea and writes to a second TextArea. Holds the state of the connection.


Field Summary
 
Fields inherited from interface javax.comm.CommPortOwnershipListener
PORT_OWNED, PORT_OWNERSHIP_REQUESTED, PORT_UNOWNED
 
Constructor Summary
SerialConnection(SerialDemo parent, SerialParameters parameters, java.awt.TextArea messageAreaOut, java.awt.TextArea messageAreaIn)
          Creates a SerialConnection object and initilizes variables passed in as params.
 
Method Summary
 void closeConnection()
          Close the port and clean up associated elements.
 boolean isOpen()
          Reports the open status of the port.
 void openConnection()
          Attempts to open a serial connection and streams using the parameters in the SerialParameters object.
 void ownershipChange(int type)
          Handles ownership events.
 void sendBreak()
          Send a one second break signal.
 void serialEvent(SerialPortEvent e)
          Handles SerialPortEvents.
 void setConnectionParameters()
          Sets the connection parameters to the setting in the parameters object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialConnection

public SerialConnection(SerialDemo parent,
                        SerialParameters parameters,
                        java.awt.TextArea messageAreaOut,
                        java.awt.TextArea messageAreaIn)
Creates a SerialConnection object and initilizes variables passed in as params.

Parameters:
parent - A SerialDemo object.
parameters - A SerialParameters object.
messageAreaOut - The TextArea that messages that are to be sent out of the serial port are entered into.
messageAreaIn - The TextArea that messages comming into the serial port are displayed on.
Method Detail

openConnection

public void openConnection()
                    throws SerialConnectionException
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.

Throws:
SerialConnectionException

setConnectionParameters

public void setConnectionParameters()
                             throws SerialConnectionException
Sets the connection parameters to the setting in the parameters object. If set fails return the parameters object to origional settings and throw exception.

Throws:
SerialConnectionException

closeConnection

public void closeConnection()
Close the port and clean up associated elements.


sendBreak

public void sendBreak()
Send a one second break signal.


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(SerialPortEvent e)
Handles SerialPortEvents. The two types of SerialPortEvents that this program is registered to listen for are DATA_AVAILABLE and BI. During DATA_AVAILABLE the port buffer is read until it is drained, when no more data is availble and 30ms has passed the method returns. When a BI event occurs the words BREAK RECEIVED are written to the messageAreaIn.

Specified by:
serialEvent in interface SerialPortEventListener

ownershipChange

public void ownershipChange(int type)
Handles ownership events. If a PORT_OWNERSHIP_REQUESTED event is received a dialog box is created asking the user if they are willing to give up the port. No action is taken on other types of ownership events.

Specified by:
ownershipChange in interface CommPortOwnershipListener


Copyright © 2001-2005 Round Mountain Rescue Ranch. All Rights Reserved.