/** * Notifies the given discovery listeners that a device was discovered. * * @param listeners The discovery listeners to be notified. * @param device The remote device discovered. */ private void notifyDeviceDiscovered(IList <IDiscoveryListener> listeners, RemoteXBeeDevice device) { if (listeners == null) { lock (deviceList) { deviceList.Add(device); } return; } XBeeNetwork network = xbeeDevice.GetNetwork(); RemoteXBeeDevice addedDev = network.addRemoteDevice(device); if (addedDev != null) { foreach (IDiscoveryListener listener in listeners) { listener.DeviceDiscovered(addedDev); } } else { String error = "Error adding device '" + device + "' to the network."; notifyDiscoveryError(listeners, error); } }
/** * Discovers and reports the first remote XBee device that matches the * supplied identifier. * * <p>This method blocks until the device is discovered or the configured * timeout in the device (NT) expires.</p> * * @param id The identifier of the device to be discovered. * * @return The discovered remote XBee device with the given identifier, * {@code null} if the timeout expires and the device was not found. * * @throws InterfaceNotOpenException if the device is not open. * @throws XBeeException if there is an error sending the discovery command. * * @see #discoverDevices(List) */ public RemoteXBeeDevice DiscoverDevice(string id) /*throws XBeeException */ { // Check if the connection is open. if (!xbeeDevice.IsOpen) { throw new InterfaceNotOpenException(); } logger.DebugFormat("{0}ND for {1} device.", xbeeDevice.ToString(), id); running = true; discovering = true; performNodeDiscovery(null, id); XBeeNetwork network = xbeeDevice.GetNetwork(); RemoteXBeeDevice rDevice = null; if (deviceList != null && deviceList.Count > 0) { rDevice = deviceList[0]; if (rDevice != null) { rDevice = network.addRemoteDevice(rDevice); } } return(rDevice); }
/** * Discovers and reports all remote XBee devices that match the supplied * identifiers. * * <p>This method blocks until the configured timeout in the device (NT) * expires.</p> * * @param ids List which contains the identifiers of the devices to be * discovered. * * @return A list of the discovered remote XBee devices with the given * identifiers. * * @throws InterfaceNotOpenException if the device is not open. * @throws XBeeException if there is an error discovering the devices. * * @see #discoverDevice(String) */ public List <RemoteXBeeDevice> discoverDevices(IList <string> ids) /*throws XBeeException */ { // Check if the connection is open. if (!xbeeDevice.IsOpen) { throw new InterfaceNotOpenException(); } logger.DebugFormat("{0}ND for all {1} devices.", xbeeDevice.ToString(), ids.ToString()); running = true; discovering = true; performNodeDiscovery(null, null); List <RemoteXBeeDevice> foundDevices = new List <RemoteXBeeDevice>(0); if (deviceList == null) { return(foundDevices); } XBeeNetwork network = xbeeDevice.GetNetwork(); foreach (RemoteXBeeDevice d in deviceList) { string nID = d.NodeID; if (nID == null) { continue; } foreach (string id in ids) { if (nID.Equals(id)) { RemoteXBeeDevice rDevice = network.addRemoteDevice(d); if (rDevice != null && !foundDevices.Contains(rDevice)) { foundDevices.Add(rDevice); } } } } return(foundDevices); }