vfstagecontroller
Class SerialConnection

java.lang.Object
  |
  +--vfstagecontroller.SerialConnection
All Implemented Interfaces:
javax.comm.CommPortOwnershipListener, java.util.EventListener, javax.comm.SerialPortEventListener

public class SerialConnection
extends java.lang.Object
implements javax.comm.SerialPortEventListener, javax.comm.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.


Inner Class Summary
(package private)  class SerialConnection.KeyHandler
          A class to handle KeyEvents generated by the messageAreaOut.
 
Fields inherited from interface javax.comm.CommPortOwnershipListener
PORT_OWNED, PORT_OWNERSHIP_REQUESTED, PORT_UNOWNED
 
Constructor Summary
SerialConnection(SerialParameters parameters)
          Creates a SerialConnection object and initilizes variables passed in as params.
SerialConnection(SerialParameters parameters, java.awt.TextArea tArea)
           
 
Method Summary
 void closeConnection()
          Close the port and clean up associated elements.
(package private)  java.io.InputStream getInputStream()
          Return input stream
(package private)  java.io.OutputStream getOutputStream()
          Rerturn outupStrem
 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.
 boolean sendAck(long msTimeOut)
          Send command to serial port
 void sendBreak()
          Send a one second break signal.
 java.lang.String sendCommand(java.lang.String command)
          Send command to serial port
 void serialEvent(javax.comm.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(SerialParameters parameters)
Creates a SerialConnection object and initilizes variables passed in as params.
Parameters:
parameters - A SerialParameters object. port are displayed on.

SerialConnection

public SerialConnection(SerialParameters parameters,
                        java.awt.TextArea tArea)
Method Detail

getOutputStream

java.io.OutputStream getOutputStream()
Rerturn outupStrem

getInputStream

java.io.InputStream getInputStream()
Return input stream

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.

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.

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(javax.comm.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 javax.comm.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 javax.comm.CommPortOwnershipListener

sendCommand

public java.lang.String sendCommand(java.lang.String command)
Send command to serial port

sendAck

public boolean sendAck(long msTimeOut)
Send command to serial port