Skip to main content

Remote debugging

Posted in

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 :

 

  1.  
  2. import lejos.nxt.*;
  3. import lejos.nxt.comm.*;
  4.  
  5. /**
  6. * example using RConsole*/
  7. public class TestRConsole {
  8. public static void main(String[] args) {
  9. USB.usbEnable(0x2);
  10. while (!RConsole.isOpen()){
  11. RConsole.open();
  12. }
  13.  
  14. RConsole.println("Start for loop ");
  15. for (int i = 0; i < 5; i++) {
  16. RConsole.print(" " + i);
  17. LCD.drawInt(i, 2, 2 * i, 4);
  18. }
  19. RConsole.println("\n done ");
  20. RConsole.close();
  21. Button.waitForPress();
  22. }
  23. }