My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GettingStartedWithEclipse  

Featured
Updated Aug 21, 2010 by andrew.rapp@gmail.com

This entry is intended to help you get started using Eclipse with XBee API. This entry assumes you have at least one XBee connected to your computer and your computer recognizes the device as a serial port. If this is not the case you probably need to download the FTDI USB Serial drivers (See GettingStarted).

First you'll need to download the Eclipse IDE. There are several versions to choose from and any of the Java version will work fine. I recommend "Eclipse IDE for Java Developers". Unzip the file and run the executable (e.g. Eclipse.exe on Windows).

Download the latest version of the XBee API, if you haven't done so already and unzip the file to where ever you keep your projects.

Now it's time to create an Eclipse project. From the Eclipse file menu, select File->Import, then, General->Existing Projects into Workspace. Click "Next", choose the "Select root directory" radio button and browse to the xbee-api folder (I leave the "copy projects into workspace" checkbox unchecked). Click "Finish".

At this point you should have an XBee attached to your serial port and configured in API mode. See XBeeConfiguration for more details.

In Eclipse, in the left most window pane, expand the project you created and navigate to the "src" folder. Then expand the "com.rapplogic.xbee.examples" package and open the ApiAtTest Java class file (this example works for both series 1 and 2 -- in API mode). Edit the line that contains the "xbee.open(..)" method and specify your COM port. Click save.

To run the example, right-click the file in the left window pane and select "Run As->Java Application". You should see the output of your code in the Console window. You can also view the the program output in xbee.log, in the project folder.

If you see an error message such as:

Caused by: java.lang.RuntimeException: Could not find port: COM6

at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:73) at com.rapplogic.xbee.RxTxSerialComm.openSerialPort(RxTxSerialComm.java:40) at com.rapplogic.xbee.api.XBee.open(XBee.java:105)

your serial port was not found. Verify it is plugged in and powered on and your computer can "see" it.

Now run some of the other examples. The examples are organized by radio type, so "com.rapplogic.xbee.examples.wpan" are for Series 1 and "com.rapplogic.xbee.examples.zigbee" are for Series 2 (ZNet).

You can start creating your own classes too. From the File menu select File->New->Class Enter a name, for example: "XBeeTest", and specify a package, like "com.foo.xbee" Now you can cut and paste pieces from the examples to get going.

For examples that are designed to run "infinitely" (e.g. while (true) collect data), remember to terminate the process before running another example. If you get an error message stating that RXTX is in use, there is probably another Java example running. If this occurs, shutdown Eclipse and start it again.

Comment by G2subsPstLC@gmail.com, Jul 4, 2010

under eclipse 3.6.0:

>>Ok so now it's time to create an Eclipse project. From the Eclipse file menu, select new->Java Project. Enter a name, for example "xbeefun".

this works

>>Under contents, select "create project from existing source" and select the xbee-api folder (from the zip file you downloaded). Now you should be able to click "next" and "finish".

however, i did not see, "create project from existing source". after creating a "jave project" as "xbeefun", i clicked these to get your "ApiAtTest?.java" :: File->Import->General->"Existing Projects into Workspace"
not a big deal, just took me a bit to navigate eclipse to get this along with being new to eclipse and java.

thanks

Comment by project member andrew.rapp@gmail.com, Aug 21, 2010

Hi, the Eclipse UI changed a bit in version 3.6. I just updated the wiki.

Comment by pte39pt...@comcast.net, Apr 18, 2011

Hi Andrew, nice example, care to provide some more? I'm just getting going, and noted that the example refers to ApiAtTest? which apparently has changed it's name to ApiAtExample?.

For those that are running this on Windows for the first time, find Andrews references to "/dev/tty.usbserial-A6005v5M" in the example you are trying to run and replace with "COMx", where X-CTU tells you the COM port you are using on The PC_Settings tab. It's the one in the brackets at the end of the Select COM port string you are using to talk to your device.

Finally, the example output is displayed in the console tab, you don't get a nice GUI, I guess you will need to write your own ;)

If you read the output, line by line, it'll start to make sense.

For people New to JAVA and Eclipse, like me, be prepared for a steep learning curve. It took me four days to ge this far. Sigh!

Comment by rasi...@gmail.com, Jan 23, 2012

It gives me a couple of errors :

java.lang.UnsatisfiedLinkError?: C:\Users\Rasik\Desktop\Games\xbee-api\rxtxSerial.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform thrown while loading gnu.io.RXTXCommDriver Exception in thread "main" java.lang.IllegalStateException?: XBee is not connected

at com.rapplogic.xbee.api.XBee.close(XBee.java:425) at com.rapplogic.xbee.examples.ApiAtExample?.<init>(ApiAtExample?.java:67) at com.rapplogic.xbee.examples.ApiAtExample?.main(ApiAtExample?.java:73)

Do I need a separate dll to be able to run this properly on a 64 bit system? Also, the XBee is very clearly connected and XCTU is able to read it, but it still gives this error. Why do you think that is?

Comment by project member andrew.rapp@gmail.com, Jan 23, 2012

Nope, you should just need to force 32-bit mode by adding the "-d32" argument to java. In Eclipse you would go to run configurations, click the arguments tab, and enter it in the vm arguments box

Comment by energise...@gmail.com, May 19, 2012

Hi Andrew,

I'm trying to run this in Netbeans, and have overcome all the issues up to and including adding the -d32 option to the configuration... but am still getting:

Exception in thread "main" java.lang.IllegalStateException?: XBee is not connected

at com.rapplogic.xbee.api.XBee.close(XBee.java:425) at com.rapplogic.xbee.examples.wpan.NodeDiscoverExample?.<init>(NodeDiscoverExample?.java:85) at com.rapplogic.xbee.examples.wpan.NodeDiscoverExample?.main(NodeDiscoverExample?.java:91)
Java Result: 1

I've changed the xbee.open command to refer to the correct COM port and baud rate for my xbee… any idea what may be causing this issue?

The next step for me is trying again in Eclipse, but it really should be able to work. Any insight would be appreciated.


Sign in to add a comment
Powered by Google Project Hosting