org.robokind.impl.motion.serial
Class RXTXSerialPort

java.lang.Object
  extended by org.robokind.api.common.property.PropertyChangeNotifier
      extended by org.robokind.impl.motion.serial.RXTXSerialPort
All Implemented Interfaces:
org.robokind.api.common.property.PropertyChangeSource

public class RXTXSerialPort
extends org.robokind.api.common.property.PropertyChangeNotifier

A SerialPort using the RXTX library. This class is not thread safe.

Author:
Matthew Stevenson

Field Summary
static String DEVICE_ERROR
          Device Error error string.
static String INVALID_PORT_ERROR
          Invalid Port error string.
static String PORT_IN_USE_ERROR
          Port In Use error string.
static String PORT_NOT_FOUND_ERROR
          Port Not Found error string.
static String PROP_ERRORS
          Property string for RXTXSerialPort Errors.
static String READ_ERROR
          Port Read Error error string.
static String TIMEOUT_ERROR
          Timeout error string.
static String WRITE_ERROR
          Port Write Error error string.
 
Constructor Summary
RXTXSerialPort(String portName)
          Creates a new RXTXSerialPort using the given port.
 
Method Summary
protected  void addError(String error)
          Adds an error to the RXTXSerialPort.
protected  void addError(String error, String message)
          Adds an error to the RXTXSerialPort.
 void addError(String error, String message, Throwable t)
          Adds an error to the RXTXSerialPort.
protected  void addError(String error, Throwable t)
          Adds an error to the RXTXSerialPort.
 void clearErrors()
          Clears all port errors.
 void clearReader()
          Clears any available data from the port reader.
 boolean connect(int baudRate, int dataBtis, int stopBits, int parity)
          Connects to the serial port using the given parameters.
 boolean disconnect()
          Disconnect the serial port.
 boolean flushWriter()
          Flushes the serial port's OutputStream.
 org.robokind.api.motion.servos.utils.ConnectionStatus getConnectionStatus()
          Returns the port's ConnectionStatus.
 List<String> getErrors()
          Returns a List of the port's errors.
 gnu.io.SerialPort getPort()
          Returns underlying SerialPort.
 InputStream getReader()
          Returns underlying InputStream.
 int getTimeoutLength()
          Returns port timeout length.
 OutputStream getWriter()
          Returns underlying OutputStream.
 boolean hasErrors()
          Returns true if the port has errors.
 int read()
          Reads a single byte.
 int read(byte[] data, int offset, int len)
          Reads a number of bytes from the serial port.
 byte[] read(int len)
          Reads a number of bytes from the serial port.
 void setTimeoutLength(int len)
          Sets the timeout length.
 boolean write(byte... data)
          Writes the data to the serial port.
 boolean write(byte[] data, int offset, int len)
          Writes the data to the serial port.
 
Methods inherited from class org.robokind.api.common.property.PropertyChangeNotifier
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_ERRORS

public static final String PROP_ERRORS
Property string for RXTXSerialPort Errors.

See Also:
Constant Field Values

TIMEOUT_ERROR

public static final String TIMEOUT_ERROR
Timeout error string.

See Also:
Constant Field Values

PORT_NOT_FOUND_ERROR

public static final String PORT_NOT_FOUND_ERROR
Port Not Found error string.

See Also:
Constant Field Values

PORT_IN_USE_ERROR

public static final String PORT_IN_USE_ERROR
Port In Use error string.

See Also:
Constant Field Values

INVALID_PORT_ERROR

public static final String INVALID_PORT_ERROR
Invalid Port error string.

See Also:
Constant Field Values

READ_ERROR

public static final String READ_ERROR
Port Read Error error string.

See Also:
Constant Field Values

WRITE_ERROR

public static final String WRITE_ERROR
Port Write Error error string.

See Also:
Constant Field Values

DEVICE_ERROR

public static final String DEVICE_ERROR
Device Error error string.

See Also:
Constant Field Values
Constructor Detail

RXTXSerialPort

public RXTXSerialPort(String portName)
Creates a new RXTXSerialPort using the given port.

Parameters:
portName - port identifier
Method Detail

setTimeoutLength

public void setTimeoutLength(int len)
Sets the timeout length.

Parameters:
len - timeout length in milliseconds

getTimeoutLength

public int getTimeoutLength()
Returns port timeout length.

Returns:
port timeout length

getPort

public gnu.io.SerialPort getPort()
Returns underlying SerialPort.

Returns:
underlying SerialPort

getWriter

public OutputStream getWriter()
Returns underlying OutputStream.

Returns:
underlying OutputStream

getReader

public InputStream getReader()
Returns underlying InputStream.

Returns:
underlying InputStream

connect

public boolean connect(int baudRate,
                       int dataBtis,
                       int stopBits,
                       int parity)
Connects to the serial port using the given parameters.

Parameters:
baudRate - port baud rate
dataBtis - number of data bits
stopBits - number of stop bits
parity - parity
Returns:
true is successful

disconnect

public boolean disconnect()
Disconnect the serial port.

Returns:
true if successful

write

public boolean write(byte[] data,
                     int offset,
                     int len)
Writes the data to the serial port.

Parameters:
data - bytes to write
offset - data array offset
len - data write length
Returns:
true if successful

write

public boolean write(byte... data)
Writes the data to the serial port.

Parameters:
data - bytes to write
Returns:
true if successful

flushWriter

public boolean flushWriter()
Flushes the serial port's OutputStream.

Returns:
true if flush is successful

read

public byte[] read(int len)
Reads a number of bytes from the serial port.

Parameters:
len - number of bytes to read
Returns:
array of bytes read from the serial port

read

public int read(byte[] data,
                int offset,
                int len)
Reads a number of bytes from the serial port.

Parameters:
data - array to fill
offset - data array offset
len - number of bytes to read
Returns:
number of bytes read from the serial port

read

public int read()
Reads a single byte.

Returns:
a single unsigned byte. Returns -1 if no data or an error is encountered

clearReader

public void clearReader()
Clears any available data from the port reader.


getConnectionStatus

public org.robokind.api.motion.servos.utils.ConnectionStatus getConnectionStatus()
Returns the port's ConnectionStatus.

Returns:
port's ConnectionStatus

addError

protected void addError(String error)
Adds an error to the RXTXSerialPort.

Parameters:
error - error string to add

addError

protected void addError(String error,
                        String message)
Adds an error to the RXTXSerialPort.

Parameters:
error - error string to add
message - error message

addError

protected void addError(String error,
                        Throwable t)
Adds an error to the RXTXSerialPort.

Parameters:
error - error string to add
t - error Throwable

addError

public void addError(String error,
                     String message,
                     Throwable t)
Adds an error to the RXTXSerialPort.

Parameters:
error - error string to add
message - error message
t - error Throwable

getErrors

public List<String> getErrors()
Returns a List of the port's errors.

Returns:
List of the port's errors

clearErrors

public void clearErrors()
Clears all port errors.


hasErrors

public boolean hasErrors()
Returns true if the port has errors.

Returns:
true if the port has errors


Copyright © 2011. All Rights Reserved.