Class serialComm

java.lang.Object
  |
  +--serialComm

public class serialComm
extends java.lang.Object

This is the serial communication class for the Seeker robot. It is based on the code from the CMUcamGUI demo program, but has been modified to use javax.comm


Field Summary
(package private) static javax.comm.CommPortIdentifier commPortId
          Reference to the javax.comm comm port
(package private) static char four
          Used by the readNum() function to convert the received characters into a single number.
protected  java.io.InputStream inStream
          Reference to the serial input stream
(package private) static char one
          Used by the readNum() function to convert the received characters into a single number.
protected  java.io.OutputStream outStream
          Reference to the serial output stream
(package private) static javax.comm.SerialPort serialPort
          Reference to the javax.comm serial port
(package private) static char three
          Used by the readNum() function to convert the received characters into a single number.
(package private) static java.util.Date time
          Used to check for serial timeouts when reading data in.
(package private) static java.util.Date time2
          Used to check for serial timeouts when reading data in.
(package private) static char two
          Used by the readNum() function to convert the received characters into a single number.
(package private) static int val
          Tmp storage used to hold read data before returning it.
(package private) static long wdTimer
          Used to check for serial timeouts when reading data in.
 
Constructor Summary
(package private) serialComm(java.lang.String commPort, int Baudrate)
          Calls initializeSerialPort to open and configure the serial port.
 
Method Summary
 void initializeSerialPort(java.lang.String commPort, int Baudrate)
          Method to initialize the serial port (N81) at the given baud rate and set up the input and output streams.
 int readByte()
          Reads in a byte of data from the serial port.
 char readNonBlock()
          Checks to see if any data is waiting to be read.
 int readNum()
          Reads in an ascii number and returns an int.
This function blocks.
 void writeStr(java.lang.String in)
          Sends the input string of characters out the serial port.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

inStream

protected java.io.InputStream inStream
Reference to the serial input stream

outStream

protected java.io.OutputStream outStream
Reference to the serial output stream

serialPort

static javax.comm.SerialPort serialPort
Reference to the javax.comm serial port

commPortId

static javax.comm.CommPortIdentifier commPortId
Reference to the javax.comm comm port

one

static char one
Used by the readNum() function to convert the received characters into a single number.

two

static char two
Used by the readNum() function to convert the received characters into a single number.

three

static char three
Used by the readNum() function to convert the received characters into a single number.

four

static char four
Used by the readNum() function to convert the received characters into a single number.

time

static java.util.Date time
Used to check for serial timeouts when reading data in.

time2

static java.util.Date time2
Used to check for serial timeouts when reading data in.

wdTimer

static long wdTimer
Used to check for serial timeouts when reading data in.

val

static int val
Tmp storage used to hold read data before returning it.
Constructor Detail

serialComm

serialComm(java.lang.String commPort,
           int Baudrate)
Calls initializeSerialPort to open and configure the serial port.
Parameters:
commPort - Desired comm port to open.
Baudrate - Baud rate to open the serial port at.
Method Detail

readNum

public int readNum()
Reads in an ascii number and returns an int.
This function blocks.
Returns:
Number read from the serial port

readByte

public int readByte()
Reads in a byte of data from the serial port. Function will wait 1 second before timing out and returning with an error.
This function blocks.
Returns:
Byte read from the serial port. Will return -1 if read times out.

readNonBlock

public char readNonBlock()
Checks to see if any data is waiting to be read. If there is data there it gets and returns it. If no data is waiting, returns immediatly with a 0.
Returns:
Byte read from the serial port, or 0 if no data is waiting.

writeStr

public void writeStr(java.lang.String in)
Sends the input string of characters out the serial port.
Parameters:
in - String of btyes to write.

initializeSerialPort

public void initializeSerialPort(java.lang.String commPort,
                                 int Baudrate)
Method to initialize the serial port (N81) at the given baud rate and set up the input and output streams. If it is unable to aquire the serial port, the program will exit.
Parameters:
commPort - Desired comm port to open.
Baudrate - Baud rate to open the serial port at.