XBEE Java - how to read multiple packets from one TX to Arduino

Currently I am using Andrew Rapp’s XBee Java Api with two XBee 900hp’s. I managed to get the PC to send a command to the Arduino to transmit back to the PC and to convert the packet to a useable form. But I am having implementation problems when I try to link in a GUI. It hangs after a while. The example implements a queue but doesn’t seem to working correctly.

Some additional info. I did created a processing sketch that sends the command to arduino to dump 32 samples of data (this is processed data, so it is text) and send back to the PC for the processing sketch to read. This seems to be working. I am using it read IMU data (mag, accel, gyro, q, altitude, press and temp). I can rotate the board and data will still come across. I am running at 57600. However, the whole thing transfer into the sketch is slow like there is too much overhead or delay.

Now, when I use the same approach in the actually GUI and I try and rotate the IMU the whole thing hangs after a 100 or so reads.

I would like to convert over to the Digi XBee Java Api (using Processing IDE) and would like to implement the calls to read x-number of packets and put it into a queue which I really need to do. The current listener follows the example for using a concurrentlinked queue on XBeeResponse.

Any help/guidance would be appreciated.

Easiest way that I finally found using a combination of the ReceiveData and SendData examples is as follows (this is for Processing):



//package com.rapplogic.xbee.examples.zigbee;
import processing.serial.*; 

import com.digi.xbee.api.RemoteXBeeDevice;
import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.XBeeNetwork;
import com.digi.xbee.api.exceptions.XBeeException;
import com.digi.xbee.api.utils.HexUtils;
import com.digi.xbee.api.listeners.IDataReceiveListener;
import com.digi.xbee.api.models.XBeeMessage;

String version = "1.02";

String mySerialPort = "COM5";

String DATA_TO_SEND = "z";
int BAUD_RATE = 57600;
int packetCnt = 0;
int count = 32;

XBeeDevice myDevice = new XBeeDevice(mySerialPort, BAUD_RATE);
byte[] dataToSend = DATA_TO_SEND.getBytes();
XBeeNetwork xbeeNetwork;
RemoteXBeeDevice remoteDevice;

void setup() {

  size(800, 230); // screen size
  smooth(); // anti-aliasing for graphic display

    System.out.println(" +--------------------------------------+");
    System.out.println(" |  XBee Java Library Send Data Sample  |");
    System.out.println(" +--------------------------------------+
    try {
      // Obtain the remote XBee device from the XBee network.
      xbeeNetwork = myDevice.getNetwork();
      remoteDevice = xbeeNetwork.discoverDevice(REMOTE_NODE_IDENTIFIER);
      if (remoteDevice == null) {
        System.out.println("Couldn't find the remote XBee device with '" + REMOTE_NODE_IDENTIFIER + "' Node Identifier.");
      myDevice.addDataListener(new MyDataReceiveListener());
>> Waiting for data...");
    } catch (XBeeException e) {
      System.out.println("Error ");
// draw loop executes continuously
void draw() {
    if(packetCnt == count) {
	try {      
	   myDevice.sendData(remoteDevice, dataToSend);
           packetCnt = 0;
           println("DATA REQUEST SENT");
	} catch (XBeeException e) {
    } else {
	packetCnt = packetCnt + 1;