rcx
Class RCXPort

java.lang.Object
  |
  +--rcx.RCXPort

public class RCXPort
extends java.lang.Object

RCXPort - Encapsulates and manages communications to and from the RCX


Field Summary
static boolean debug
          used to display debugging messages
 boolean isEmulation
          used to indicate emulation mode
static boolean skipalive
          used to skip sending the initial alive message
 
Constructor Summary
RCXPort()
          creates the port and calls init(null)
RCXPort(java.lang.String portname)
          creates the port and calls init(portname)
 
Method Summary
 void addAllMessagesListener(AllMessagesListener rl)
          adds an AllMessagesListener
 void addRCXErrorListener(RCXErrorListener rl)
          adds an RCXErrorListener
 void addRCXListener(RCXListener rl)
          adds an RCXListener
 void alive()
          sends an alive message to the RCX
static java.lang.String ArrayToString(byte[] message, int length)
          utility to return a string representation of an array or first part of an array (given a length)
 void beep()
          play system sound (0)
 void beepSequence()
          plays system sound (2)
 void beepSequenceUp()
          plays system sound (3)
 void buzz()
          plays system sound (4)
 void close()
          closes the streams and the port
 void controlMotor(char id, short mode, short power)
           
 float getBatteryPower()
          gets the battery power level in volts
 java.io.InputStream getInputStream()
          gets the InputStream
 java.lang.String getLastError()
          retrieves the last error that occurred
 int getLastValue()
          returns the return value of the last message processed (if it returned a value)
 java.io.OutputStream getOutputStream()
          gets the OutputStream
 void init(java.lang.String port)
          creates an instance of RCXOpcode for looking up opcodes, creates the static instances of Motor and Sensor, and calls open(port)
protected  void initPort()
          creates an instance of the RCXCommPort: RCXUSBPort, RCXSocketPort or RCXSerialPort
 boolean isOpen()
          tests to see if port already opened
 boolean open()
          actually opens the port and obtains the output and input streams
 void open(java.lang.String port)
          determines the type of port from the port name
(if null will find first available serial port
 void playTone(int frequency, int duration)
          Plays a tone, given its frequency and duration.
 void processMessage(byte[] message)
          processes messages by converting return values and storing the return value internally until retrieved by getLastValue()
 int readSensorValue(int sensorId, int requestType)
           
 boolean send(java.lang.String packet)
          converts string to byte array and send it to RCX
 void setDebug(boolean set)
          sets debug mode on or off
 void setError(java.lang.String msg)
          sets error message and sends it to the errorListener
 void setOpen(boolean set)
          used to overide the port open status (for example, mark as closed when errors occur)
 void setSensorValue(int sensorId, int val, int requestType)
          sets the sensorID value and type (if in emulation mode, sets the value to be read)
 void setStreams(java.io.InputStream in, java.io.OutputStream out)
          sets the streams to swap and creates an instance (thread) of StreamSwap
 void systemSound(boolean queued, int code)
          plays a system sound (0-5)
0:Blip 1:Beep beep 2:Downward tones 3:Upward tones 4:Low buzz 5:Fast upward tones
(note: queued not applied here - used just for compatiblity with leJOS)
 void twoBeeps()
          plays system sound (1)
 void upwardTones()
          plays system sound (5)
 boolean write(byte[] bArray)
          writes a byte array to the RCX port
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
used to display debugging messages


isEmulation

public boolean isEmulation
used to indicate emulation mode


skipalive

public static boolean skipalive
used to skip sending the initial alive message

Constructor Detail

RCXPort

public RCXPort()
creates the port and calls init(null)


RCXPort

public RCXPort(java.lang.String portname)
creates the port and calls init(portname)

Method Detail

addAllMessagesListener

public void addAllMessagesListener(AllMessagesListener rl)
adds an AllMessagesListener


addRCXErrorListener

public void addRCXErrorListener(RCXErrorListener rl)
adds an RCXErrorListener


addRCXListener

public void addRCXListener(RCXListener rl)
adds an RCXListener


alive

public void alive()
sends an alive message to the RCX


ArrayToString

public static java.lang.String ArrayToString(byte[] message,
                                             int length)
utility to return a string representation of an array or first part of an array (given a length)


beep

public void beep()
play system sound (0)


beepSequence

public void beepSequence()
plays system sound (2)


beepSequenceUp

public void beepSequenceUp()
plays system sound (3)


buzz

public void buzz()
plays system sound (4)


close

public void close()
closes the streams and the port


controlMotor

public void controlMotor(char id,
                         short mode,
                         short power)

getBatteryPower

public float getBatteryPower()
gets the battery power level in volts


getInputStream

public java.io.InputStream getInputStream()
gets the InputStream


getLastError

public java.lang.String getLastError()
retrieves the last error that occurred


getLastValue

public int getLastValue()
returns the return value of the last message processed (if it returned a value)


getOutputStream

public java.io.OutputStream getOutputStream()
gets the OutputStream


init

public void init(java.lang.String port)
creates an instance of RCXOpcode for looking up opcodes, creates the static instances of Motor and Sensor, and calls open(port)


initPort

protected void initPort()
creates an instance of the RCXCommPort: RCXUSBPort, RCXSocketPort or RCXSerialPort


isOpen

public boolean isOpen()
tests to see if port already opened


open

public boolean open()
actually opens the port and obtains the output and input streams


open

public void open(java.lang.String port)
determines the type of port from the port name
(if null will find first available serial port


playTone

public void playTone(int frequency,
                     int duration)
Plays a tone, given its frequency and duration. Frequency is audible from about 31 to 2100 Hertz. The duration argument is in hundreds of a seconds and is truncated at 256, so the maximum duration of a tone is 2.56 seconds.


processMessage

public void processMessage(byte[] message)
processes messages by converting return values and storing the return value internally until retrieved by getLastValue()


readSensorValue

public int readSensorValue(int sensorId,
                           int requestType)
Parameters:
sensorId - Sensor ID (0..2).
requestType - 0 = raw value, 1 = canonical value, 2 = boolean value.

send

public boolean send(java.lang.String packet)
converts string to byte array and send it to RCX


setDebug

public void setDebug(boolean set)
sets debug mode on or off


setError

public void setError(java.lang.String msg)
sets error message and sends it to the errorListener

See Also:
RCXErrorListener

setOpen

public void setOpen(boolean set)
used to overide the port open status (for example, mark as closed when errors occur)


setSensorValue

public void setSensorValue(int sensorId,
                           int val,
                           int requestType)
sets the sensorID value and type (if in emulation mode, sets the value to be read)

See Also:
Sensor, SensorConstants

setStreams

public void setStreams(java.io.InputStream in,
                       java.io.OutputStream out)
sets the streams to swap and creates an instance (thread) of StreamSwap

See Also:
RCXServer

systemSound

public void systemSound(boolean queued,
                        int code)
plays a system sound (0-5)
0:Blip 1:Beep beep 2:Downward tones 3:Upward tones 4:Low buzz 5:Fast upward tones
(note: queued not applied here - used just for compatiblity with leJOS)


twoBeeps

public void twoBeeps()
plays system sound (1)


upwardTones

public void upwardTones()
plays system sound (5)


write

public boolean write(byte[] bArray)
writes a byte array to the RCX port



Copyright 1998-2002 dario laverde