I'm trying to start a program with a bluetooth connection, but i'm having some troubles because the bluetooth connection is closed when the program starts.
Does anyone knows how I could re-establish the bluetooth connection?
I use the following code:
- Code: Select all
private NXTCommand nxtCommand = new NXTCommand();
private boolean connected;
private NXTComm nxtComm;
//Connect button
jButton1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
try {
NXTInfo nxtInfo = new NXTInfo(NXTCommFactory.BLUETOOTH, "NXT", "00:16:53:09:16:BF");
NXTComm nxtComm = NXTCommFactory.createNXTComm(nxtInfo.protocol);
connected = nxtComm.open(nxtInfo, NXTComm.LCP);
nxtCommand.getSingleton().setNXTComm(nxtComm);
} catch (NXTCommException ex) {
Logger.getLogger(RemoteNXTView.class.getName()).log(Level.SEVERE, null, ex);
}
//If the connection fails
if(!connected)
{
jLabel3.setForeground(Color.red);
jLabel3.setText("Connection problem!");
jLabel3.setVisible(true);
}
//If the connection is succefull
else
{
try {
nxtCommand.getSingleton().startProgram("Example1.nxj");
} catch (IOException ex) {
Logger.getLogger(RemoteNXTView.class.getName()).log(Level.SEVERE, null, ex);
jLabel4.setText("Couldn't open file!");
}
//Re-establish the bluetooth connection
}
}
});
Many thanks in advance!!
