Main /
XBeeThe XBee is Digi's IEEE 802.15.4 product, some of which are ZigBee compatible. XBeePro
The XBee Pro S1 is not ZigBee, though the XBee ZigBee modules are ZigBee compatible.
USBThe two XBee Pros that I have are plugged in to USB boards. Either one seems to work.
Raw Serial Port AccessThe Ptolemy II tree includes an implementation of RXTX (at least for MacOS) and a SerialPort actor that provides low-level access to serial port devices, including the XBee devices. If you plug in the XBee device into your USB port, two new serial devices will be discovered by the SerialPort actor. On my machine, they are called "/dev/tty.usbserial-DA01LK3S" and "/dev/cu.usbserial-DA01LK3S". I don't know what the difference is, but either worked for me. The SerialPort actor accepts as input a unsigned byte array and produces as output an unsigned byte array. If you send to its input port a sequence of two strings (convert to unsigned byte array using StringToUnsignedByteArray) "+++" followed by "ATSH\r" within 3 seconds, then you will be returned the upper half of the address of your XBee device, per the AT command instructions (Note that these instructions are self contradictory... the second mention of the three second wait is incorrect. The first one is correct). Note that "\r" is a Windows-style return character. Using "\n" does not work. On my device, this returns "13A200" (a hex number representing the upper half of the address of the device). Adding "ATSL\r" to the commands returns "40D5FF39", the lower half of the address. So the address appears to be a 56 bit address. Note that the SerialPort actor may produce the output in multiple firings. I.e., it may produce "40" followed by "D5FF39" or "40D" followed by "5FF39" (or any other partitioning). X-CTU SoftwareThe X-CTU Software runs on the Mac or other host. The software is used to configure the XBee and has a simple console application.
Oddly, I could not get X-CTU 6.3.0 Build IS 20141110-08 to work with Mac OS X 10.7.5. The problem was that clicking on Discover Devices did not find my port. The same two XBees are discovered just fine under 10.11.1. XBCTU Under Ubuntu Studio
XCTU: Ubuntu: Permission denied:com.digi.xbee.exceptions.XBeeException: Error initializing XBee device parameters /dev/ttyS0: SerOpenPort failed: Permission denied Solution: sudo usermod -a -G dialout sbuser Then, as buser@swarmnuc001:~$ groups admin dialout sbuser@swarmnuc001:~$ ls -l /dev/ttyUSB1 crw-rw---- 1 root dialout 188, 1 Dec 9 15:16 /dev/ttyUSB1 sbuser@swarmnuc001:~$ XCTU Won't Start under UbuntuUnder Ubuntu 14.04.3 LTS, XCTU failed to start because I accidentally downloaded the x86 version instead of the x64 version, below is the error message sbuser@swarmnuc001:~$ /opt/Digi/XCTU-NG/app App: An error has occurred. See the log file /home/sbuser/.eclipse/13786435/configuration/1449687334319.log. sbuser@swarmnuc001:~$ The error message is: java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: /opt/Digi/XCTU-NG/configuration/org.eclipse.osgi/bundles/146/1/.cp/libswt-pi-gtk-4236.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory no swt-pi-gtk in java.library.path /home/sbuser/.swt/lib/linux/x86/libswt-pi-gtk-4236.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory Can't load library: /home/sbuser/.swt/lib/linux/x86/libswt-pi-gtk.so Java Interfaces to XBeeAs far as a Java Interface to the XBee, I see two approaches:
XBeeJavaLibrary
The docs describe how to create an Eclipse project that uses
XBee Java ExampleThe Building your first XBee Java application example worked for me under Mac OS X 10.11.1. The source code for package com.digi.xbee.example; import com.digi.xbee.api.XBeeDevice; import com.digi.xbee.api.exceptions.XBeeException; public class MainApp { /* Constants */ // TODO Replace with the port where your sender module is connected to. private static final String PORT = "COM1"; // TODO Replace with the baud rate of your sender module. private static final int BAUD_RATE = 9600; private static final String DATA_TO_SEND = "Hello XBee World!"; public static void main(String[] args) { XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE); byte[] dataToSend = DATA_TO_SEND.getBytes(); try { myDevice.open(); System.out.format("Sending broadcast data: '%s'", new String(dataToSend)); myDevice.sendBroadcastData(dataToSend); System.out.println(" >> Success"); } catch (XBeeException e) { System.out.println(" >> Error"); e.printStackTrace(); System.exit(1); } finally { myDevice.close(); } } } What this does is construct an XBeeDevice, The summary is that open() creates a DataReader (JavaDoc, Source) that is a Thread that reads from the serial port using IConnectionInterface (JavaDoc, Source) See XBeeJavaAnalysis. Using Serial Console to Communicate with an XBeeThis does not totally work, but at least the XBee answers
XBee Java Interface and nrjavaserialWhen trying to run the XBee Java example at https://docs.digi.com/display/XBJLIB/Building+your+first+XBee+Java+application with nrjavaserial, the following error appeared: Exception in thread "main" java.lang.NoSuchMethodError: gnu.io.CommPortIdentifier.open(Ljava/lang/String;I)Lgnu/io/CommPort; at com.digi.xbee.api.connection.serial.SerialPortRxTx.open(SerialPortRxTx.java:167) at com.digi.xbee.api.XBeeDevice.open(XBeeDevice.java:195) at ptolemy.actor.lib.jjs.modules.xbee.XBeeHello.main(XBeeHello.java:20) The error message in question is: gnu.io.CommPortIdentifier.open(Ljava/lang/String;I)Lgnu/io/CommPort; http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7/src/CommPortIdentifier.java, which is similar to what is in XBeeJava has: public synchronized CommPort open(String TheOwner, int i) https://github.com/NeuronRobotics/nrjavaserial/blob/86b44454cebc7ba29c2032e904cfbe4eb098b841/src/main/java/gnu/io/CommPortIdentifier.java, which is what is in nrjavaserial has: public RXTXPort open(String TheOwner, int i) However, RXTXPort extends SerialPort which extends CommPort, so this should work (I think). For reference, Line 167 of SerialPortRxTx.java is serialPort = (RXTXPort)portIdentifier.open(PORT_ALIAS + " " + port, receiveTimeout); To recompile the XBee Java Library, I edited the pom.xml file and commented out the rxtx references and added references to nrjavaserial. <dependencies> <dependency> <groupId>com.neuronrobotics</groupId> <artifactId>nrjavaserial</artifactId> <version>3.11.0</version> </dependency> <!-- <dependency> <groupId>org.rxtx</groupId> <artifactId>rxtx</artifactId> <version>${rxtx.version}</version> </dependency> <dependency> <groupId>org.rxtx</groupId> <artifactId>rxtx-native</artifactId> <version>${rxtx.version}</version> <classifier>${build.type}</classifier> </dependency> --> To build: cd ~/src/XBeeJavaLibrary/ mvn3 install cp target/library/xbjlib-1.1.0.jar $PTII/lib/xbjlib-1.1.0.nrjavaserial.jar Note that at build time for the xbjlib library, the reference to com.neuronrobotics uses an older version of nrjavaserial that does not have the Apple-specific fix needed in RxTx Hanging. However, at runtime, we use a version of nrjavaserial that has the fix. Java Software for the XBeeRxTxSee RxTx for information about the RxTx Java Serial Port Interface. |