Bluetooth + startProgram()

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Bluetooth + startProgram()

Postby mindstormer1 » Fri Oct 28, 2011 11:12 am

Hello all,

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!!
mindstormer1
New User
 
Posts: 1
Joined: Thu Oct 27, 2011 5:35 pm

Re: Bluetooth + startProgram()

Postby kirkpthompson » Fri Oct 28, 2011 1:35 pm

Well, the first thing I see is
Code: Select all
private NXTCommand nxtCommand = new NXTCommand();
doesn't provide a NXTCommRequest object in the constructor. What version are you using?

The next thing (assuming the above is not a problem) I see is you try to establish a new connection for every mouse button press. Why?

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff