edu.virginia.jburnette.io
Class SerialReadWrite

java.lang.Object
  extended byedu.virginia.jburnette.io.SerialReadWrite

public class SerialReadWrite
extends java.lang.Object


Constructor Summary
SerialReadWrite()
          Opens a connection on the serial port.
SerialReadWrite(java.lang.String port)
          Opens the specified port.
 
Method Summary
 byte[] read()
          Reads and returns the byte from the serial device.
 void stop()
          Attempt to close the port.
 boolean wasPortOpened()
          Returns true if the port opened.
 void write(int output)
          Sends an int to the serial device.
 void write(java.lang.String output)
          Sends a java.lang.String to the serial device.
 java.lang.String writeOut()
          Convience method for testing writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialReadWrite

public SerialReadWrite()
                throws gnu.io.PortInUseException,
                       PortNotFoundException
Opens a connection on the serial port. Eventually will take a port address. Right now uses /dev/tty.USA19H181P1.1. This must be changed and the code compiled if the port address changes. Exceptions must handled by the caller. If the port is opened portOpen is set to True. Check by calling wasPortOpened().

Throws:
PortNotFoundException - thrown if the port did not open.
gnu.io.PortInUseException

SerialReadWrite

public SerialReadWrite(java.lang.String port)
                throws gnu.io.PortInUseException,
                       PortNotFoundException
Opens the specified port.

Parameters:
port - User specified port.
Method Detail

read

public byte[] read()
            throws java.io.IOException
Reads and returns the byte from the serial device. In calling code (assuming the device is sending byte65:
		while((int)nums[0] != 65){
                                        try {
                                                nums = readWrite.read();
                                        } catch (IOException ioe) {}
                                }
                

Returns:
the byte sent by the serial device.
Throws:
java.io.IOException

write

public void write(int output)
Sends an int to the serial device.

Parameters:
output - Number to send

write

public void write(java.lang.String output)
Sends a java.lang.String to the serial device.

Parameters:
output - String to send

writeOut

public java.lang.String writeOut()
Convience method for testing writing. Returns a message if sending worked. Sends a '0' followed by a 'Z' to the serial device.

Returns:
'Sent 0 then Z.' returned if all went well.

stop

public void stop()
          throws java.io.IOException
Attempt to close the port. Doesn't work becuase cannot re-open the port latter.

Throws:
java.io.IOException

wasPortOpened

public boolean wasPortOpened()
Returns true if the port opened. False if it did not.

Returns:
port state.