the problem I am facing is time it takes for connection , when I run the program multiple times, sometimes it takes only 2 seconds to connect, other times it takes up to 25 seconds.
I don't know where is the problem, and is there any factors or properties I should consider in the program to speed up the connection time ?
I am using leJOS 0.9 , and I running under windows 7, I am using netbeans jdk 1.7.0
Here is my sample code :
nxt program :
- Code: Select all
import lejos.nxt.*;
import lejos.nxt.comm.*;
import java.io.*;
import java.net.*;
public class program extends BaseClass {
public static void main(String[] args) throws Exception {
BTConnection conn = Bluetooth.waitForConnection();
Beep();// function in the BaseClass
for ( int count0 =0 ;count0< 10 ;count0++)
{
Backward();// function in the BaseClass
}
}
}
pc program :
- Code: Select all
import lejos.pc.comm.*;
import java.io.*;
public static void main(String [] args)
{
Process p ;
try{
p= Runtime.getRuntime().exec("cmd.exe /c start nxj -r program");
Thread.sleep(15000);
System.out.println("trying to connect");
NXTConnector connt = new NXTConnector();
boolean connected = connt.connectTo("btspp://");
if(connected)System.out.println("Connected");
else
System.out.println("Disconnected");
}
catch (Exception ex)
{}
}
