Hello again,
I've tried using my understanding of what you are suggesting, and am not able to tell the Main Menu apart from another program, even using the latest snapshot. What I understood from your reply is that when I am performing a read command (such as NXTCommand messageRead()), I should get an error code from the Main Menu, but not from a running program. (It is altogether possible that I misunderstood).
What I find instead is that I get the LCPExcption "protocol error" when there is no data to be read, with the snapshot, and, with leJOS 0.9.1, I get a message length of 0 and no exception. For a given version of leJOS, I get the same output regardless of if the NXT is running my program or the Main Menu.
Here is my test application, MainMenuProbe.java:
- Code: Select all
import java.io.*;
import lejos.nxt.remote.*;
import lejos.pc.comm.*;
// The purpose of this application is to determine if the Main Menu application is running.
public class MainMenuProbe {
private String nxtname = "";
private String address = "";
private int protocols = NXTCommFactory.USB; // | NXTCommFactory.BLUETOOTH;
private NXTCommand nxtcommand;
private NXTConnector nxtconnector = new NXTConnector();
public void delay(int ms) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// we are unlikely to be interrupted
throw new RuntimeException(e);
}
}
MainMenuProbe() {
while (true) {
// Connect to an NXT
boolean connected = false;
System.out.print("Connecting");
while (!connected) {
delay(500);
System.out.print(".");
try {
connected = nxtconnector.connectTo(nxtname, address, protocols);
} catch (java.lang.RuntimeException e) {
System.out.println("\nRuntimeException occurred while trying to connect to NXT: " + e.getMessage());
}
}
System.out.println(" Connected.");
nxtcommand = new NXTCommand(nxtconnector.getNXTComm());
try {
System.out.println(" Connected to NXT running v" + nxtcommand.getNXJFirmwareVersion());
} catch (IOException e) { }
// Communicate with the NXT until we are disconnected
try {
System.out.print("Reading data: ");
while (true) {
byte [] message;
try {
message = nxtcommand.messageRead((byte) 0, (byte) 0, true);
} catch (LCPException e) {
if (e.getMessage() == "protocol error") {
System.out.println("No data ready.");
delay(500);
continue;
} else {
throw e;
}
}
System.out.printf("%d, ", message.length);
delay(500);
}
} catch (IOException e) {
System.out.println("\nIOException occurred while reading messages: " + e.getMessage());
}
System.out.println("\nDisconnected.");
try {
nxtcommand.disconnect();
nxtconnector.close();
} catch (IOException e) {}
}
}
public static void main(String[] args) {
new MainMenuProbe();
}
}
I compile and run it thusly:
- Code: Select all
nxjpcc MainMenuProbe.java && nxjpc MainMenuProbe
Here are the results, using the latest snapshot, connecting to the NXT running the Main Menu, and then disconnecting, after a while:
Connecting..................................Found NXT: NXT 00165313C275
Connected.
Connected to NXT running v0.9.1(6817)
Reading data: No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
IOException occurred while reading messages: Error in write: -1073807194
Disconnected.
Connecting.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
and when connecting to an Enchanting application running on the NXT:
Connecting.......Found NXT: NXT 00165313C275
Connected.
Connected to NXT running v0.9.1(6817)
Reading data: No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
No data ready.
IOException occurred while reading messages: Error in write: -1073807194
Disconnected.
Connecting.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
Here are the results when using leJOS 0.9.1 (well, it is slightly modified, but much closer to 0.9.1), and connecting to the main menu:
Connecting..........Found NXT: NXT 00165313C275
Connected.
Connected to NXT running v0.9.1(6595)
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Error in write
Disconnected.
Connecting.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
and when connecting to an Enchanting application on the NXT:
Connecting............Found NXT: NXT 00165313C275
Connected.
Connected to NXT running v0.9.1(6595)
Reading data: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
IOException occurred while reading messages: Error in write
Disconnected.
Connecting.
RuntimeException occurred while trying to connect to NXT: already connected
.
RuntimeException occurred while trying to connect to NXT: already connected
.
I'm afraid I don't see any difference between connecting to the Main Menu or to my application.
Cheers,
Clinton