kaos.robots.util.gps
Class SerialComm

java.lang.Object
  extended by kaos.robots.util.gps.SerialComm
Direct Known Subclasses:
GPSHelper

public class SerialComm
extends java.lang.Object


Field Summary
 java.io.BufferedReader _bufferedReader
           
 java.io.InputStream _inputStream
           
protected  Logger _logger
           
 
Constructor Summary
SerialComm()
          This constructor assumes common default settings.
SerialComm(int comPort)
           
SerialComm(int comPort, int speed, int databits, int stopbits, java.lang.String parity)
           
 
Method Summary
 boolean getDTR()
          Returns the value of the DTR line
 boolean getRTS()
          Returns the value of the RTS line
 boolean matchSubstring(java.lang.String input)
          Retrieves the next line of input from the stream, delimited by either a line feed or carriage return, and compares it to the provided input string to see if the two strings begin in the same manner.
protected  void printDebugString(java.lang.String msg, int loggerDisplayLevel)
           
 byte[] receiveBlob(int numbytes)
          Read a continuous block or 'blob' of bytes from the input stream.
 java.lang.String receiveLine()
          Retrieves the next line of input from the stream, delimited by either a line feed or carriage return.
 void send(byte b)
          Send the argument character on the output stream, and indicate end of input with a carriage return.
 void send(java.lang.String buffer)
          Send the argument string on the output stream.
 void sendLine(java.lang.String buffer)
          Send the argument string on the output stream, and indicate end of input with a carriage return.
 void setDTR(boolean setting)
          Sets the DTR line on or off
 void setFlowControl(java.lang.String flowControl)
          Set the flow control mode on the port.
 void setRTS(boolean setting)
          Sets the RTS line on or off
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_logger

protected Logger _logger

_inputStream

public java.io.InputStream _inputStream

_bufferedReader

public java.io.BufferedReader _bufferedReader
Constructor Detail

SerialComm

public SerialComm()
           throws java.lang.Exception
This constructor assumes common default settings.

Throws:
java.lang.Exception

SerialComm

public SerialComm(int comPort)
           throws java.lang.Exception
Parameters:
comPort - -- integer indicator of preferred Serial Com Port - a '1' would indicate: COM1 on Windows/DOS system, /dev/ttyS0 on Linux, /dev/ttya on Sun, etc. Currently coded to expect two com ports, 1 and 2.
Throws:
java.lang.Exception

SerialComm

public SerialComm(int comPort,
                  int speed,
                  int databits,
                  int stopbits,
                  java.lang.String parity)
           throws java.lang.Exception,
                  PortInUseException,
                  java.io.IOException,
                  UnsupportedCommOperationException
Parameters:
comPort - integer indicator of preferred Serial Com Port - a '1' would indicate COM1 on Windows/DOS system, /dev/ttyS0 on Linux, /dev/ttya on Sun, etc. Currently coded to expect two com ports, 1 and 2.
speed - baudrate - needs to be a speed that COM port and app can handle - i.e., one of 2400, 4800, 9600, 19200, 38400, 57600, etc.
databits - actual number of databits - needs to be one of 5, 6 ,7 or 8.
stopbits - actual number of stopbits - needs to be one of 1, 2 or 15 (i.e., 1.5).
parity - needs to be one of none, even, odd, mark or space.
Throws:
java.lang.Exception
PortInUseException
java.io.IOException
UnsupportedCommOperationException
Method Detail

setFlowControl

public void setFlowControl(java.lang.String flowControl)
Set the flow control mode on the port. It expects either "none", "rtscts" or "hardware", or "xonxoff" or "software".

Parameters:
flowControl - string determines which type of flowcontrol to set on port.

setRTS

public void setRTS(boolean setting)
Sets the RTS line on or off

Parameters:
setting - passing in true turns on RTS whereas false turns off RTS

getRTS

public boolean getRTS()
Returns the value of the RTS line

Returns:
true if RTS is currently on and false otherwise

setDTR

public void setDTR(boolean setting)
Sets the DTR line on or off

Parameters:
setting - passing in true turns on DTR whereas false turns off DTR

getDTR

public boolean getDTR()
Returns the value of the DTR line

Returns:
true if DTR is currently on and false otherwise

send

public void send(byte b)
Send the argument character on the output stream, and indicate end of input with a carriage return.

Parameters:
buffer - string to place onto output stream.

send

public void send(java.lang.String buffer)
Send the argument string on the output stream.

Parameters:
buffer - string to place onto output stream.

sendLine

public void sendLine(java.lang.String buffer)
Send the argument string on the output stream, and indicate end of input with a carriage return.

Parameters:
buffer - string to place onto output stream.

receiveLine

public java.lang.String receiveLine()
Retrieves the next line of input from the stream, delimited by either a line feed or carriage return. If the end of stream is reached, a null will be returned.

Returns:
string next line of input.

matchSubstring

public boolean matchSubstring(java.lang.String input)
Retrieves the next line of input from the stream, delimited by either a line feed or carriage return, and compares it to the provided input string to see if the two strings begin in the same manner. Response is boolean - true if the strings begin the same, false otherwise.

Parameters:
input - string that is to be compared with string read in from line.
Returns:
boolean indicating whether or not strings start the same.

receiveBlob

public byte[] receiveBlob(int numbytes)
Read a continuous block or 'blob' of bytes from the input stream. Quantity as specified as the first argument.

Parameters:
integer - number of bytes expected to comprise the blob to be read from inout stream
Returns:
char[] that contains the blob of characters.

printDebugString

protected void printDebugString(java.lang.String msg,
                                int loggerDisplayLevel)