Connection to remote device

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Connection to remote device

Postby hyderabat » Fri Nov 04, 2011 10:25 am

Hi everyone

I am trying to remotely control one NXT from another one. For this reason, I would like to periodically check if the connection still exists. That is why I am using the code down there:

Code: Select all
try {
         
         String blueadd = remo.getBluetoothAddress();
         LCD.drawString(blueadd,0,2);
         if (blueadd == remo.getBluetoothAddress()) LCD.drawString("CORRECT!", 0, 4);
         else LCD.drawString("WRONG!", 0, 4);
         Delay.msDelay(3000);
      } catch (Exception e) {LCD.drawString("ReadingException",0,7);Delay.msDelay(3000);System.exit(1);}


The hallarious thing is, that even though I just said blueadd = the bluetooth address, it keeps saying that its WRONG (I have to check that because I use it in another part of the program).

So what can I do? Does the string cut off some parts of the address, or what doesn't work? PS: It is the same with getName().
hyderabat
New User
 
Posts: 14
Joined: Sun Oct 16, 2011 12:48 pm

Re: Connection to remote device

Postby hyderabat » Fri Nov 04, 2011 10:40 am

I solved it now with the Name:

Code: Select all
      try {
         
         String blueadd = remo.getBrickName();
         blueadd = blueadd.substring(0,4);
         LCD.drawString(blueadd,0,2);
         String name = remo.getBrickName().substring(0,4);
         LCD.drawString(name,0,3);
         if (blueadd.equals(name)) LCD.drawString("CORRECT!", 0, 4);
         
         else LCD.drawString("WRONG!", 0, 4);
         Delay.msDelay(3000);
      } catch (Exception e) {LCD.drawString("ReadingException",0,7);Delay.msDelay(3000);System.exit(1);}


But with the bluetooth address, I don't have a clue what I am doing wrong there... :-(
hyderabat
New User
 
Posts: 14
Joined: Sun Oct 16, 2011 12:48 pm

Re: Connection to remote device

Postby gloomyandy » Fri Nov 04, 2011 11:25 am

Hi,
your two examples are not using the same comparison operator, you may want to read the following article == is not doing what you think it is...
http://www.devdaily.com/java/edu/qanda/pjqa00001.shtml

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3964
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff