/// <summary> /// Read the sensor value /// </summary> /// <returns>Value as a int</returns> public int ReadRaw() { try { var ret = _brick.GetSensor((byte)Port); switch (_mode) { case UltraSonicMode.Centimeter: return(ByteUtils.ByteArrayToInt(ret)); case UltraSonicMode.Inch: return(ByteUtils.ByteArrayToInt(ret)); case UltraSonicMode.Listen: return(ret[0]); } } catch (Exception ex) when(ex is IOException) { } return(int.MaxValue); }
/** * 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); }
/// <summary> /// Returns the current association status of this Cellular device. /// </summary> /// <remarks>It indicates occurrences of errors during the modem initialization and connection.</remarks> /// <returns>The current <see cref="CellularAssociationIndicationStatus"/> of the device.</returns> /// <exception cref="InterfaceNotOpenException">If this device connection is not open.</exception> /// <exception cref="TimeoutException">If there is a timeout reading the cellular association /// indication status.</exception> /// <exception cref="XBeeException">If there is any other XBee related error.</exception> /// <seealso cref="CellularAssociationIndicationStatus"/> public CellularAssociationIndicationStatus GetCellularAssociationIndicationStatus() { byte[] associationIndicationValue = GetParameter("AI"); return(CellularAssociationIndicationStatus.UNKNOWN.Get(ByteUtils.ByteArrayToInt(associationIndicationValue))); }