This tutorial results from the official leJos web site.
You can use your PC as a remote console to display tracing statements generated your NXJ program. The lejos.nxt.comm.RConsole class has methods to it. Since there are no instances of this class, all methods are static.
To start debugging, you use one of these methods:
- void open() : opens a USB connection with no timeout
- void openUSB(int timeout)
- void openBluetooth(int timeout)
The NXT displays USB Console.. or BT Console and waits for the PC based monitor to connect.
Then execute the nxjconsole program on your PC. When the connection is established, the NXT displays Got Connection and, after some seconds, both the NXT and the PC display Console open.
If you use the variant of open with a timeout, it waits the specified number of seconds and if the debug monitor has not connected, proceeds without debugging. If the timeout is zero, it waits indefinitely.
Debug statements can be output using one of the methods:
- void println(String s)
- void print(String s);
If no successful open statement has been executed, the debug output is discarded. If there was a successful output, the string appears on standard out in the window or terminal that nxjconsole was run from, on the PC.
When debugging is completed, you should call:
- void close()
This closes the USB or Bluetooth connection.
For example :
import lejos.nxt.*; import lejos.nxt.comm.*; /** * example using RConsole*/ public class TestRConsole { USB.usbEnable(0x2); while (!RConsole.isOpen()){ RConsole.open(); } RConsole.println("Start for loop "); for (int i = 0; i < 5; i++) { RConsole.print(" " + i); LCD.drawInt(i, 2, 2 * i, 4); } RConsole.println("\n done "); RConsole.close(); } }