lejos.nxt.comm
Class RConsole

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.nxt.comm.RConsole
All Implemented Interfaces:
Runnable

public class RConsole
extends Thread

This class provides a simple way of sending output for viewing on a PC. The output is transmitted via the nxt USB connection or via Bluetooth. If open is not called or if the connection to the PC is timed out, then the output is discarded. The class may also be used to provide a remote view of the NXT LCD display, and to capture various debug events. The use of these facilities requires corresponding capabilities within the remote viewer and is negotiated at connection time. Use of this class is normally initiated in two ways:
1. Explicit usage. The user program makes a call to one of the open methods and than uses the RConsole.println method to display output.
2. Implicit usage. In this mode the -gr (--remotedebug) is specified to the leJOS linker and this arranges to start the user program via this class. This class then hooks any required debug events, waits for a remote viewer to connect (via either Bluetooth or USB), and then routes the standard system output and err print streams to the remote display.


Nested Class Summary
static class RConsole.Monitor
          The following internal class provides an implicit remote console and also hooks into the debug event system.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static void close()
          Close the remote console connection.
static boolean exception(int classNo, int methodNo, int pc, int[] stackTrace, String msg)
          Send an exception event to the remote console.
static PrintStream getPrintStream()
          Return a print stream connected to the remote console.
static boolean isOpen()
          Check to see if the remote console is available for use.
static void open()
          Wait forever for a remote viewer to connect.
static void openAny(int timeout)
          Wait for a remote viewer to connect using either USB or Bluetooth.
static void openBluetooth(int timeout)
          Wait for a remote viewer to connect via Bluetooth.
static void openUSB(int timeout)
          Wait for a remote viewer to connect via USB.
static void print(String s)
          Send output to the remote viewer.
static void println(String s)
          Send a line to the remote viewer.
 void run()
          Main console I/O thread.
 
Methods inherited from class java.lang.Thread
currentThread, getDefaultUncaughtExceptionHandler, getName, getPriority, getUncaughtExceptionHandler, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, start, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openUSB

public static void openUSB(int timeout)
Wait for a remote viewer to connect via USB.

Parameters:
timeout - how long to wait, 0 waits for ever.

openBluetooth

public static void openBluetooth(int timeout)
Wait for a remote viewer to connect via Bluetooth.

Parameters:
timeout - how long to wait, 0 waits for ever.

openAny

public static void openAny(int timeout)
Wait for a remote viewer to connect using either USB or Bluetooth.

Parameters:
timeout - time to wait for the connection, 0 waits for ever.

open

public static void open()
Wait forever for a remote viewer to connect.


print

public static void print(String s)
Send output to the remote viewer.

Parameters:
s -

println

public static void println(String s)
Send a line to the remote viewer.

Parameters:
s -

close

public static void close()
Close the remote console connection.


isOpen

public static boolean isOpen()
Check to see if the remote console is available for use.

Returns:
true if the console is open.

getPrintStream

public static PrintStream getPrintStream()
Return a print stream connected to the remote console.

Returns:
the print stream

run

public void run()
Main console I/O thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

exception

public static boolean exception(int classNo,
                                int methodNo,
                                int pc,
                                int[] stackTrace,
                                String msg)
Send an exception event to the remote console.

Parameters:
classNo - The exception class.
methodNo - The method in which the exception occurred.
pc - The location of the exception.
stackTrace - An internal stack trace.
msg - A text message associated with the exception.
Returns:
True if OK.