/** * Calculates the maximum response time, in milliseconds, for network * discovery responses. * * @param listeners Discovery listeners to be notified about process events. * * @return Maximum network discovery timeout. */ private long CalculateTimeout(IList <IDiscoveryListener> listeners) { long timeout = -1; // Read the maximum discovery timeout (N?). try { timeout = ByteUtils.ByteArrayToLong(xbeeDevice.GetParameter("N?")); } catch (XBeeException) { logger.DebugFormat("{0}Could not read the N? value.", xbeeDevice.ToString()); } // If N? does not exist, read the NT parameter. if (timeout == -1) { // Read the device timeout (NT). try { timeout = ByteUtils.ByteArrayToLong(xbeeDevice.GetParameter("NT")) * 100; } catch (XBeeException) { timeout = DEFAULT_TIMEOUT; String error = "Could not read the discovery timeout from the device (NT). " + "The default timeout (" + DEFAULT_TIMEOUT + " ms.) will be used."; notifyDiscoveryError(listeners, error); } // In DigiMesh/DigiPoint the network discovery timeout is NT + the // network propagation time. It means that if the user sends an AT // command just after NT ms, s/he will receive a timeout exception. if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_MESH) { timeout += 3000; } else if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_POINT) { timeout += 8000; } } if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_MESH) { try { // If the module is 'Sleep support', wait another discovery cycle. bool isSleepSupport = ByteUtils.ByteArrayToInt(xbeeDevice.GetParameter("SM")) == 7; if (isSleepSupport) { timeout += timeout + (timeout / 10L); } } catch (XBeeException) { logger.DebugFormat("{0}Could not determine if the module is 'Sleep Support'.", xbeeDevice.ToString()); } } return(timeout); }