Home/Support/Support Forum/XBEE Java - how to read multiple packets from one TX to Arduino

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

0 votes
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.
Mike
asked Dec 21, 2014 in DigiMesh Proprietary Mesh Networking by Merlin513 New to the Community (7 points)
edited Dec 22, 2014 by Merlin513

Please log in or register to answer this question.

1 Answer

0 votes
 
Best answer
Easiest way that I finally found using a combination of the ReceiveData and SendData examples is as follows (this is for Processing):
Code:
/** */ //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"; // *** REPLACE WITH THE SERIAL PORT (COM PORT) FOR YOUR LOCAL XBEE *** String mySerialPort = "COM5"; String DATA_TO_SEND = "z"; String REMOTE_NODE_IDENTIFIER = "END_ROUTER_1"; 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(" +--------------------------------------+\n"); try { myDevice.open(); // 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."); System.exit(1); } myDevice.addDataListener(new MyDataReceiveListener()); System.out.println("\n>> Waiting for data..."); } catch (XBeeException e) { System.out.println("Error "); e.printStackTrace(); System.exit(1); } } // draw loop executes continuously void draw() { if(packetCnt == count) { try { myDevice.sendData(remoteDevice, dataToSend); packetCnt = 0; println("DATA REQUEST SENT"); } catch (XBeeException e) { System.out.println("Error"); e.printStackTrace(); System.exit(1); } } else { packetCnt = packetCnt + 1; } }
answered Dec 29, 2014 by Merlin513 New to the Community (7 points)
selected Dec 31, 2014 by Merlin513
...