Product family: XBP24-ZB
Function set: ZigBee Coordinator API
Firmware version: 21A7
Hello, I am currently using Digi’s XBee Java Library with API (AP=1) and it works properly.
However, another node of my network is associated with an Arduino and I want to use ‘Arduino Library for communicating with XBee in API mode’ (https://github.com/andrewrapp/xbee-arduino).
That Arduino Library requires API Escaped operating mode (API 2). It was not supposed to be a problem, since XBee Java Library supports API 2. Nevertheless, I got an error when trying to open the serial connection with the XBee.
>> Error
com.digi.xbee.api.exceptions.TimeoutException: There was a timeout while executing the requested operation.
at com.digi.xbee.api.AbstractXBeeDevice.sendXBeePacket(AbstractXBeeDevice.java:989)
at com.digi.xbee.api.AbstractXBeeDevice.sendATCommand(AbstractXBeeDevice.java:806)
at com.digi.xbee.api.AbstractXBeeDevice.sendParameter(AbstractXBeeDevice.java:1983)
at com.digi.xbee.api.AbstractXBeeDevice.getParameter(AbstractXBeeDevice.java:1925)
at com.digi.xbee.api.AbstractXBeeDevice.readDeviceInfo(AbstractXBeeDevice.java:365)
at com.digi.xbee.api.XBeeDevice.open(XBeeDevice.java:219)
at com.digi.xbee.example.MainApp.main(MainApp.java:20)
Is there any difference between API and API 2 when programming with this Java Library?
Thanks for your reply! I looked, but it always says that this library supports API 2. I looked at the source code of the library and it does work with API 2, but I can not identify the reason of the problem.
Eclipse indicates the error in the following function of the library source code (line indicated as a comment):
protected XBeePacket sendXBeePacket(final XBeePacket packet)
throws InvalidOperatingModeException, TimeoutException, IOException {
// Check if the packet to send is null.
if (packet == null)
throw new NullPointerException("XBee packet cannot be null.");
// Check connection.
if (!connectionInterface.isOpen())
throw new InterfaceNotOpenException();
OperatingMode operatingMode = getOperatingMode();
switch (operatingMode) {
case AT:
case UNKNOWN:
default:
throw new InvalidOperatingModeException(operatingMode);
case API:
case API_ESCAPE:
// Build response container.
ArrayList responseList = new ArrayList();
// If the packet does not need frame ID, send it async. and return null.
if (packet instanceof XBeeAPIPacket) {
if (!((XBeeAPIPacket)packet).needsAPIFrameID()) {
sendXBeePacketAsync(packet);
return null;
}
} else {
sendXBeePacketAsync(packet);
return null;
}
// Add the required frame ID to the packet if necessary.
insertFrameID(packet);
// Generate a packet received listener for the packet to be sent.
IPacketReceiveListener packetReceiveListener = createPacketReceivedListener(packet, responseList);
// Add the packet listener to the data reader.
addPacketListener(packetReceiveListener);
// Write the packet data.
writePacket(packet);
try {
// Wait for response or timeout.
synchronized (responseList) {
try {
responseList.wait(receiveTimeout);
} catch (InterruptedException e) {}
}
// After the wait check if we received any response, if not throw timeout exception.
if (responseList.size() < 1)
throw new TimeoutException();//ERROR INDICATED IN THIS LINE!
// Return the received packet.
return responseList.get(0);
} finally {
// Always remove the packet listener from the list.
removePacketListener(packetReceiveListener);
}
}
}