|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--rcxport.RCXPort
Top-level interface to the RCX. This is the top-level interface for interacting with the Lego Mindstorms Robotics Kit RCX. It uses the communication protocol described and documented in the RCX Internals web page. The primary method for sending RCX byte codes to the RCX is the downloadProgram method in this class.
| Field Summary | |
static byte |
DEFAULTRETRYCOUNT
|
static byte |
DOWNLOAD_SOUND
|
static byte |
DOWNLOADCHUNK
|
static String |
FILE_DELIMITERS
|
static int |
FILE_RADIX
|
static int |
INSBUFF
|
static int |
OUTBUFF
|
static int |
PORTOPENTIMEOUT
|
static int |
PORTREADTIMEOUT
|
static String |
RCXPORTNAME
|
| Constructor Summary | |
RCXPort(String port)
Create an interface to the RCX. |
|
| Method Summary | |
void |
close()
Close interaction with this port. |
void |
deleteSubs()
|
void |
deleteTasks()
|
void |
downloadFragment(boolean type,
byte num,
byte[] data)
|
void |
downloadProgram(RCXProgram aProg,
boolean run)
Download given program and optionally run it. |
byte[] |
getByteCodesFromReader(BufferedReader r)
Get byte codes from a BufferedReader. |
byte[] |
getByteCodesFromString(String aString,
String delimiters,
int radix)
Create byte array from string of byte codes. |
String |
getPortName()
Get port name. |
protected String |
loadStringFromFile(BufferedReader r)
|
static void |
main(String[] args)
Test program for Java code to communicate with the Lego Mindstorms RCX. |
void |
ping()
|
void |
playSound(byte sound)
|
void |
selectProgram(byte prog)
|
RCXResult |
sendData(byte[] data)
Alternative to sendData/2 that has a retry by default. |
RCXResult |
sendData(byte[] data,
boolean retry)
Send data to the RCX, and get an RCXResult back. |
void |
startTask(byte task)
|
void |
stopTask(byte task)
|
void |
sync()
|
(package private) static void |
usage()
|
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final int INSBUFF
public static final int OUTBUFF
public static final String RCXPORTNAME
public static final int PORTOPENTIMEOUT
public static final int PORTREADTIMEOUT
public static final String FILE_DELIMITERS
public static final int FILE_RADIX
public static final byte DOWNLOADCHUNK
public static final byte DEFAULTRETRYCOUNT
public static final byte DOWNLOAD_SOUND
| Constructor Detail |
public RCXPort(String port)
throws Exception
port - the name of the system port to use. This name will be system
dependent (e.g. "COM1").| Method Detail |
public RCXResult sendData(byte[] data,
boolean retry)
throws IOException
data - the byte array to send. Must not be null and should have length longer than 0.
public RCXResult sendData(byte[] data)
throws IOException
data - the data to sendpublic String getPortName()
public void close()
public void sync()
throws IOException
public void ping()
throws IOException
public void deleteSubs()
throws IOException
public void deleteTasks()
throws IOException
public void selectProgram(byte prog)
throws IOException
public void playSound(byte sound)
throws IOException
public void downloadProgram(RCXProgram aProg,
boolean run)
throws IOException
aProg - the RCXProgram to download to the RCX.run - if true, immediately run the downloaded program. If false, just
do the download
public void startTask(byte task)
throws IOException
public void stopTask(byte task)
throws IOException
public void downloadFragment(boolean type,
byte num,
byte[] data)
throws IOException
public byte[] getByteCodesFromReader(BufferedReader r)
throws IOException
r - the BufferedReader to read from
public byte[] getByteCodesFromString(String aString,
String delimiters,
int radix)
aString - the string to read. Must not be null.delimiters - the delimiters used by the StringTokenizer to parse the given String.radix - the radix of the numbers given in the first parameter.
protected String loadStringFromFile(BufferedReader r)
throws IOException
public static void main(String[] args)
throws Exception
Usage: java rcxport.RCXPort -p <comm port> -n <prog num> [-f <filename>] | [-raw <byte codes>]
Options:
-p: serial port (e.g. COM1). Defaults to COM1.
-n: RCX program number (in range 1-5 inclusive). Defaults to 5.
-f: file of byte codes to read. In hex.
-raw: raw byte codes to send to RCX (e.g. 51 3). In hex.
Either the -f param or the -raw param should be provided. If the -f parameter is specified, the file is read for byte codes (in hex). If -raw is specified, byte codes are specified directly on the command line (also in hex):
java rcxport.RCXPort -p COM1 -n 1 -f filename.lis
to read the byte codes from filename.lis, or
java rcxport.RCXPort -p COM1 -n 1 -raw 51 3
to send 51 3 (play sound '3') to the RCX.
static void usage()
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||