|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrcx.RCXPort
public class RCXPort
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) |
boolean |
isOpen()
tests to see if port already opened |
static void |
main(java.lang.String[] args)
|
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)
My new simple write! |
boolean |
writeOrig(byte[] bArray)
writes a byte array to the RCX port |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean debug
public static boolean skipalive
public boolean isEmulation
Constructor Detail |
---|
public RCXPort()
public RCXPort(java.lang.String portname)
Method Detail |
---|
public void init(java.lang.String port)
public void addRCXListener(RCXListener rl)
public void addAllMessagesListener(AllMessagesListener rl)
public void addRCXErrorListener(RCXErrorListener rl)
public void setDebug(boolean set)
public void open(java.lang.String port)
public void alive()
public boolean open()
public void close()
public boolean isOpen()
public void setOpen(boolean set)
public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public void setStreams(java.io.InputStream in, java.io.OutputStream out)
RCXServer
public boolean write(byte[] bArray)
bArray
-
public boolean writeOrig(byte[] bArray)
public boolean send(java.lang.String packet)
public java.lang.String getLastError()
public int getLastValue()
public static java.lang.String ArrayToString(byte[] message, int length)
public void processMessage(byte[] message)
public void setError(java.lang.String msg)
RCXErrorListener
public void beep()
public void twoBeeps()
public void beepSequence()
public void beepSequenceUp()
public void buzz()
public void upwardTones()
public void systemSound(boolean queued, int code)
public void playTone(int frequency, int duration)
frequency
- The frequency of the tone in Hertz (Hz).duration
- The duration of the tone, in centiseconds.
Value is truncated at 256 centiseconds.public void controlMotor(char id, short mode, short power)
id
- 'A', 'B' or 'C'.mode
- 1=forward, 2=backward, 3=stop, 4=floatpower
- 0-7public int readSensorValue(int sensorId, int requestType)
sensorId
- Sensor ID (0..2).requestType
- 0 = raw value, 1 = canonical value, 2 = boolean value.public void setSensorValue(int sensorId, int val, int requestType)
Sensor
,
SensorConstants
public float getBatteryPower()
public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
java.lang.InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |