I am trying to contorl the nxt remotely via Bluetooth from my java application.
I made a simple application that move motor A forward for a second then stops it
- Code: Select all
import lejos.nxt.Motor;
private void jBtnNXTForward(java.awt.event.ActionEvent evt) {
Motor.A.forward();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
Motor.A.stop();
}
The problem is If I restarted the nxt and pressed the forwatd button again. It doesn't work, The first press doesn't work and doesn't show any error , starting from the second press I get the error message
Failed to write; [10053] An established connection was aborted by the software in your host machine.
I tried to use a connect function before Motor.A.forward(); command, to connect if the nxt isn't connected, but it didn't help. It shows that the nxt is already connected
The connect function:
- Code: Select all
public static void Connect () throws Exception {
NXTCommand singleton = NXTCommand.getSingleton();
if (!singleton.isOpen()) {
try {
NXTComm nxtComm = NXTCommandConnector.open();
if (nxtComm == null)
{
System.out.println("nxtcomm is null");
throw new IOException();
}
singleton.setNXTComm(nxtComm);
} catch (IOException ioe)
{
System.err.println("Failed to open connection to the NXT");
}
}
else
System.err.println("The connection is already open....");
}
I have to close my java application and open it again to start working. Is there something missing in my code ?
Thanks in advance
