IDiscoveryListener implementation example, MyDiscoveryListener
MyDiscoveryListener must implement the IDiscoveryListener interface, which includes the methods that are executed when discover events occur.
The behavior of the listener is as follows:
- When a new remote XBee device is discovered, the deviceDiscovered() method of the IDiscoveryListener executes, providing the reference of the RemoteXBeeDevice discovered as a parameter. It is a reference, because the XBee network already stores that device inside its list of remote XBee devices.
- If there is an error during the discovery process, the discoveryError() method of the IDiscoveryListener executes, providing an error message with the cause of that error.
- When the discovery process finishes or the configured timeout expires, the discoveryFinished() method of the IDiscoveryListener executes, providing the error message with the reason the process did not finish successfully, or null if the process finished successfully.
IDiscoveryListener implementation example, MyDiscoveryListener
import com.digi.xbee.api.RemoteXBeeDevice;
import com.digi.xbee.api.listeners.IDiscoveryListener;
public class MyDiscoveryListener implements IDiscoveryListener {
/*
* Device discovered callback.
*/
@Override
public void deviceDiscovered(RemoteXBeeDevice discoveredDevice) {
System.out.println("New device discovered: " +
discoveredDevice.toString());
}
/*
* Discovery error callback.
*/
@Override
public void discoveryError(String error) {
System.out.println("There was an error during the discovery: " +
error);
}
/*
* Discovery finished callback.
*/
@Override
public void discoveryFinished(String error) {
if (error != null)
System.out.println("Discovery finished due to an error: " +
error);
else
System.out.println("Discovery finished successfully.");
}
}
PDF
