Using the pc API in eclipse

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

Moderators: 99jonathan, roger, imaqine

Using the pc API in eclipse

Postby janvos2506 » Tue Jul 10, 2012 7:18 pm

So hey i want to connect my iMac to my net so i looked up on google and found this page: http://lejos.sourceforge.net/nxt/nxj/tutorial/Communications/Communications.htm
so i added pccom.jar and blue cove.jar to the build path of my project in eclipse but when i run the program.
this program :
Code: Select all
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTInfo;


public class BlueToothClass {
   
   
   public static void main(String [] args) throws Exception {
      
      NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
      NXTInfo[] nxtInfo = nxtComm.search("NXT");
      
   }
   
   
}


it gives me these errors:
Code: Select all
Native Library bluecove not available
Exception in thread "main" lejos.pc.comm.NXTCommException: Bluetooth stack not detected
   at lejos.pc.comm.NXTCommBluecove.search(NXTCommBluecove.java:54)
   at BlueToothClass.main(BlueToothClass.java:12)
Caused by: javax.bluetooth.BluetoothStateException: BlueCove library bluecove not available
   at com.intel.bluetooth.BlueCoveImpl.loadNativeLibraries(BlueCoveImpl.java:381)
   at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:434)
   at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:65)
   at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1020)
   at java.security.AccessController.doPrivileged(Native Method)
   at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
   at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
   at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
   at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
   at lejos.pc.comm.NXTCommBluecove.search(NXTCommBluecove.java:45)
   ... 1 more


and on that page i found they also said i needed to remove classes.jar but then i couldn't do anything with java and i couldn't even remove it?
so could you maybe help me ?
Thanks!

I'm using mac osx 10.7.4
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby Shawn » Tue Jul 10, 2012 9:37 pm

Did you pass in a -d32 flag to your Eclipse menu -->run --> run configurations --> your class --> arguments --> VM arguments?

Otherwise it will be looking for 64 bit bluecove which isn't supported.
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Re: Using the pc API in eclipse

Postby janvos2506 » Wed Jul 11, 2012 12:14 am

i think that's the prob...
i will check it out when i wake up tomorrow I'm sleeping right now hehe good night:p
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby Shawn » Wed Jul 11, 2012 7:55 am

oooh, sorry for waking you :wink:
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Re: Using the pc API in eclipse

Postby janvos2506 » Wed Jul 11, 2012 12:12 pm

well i got it working over bluetooth but i use usb now and the program finds my net but the communication page says
Once you have a NXTInfo object,you can call the open() method of the NXTComm object to connect to the NXT:

public boolean open(NXTInfo nxt) throws NXTCommException;

but it just gives me a bunch of errors and i used my own net info object in it and it didn't work ???
this is my code

Code: Select all
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTCommUSB;
import lejos.pc.comm.NXTInfo;


public class BlueToothClass {
   
   
   public static void main(String [] args) throws Exception {
      
      NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
      NXTInfo[] nxtInfo = nxtComm.search("NXT");
      boolean open(nxtInfo);
      
   }

}
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby Shawn » Wed Jul 11, 2012 9:16 pm

Is your brick named "NXT"?
Did you use a -d32 flag (for USB too)?
Have you looked at the samples?
What's the error(s)?
User avatar
Shawn
Advanced Member
 
Posts: 723
Joined: Wed Sep 12, 2007 4:59 am
Location: Tokyo

Re: Using the pc API in eclipse

Postby janvos2506 » Wed Jul 11, 2012 10:30 pm

yes yes and it just gives errors while coding but my main problem is how would i send things to my nxt how would i open a input stream and output stream its a bit vague on that page
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby skoehler » Wed Jul 11, 2012 10:39 pm

janvos2506 wrote:
Code: Select all
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTCommUSB;
import lejos.pc.comm.NXTInfo;


public class BlueToothClass {
   
   
   public static void main(String [] args) throws Exception {
      
      NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
      NXTInfo[] nxtInfo = nxtComm.search("NXT");
      boolean open(nxtInfo);
      
   }

}

Any Java compiler (including Eclipse, javac, and whatnot) will tell you that the line "boolean open(nxtInfo);" is incorrect syntax.
The text you quoted from the tutorial page clearly states, that you should call the open method of the nxtComm object which is done like this:
boolean result = nxtComm.open(nxtInfo);

After you have opened the nxtComm object, you can get the Input and OutputStreams like this:
InputStream in = nxtComm.getInputStream();
OutputStram out = nxtComm.getOutputStream();

Note that if result==false, the call to open() was not successful.
skoehler
leJOS Team Member
 
Posts: 1448
Joined: Thu Oct 30, 2008 4:54 pm

Re: Using the pc API in eclipse

Postby janvos2506 » Wed Jul 11, 2012 11:12 pm

haha thanks man !
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby janvos2506 » Wed Jul 11, 2012 11:55 pm

okay i tested it but now it gives me an error i can't use an NXTInfo[] object in the open method..?

Code: Select all
import lejos.pc.comm.NXTComm;
import lejos.pc.comm.NXTCommFactory;
import lejos.pc.comm.NXTCommUSB;
import lejos.pc.comm.NXTInfo;


public class BlueToothClass {
   
   
   public static void main(String [] args) throws Exception {
     
      NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
      NXTInfo[] nxtInfo = nxtComm.search("NXT");
      boolean result = nxtComm.open(nxtInfo);
     
   }

}
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Using the pc API in eclipse

Postby skoehler » Wed Jul 11, 2012 11:56 pm

Of course not. I made an error: nxtInfo is an array. So the correct line would be:
boolean result = nxtComm.open(nxtInfo[0]);

But if course only, if nxtInfo.length>0
skoehler
leJOS Team Member
 
Posts: 1448
Joined: Thu Oct 30, 2008 4:54 pm

Re: Using the pc API in eclipse

Postby janvos2506 » Thu Jul 12, 2012 12:18 am

thanks!
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm


Return to NXJ Software

Who is online

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

more stuff