Connection failed with communication PC - NXT

Post your NXJ projects, project ideas, etc here!

Moderators: roger, 99jonathan, imaqine

Connection failed with communication PC - NXT

Postby Marco9x » Sat Jun 16, 2012 1:40 pm

Hi,
I'm trying to connect to NXT, here's my code:

Code: Select all
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTConnector;
import lejos.nxt.*;
import lejos.nxt.remote.NXTCommand;
import lejos.pc.comm.*;

public class bluetooth {

   /**
    * @param args
    */
   public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
      
      NXTConnector conn = new NXTConnector();
      
      if(!conn.connectTo("NXT","00:16:53:09:1a:74",NXTComm.LCP)){
         
      System.err.println("Connection failed");
      System.exit(1);
      }
      
      
      conn.close();

   }

}

i receive ever "Connection Failed"

I use eclipse with plugin for lejos.
i use lejos 9.0.1 and i have a internal device bluetooth.
Is There a problem with api lejos9.0.1?
Last edited by Marco9x on Sat Jun 16, 2012 3:25 pm, edited 1 time in total.
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby Marco9x » Sat Jun 16, 2012 1:41 pm

i have already added pccomm.jar
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby matthias » Wed Jun 20, 2012 6:38 am

Is the Robot turned on? Bluetooth/USB connected and paired with your PC?
Are you sure, that the Name and Address of the robot is correct?

Which operating system?
Do you want to connect with USB or with Bluetooth?
matthias
New User
 
Posts: 20
Joined: Thu Mar 22, 2012 11:44 am

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 8:52 am

Also can you connect to the NXT using nxjbrowse? What about using the standard Lego software does that work using the same system and NXT.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Connection failed with communication PC - NXT

Postby Marco9x » Wed Jun 20, 2012 1:44 pm

Robot is turned on.
I use debian.
I have configure a new device NXT on computer but i fail to pair from NXT.
I success connected with nxjbrowse via bluetooth.
i have already intalled libbluetooth-dev.
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 2:24 pm

If you can connect from nxjbrowse then you should be able to connect from your own program, it uses that same code and methods. So I suspect that there may be some sort of problem in either the address you have specified, your code, or the way you are building and running it... Are you sure you have the name and the address correct? They will be displayed by nxjbrowse when it connects.

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

Re: Connection failed with communication PC - NXT

Postby Marco9x » Wed Jun 20, 2012 2:42 pm

I have seen name and address by nxjbrowse and are correct.
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby skoehler » Wed Jun 20, 2012 3:02 pm

Don't specify a name and address. (I think you have to pass null) Does it connect?
skoehler
leJOS Team Member
 
Posts: 1110
Joined: Thu Oct 30, 2008 4:54 pm

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 3:23 pm

Are you sure the name is exactly the same including upper/lower case?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Connection failed with communication PC - NXT

Postby Marco9x » Wed Jun 20, 2012 3:56 pm

i have try:
Code: Select all
if(!conn.connectTo("NXT","001653091A74",NXTComm.LCP)){
      System.err.println("connection failed");
      System.exit(1);
      }

and
Code: Select all
if(!conn.connectTo("NXT","00:16:53:09:1A:74",NXTComm.LCP)){
      System.err.println("connection failed");
      System.exit(1);
      }


and
Code: Select all
if(!conn.connectTo(null,null,NXTComm.LCP)){
      System.err.println("connection failed");
      System.exit(1);
      }


but nothing, i receive ever Connection failed.
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 4:15 pm

please copy and paste the output from running nxtbrowse exactly as it appears in the terminal window...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Connection failed with communication PC - NXT

Postby Marco9x » Wed Jun 20, 2012 6:04 pm

this is output by nxjbrowse:

marco@debian:~$ cd Scrivania/leJOS_NXJ_0.9.1beta-3/bin/
marco@debian:~/Scrivania/leJOS_NXJ_0.9.1beta-3/bin$ ./nxjbrowse
leJOS NXJ> Error: Failed to load USB comms driver.
leJOS NXJ> Caused by lejos.pc.comm.NXTCommException: Cannot load NXTComm driver
leJOS NXJ> at lejos.pc.comm.NXTCommFactory.newNXTCommInstance(NXTCommFactory.java:110)
leJOS NXJ> Caused by lejos.internal.jni.JNIException: library libjlibnxt.so was not found in /home/marco/Scrivania/leJOS_NXJ_0.9.1beta-3/bin/../lib/pc/native, architecture linux/x86
leJOS NXJ> at lejos.internal.jni.JNILoader.loadLibrary(JNILoader.java:127)
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 6:57 pm

Hi,
Ok I see the problem now. You are using this version of the connectTo method:
http://lejos.sourceforge.net/nxt/pc/api/lejos/pc/comm/NXTConnector.html#connectTo(java.lang.String,%20java.lang.String,%20int)
As the documentation states this will always connect in packet mode and the third parameter specifies what sort of transport to use (Bluetooth or USB or either) and must have values of...
NXTCommFactory.ALL_PROTOCOLS, NXTCommFactory.BLUETOOTH, or NXTCommFactory.USB
Try changing your code to be...
Code: Select all
      NXTConnector conn = new NXTConnector();
     
      if(!conn.connectTo("NXT","00:16:53:09:1a:74",NXTCommFactory.BLUETOOTH)){
         
      System.err.println("Connection failed");

and it should work. If you do want to connect using LCP mode then you need to use this version of the connectTo method:
http://lejos.sourceforge.net/nxt/pc/api/lejos/pc/comm/NXTConnector.html#connectTo(java.lang.String,%20java.lang.String,%20int,%20int)
and your code should be...
Code: Select all
]      NXTConnector conn = new NXTConnector();
     
      if(!conn.connectTo("NXT","00:16:53:09:1a:74",NXTCommFactory.BLUETOOTH,  NXTComm.LCP)){
         
      System.err.println("Connection failed");


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

Re: Connection failed with communication PC - NXT

Postby Marco9x » Wed Jun 20, 2012 7:45 pm

i have modified the code but it didn't work.
Damn, i receive ever connection failed
Marco9x
New User
 
Posts: 9
Joined: Sat Jun 16, 2012 1:32 pm

Re: Connection failed with communication PC - NXT

Postby gloomyandy » Wed Jun 20, 2012 7:49 pm

What does your code look like now? I tested your original code and it failed. I made the changes given above and it works. Please post the current state of your code...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Next

Return to NXJ Projects

Who is online

Users browsing this forum: Google [Bot] and 2 guests

more stuff