sophware.home.io
Class SerialAccess

java.lang.Object
  extended by sophware.home.io.SerialAccess
All Implemented Interfaces:
java.util.EventListener, javax.comm.SerialPortEventListener, HomeAccess

public class SerialAccess
extends java.lang.Object
implements HomeAccess, javax.comm.SerialPortEventListener

SerialAccess provides communications access to serial ports.

Requires a javax.comm implementation.

Version:
1.0, 02/17/06
Author:
Russell Soph

Constructor Summary
SerialAccess(java.lang.String port)
          Creates an instance of the SerialAccess
SerialAccess(java.lang.String port, int baudrate, int databits, int stopbits, int parity)
          Creates an instance of the SerialAccess
 
Method Summary
 void close()
          Closes the Serial Port
 java.io.InputStream getInputStream()
          Gets the input stream associate with the Serial Port
 java.io.OutputStream getOutputStream()
          Gets the output stream associate with the Serial Port
 boolean isOpen()
          Checks status of the connection
 void open()
          Opens and initializes the Serial Port
 void serialEvent(javax.comm.SerialPortEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialAccess

public SerialAccess(java.lang.String port)
Creates an instance of the SerialAccess

DEFAULT: 4800 baud, 8 data bits, 1 stop bit, no parity

Parameters:
port - the COM port connected to the device

SerialAccess

public SerialAccess(java.lang.String port,
                    int baudrate,
                    int databits,
                    int stopbits,
                    int parity)
Creates an instance of the SerialAccess

The databits, stopbits and parity should use the static fields provided by javax.comm.SerialPort

Parameters:
port - the COM port connected to the device (e.g. COM1, COM2, ...)
baudrate - the baud rate of the port
databits -
  • SerialPort.DATABITS_5: 5 data bits
  • SerialPort.DATABITS_6: 6 data bits
  • SerialPort.DATABITS_7: 7 data bits
  • SerialPort.DATABITS_8: 8 data bits
stopbits -
  • SerialPort.STOPBITS_1: 1 stop bit
  • SerialPort.STOPBITS_2: 2 stop bits
  • SerialPort.STOPBITS_1_5: 1.5 stop bits
parity -
  • SerialPort.PARITY_NONE: no parity
  • SerialPort.PARITY_ODD: odd parity
  • SerialPort.PARITY_EVEN: even parity
  • SerialPort.PARITY_MARK: mark parity
  • SerialPort.PARITY_SPACE: space parity
Method Detail

open

public void open()
          throws java.io.IOException
Opens and initializes the Serial Port

Specified by:
open in interface HomeAccess
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
Gets the input stream associate with the Serial Port

Specified by:
getInputStream in interface HomeAccess
Returns:
the input stream

getOutputStream

public java.io.OutputStream getOutputStream()
Gets the output stream associate with the Serial Port

Specified by:
getOutputStream in interface HomeAccess
Returns:
the output stream

serialEvent

public void serialEvent(javax.comm.SerialPortEvent event)
Specified by:
serialEvent in interface javax.comm.SerialPortEventListener
See Also:
SerialPortEventListener

close

public void close()
Closes the Serial Port

Specified by:
close in interface HomeAccess

isOpen

public boolean isOpen()
Checks status of the connection

Specified by:
isOpen in interface HomeAccess
Returns:
true is connection is open