roombacomm
Class RoombaCommSerial

java.lang.Object
  extended by roombacomm.RoombaComm
      extended by roombacomm.RoombaCommSerial
All Implemented Interfaces:
gnu.io.SerialPortEventListener, java.util.EventListener

public class RoombaCommSerial
extends RoombaComm
implements gnu.io.SerialPortEventListener

The serial-port based implementation of RoombaComm. Handles both physical RS-232 ports, USB adapter ports like Keyspan USA-19HS, and Bluetooth serial port profiles.

Some code taken from processing.serial.Serial. Thanks guys!


Field Summary
 boolean flushOutput
          RXTX bombs when flushing output sometimes, so by default do not flush the output stream.
 java.io.InputStream input
          the serial input stream, normally you don't need access to this
 java.io.OutputStream output
          the serial output stream, normally you don't need access to this
 gnu.io.SerialPort port
          The RXTX port object, normally you don't need access to this
static int updateSensorsPause
          The time to wait in milliseconds after sending sensors command before attempting to read
 boolean waitForDSR
          Some "virtual" serial ports like Bluetooth serial on Windows return weird errors deep inside RXTX if an opened port is used before the virtual COM port is ready.
 
Fields inherited from class roombacomm.RoombaComm
debug, defaultSensorsUpdateTime, defaultSpeed, millimetersPerDegree, millimetersPerRadian, speed, VERSION, wheelbase
 
Constructor Summary
RoombaCommSerial()
           
RoombaCommSerial(boolean autoupdate)
           
RoombaCommSerial(boolean autoupdate, int updateTime)
           
 
Method Summary
 void computeSensors()
          called by serialEvent when we have enough bytes to make sensors valid
 boolean connect(java.lang.String portid)
          Connect to a serial port specified by portid doesn't guarantee connection to Roomba, just to serial port
 void disconnect()
          Disconnect from serial port
static boolean isPortInUse(java.lang.String pname)
          Let you check to see if a port is in use by another Rooomba before trying to use it.
 java.lang.String[] listPorts()
          If this just hangs and never completes on Windows, it may be because the DLL doesn't have its exec bit set.
 boolean send(byte[] bytes)
          subclassed.
 boolean send(int b)
          This will handle both ints, bytes and chars transparently.
 void serialEvent(gnu.io.SerialPortEvent serialEvent)
          callback for SerialPortEventListener (from processing.serial.Serial)
 boolean updateSensors()
          Update sensors.
 void wakeup()
          toggles DD line via serial port DTR (if available)
 
Methods inherited from class roombacomm.RoombaComm
angle, angleInDegrees, angleInRadians, binary, bump, bumpLeft, bumpRight, bumps_wheeldrops, buttons, capacity, charge, charging_state, clean, cleanButton, cliff_frontleft, cliff_frontright, cliff_left, cliff_right, cliffFrontLeft, cliffFrontRight, cliffLeft, cliffRight, computeSafetyFault, connected, control, createSong, createSong, current, delay, dirt_left, dirt_right, dirt, dirtLeft, dirtRight, distance, drive, errorMessage, full, getSpeed, goBackward, goBackward, goBackwardAt, goForward, goForward, goForwardAt, goStraight, goStraightAt, hex, hex, logmsg, max, maxButton, mode, modeAsString, motor_overcurrents, motorOvercurrentDriveLeft, motorOvercurrentDriveRight, motorOvercurrentMainBrush, motorOvercurrentSideBrush, motorOvercurrentVacuum, pause, playNote, playSong, powerButton, powerOff, println, remote_opcode, reset, safe, safetyFault, sensors, sensors, sensorsAsString, sensorsAutoUpdate, sensorsUpdateTime, sensorsValid, setLEDs, setMotors, setSensorsAutoUpdate, setSensorsUpdateTime, setSpeed, spin, spinLeft, spinLeft, spinLeftAt, spinRight, spinRight, spinRightAt, spot, spotButton, start, startAutoUpdate, startup, stop, temperature, toShort, toUnsignedShort, turn, turnLeft, turnRight, vacuum, virtual_wall, voltage, wall, wheelDropCenter, wheelDropLeft, wheelDropRight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

updateSensorsPause

public static int updateSensorsPause
The time to wait in milliseconds after sending sensors command before attempting to read


port

public gnu.io.SerialPort port
The RXTX port object, normally you don't need access to this


input

public java.io.InputStream input
the serial input stream, normally you don't need access to this


output

public java.io.OutputStream output
the serial output stream, normally you don't need access to this


flushOutput

public boolean flushOutput
RXTX bombs when flushing output sometimes, so by default do not flush the output stream. If the output is too buffered to be useful, do: roombacomm.comm.flushOutput = true; before using it and see if it works.


waitForDSR

public boolean waitForDSR
Some "virtual" serial ports like Bluetooth serial on Windows return weird errors deep inside RXTX if an opened port is used before the virtual COM port is ready. One way to check that it is ready is to look for the DSR line going high. However, most simple, real serial ports do not do hardware handshaking so never set DSR high. Thus, if using Bluetooth serial on Windows, do: roombacomm.waitForDSR = true; before using it and see if it works.

Constructor Detail

RoombaCommSerial

public RoombaCommSerial()

RoombaCommSerial

public RoombaCommSerial(boolean autoupdate)

RoombaCommSerial

public RoombaCommSerial(boolean autoupdate,
                        int updateTime)
Method Detail

isPortInUse

public static boolean isPortInUse(java.lang.String pname)
Let you check to see if a port is in use by another Rooomba before trying to use it.


connect

public boolean connect(java.lang.String portid)
Connect to a serial port specified by portid doesn't guarantee connection to Roomba, just to serial port

Specified by:
connect in class RoombaComm
Parameters:
portid - name of port, e.g. "/dev/cu.KeySerial1" or "COM3"
Returns:
true if connect was successful, false otherwise

disconnect

public void disconnect()
Disconnect from serial port

Specified by:
disconnect in class RoombaComm

send

public boolean send(byte[] bytes)
subclassed. FIXME:

Specified by:
send in class RoombaComm
Parameters:
bytes - byte array of SCI commands to send
Returns:
true on successful send

send

public boolean send(int b)
This will handle both ints, bytes and chars transparently.

Specified by:
send in class RoombaComm
Parameters:
b - byte of an SCI command to send
Returns:
true on successful send

wakeup

public void wakeup()
toggles DD line via serial port DTR (if available)

Overrides:
wakeup in class RoombaComm

updateSensors

public boolean updateSensors()
Update sensors. Block for up to 1000 ms waiting for update To use non-blocking, call sensors() and then poll sensorsValid()

Specified by:
updateSensors in class RoombaComm
Returns:
true on successful sensor update, false otherwise

computeSensors

public void computeSensors()
called by serialEvent when we have enough bytes to make sensors valid


listPorts

public java.lang.String[] listPorts()
If this just hangs and never completes on Windows, it may be because the DLL doesn't have its exec bit set. Why the hell that'd be the case, who knows. FIXME: deal more gracefully (from processing.serial.Serial)

Specified by:
listPorts in class RoombaComm
Returns:
a list available portids, if applicable or empty set if no ports, or return null if list is not enumerable

serialEvent

public void serialEvent(gnu.io.SerialPortEvent serialEvent)
callback for SerialPortEventListener (from processing.serial.Serial)

Specified by:
serialEvent in interface gnu.io.SerialPortEventListener