/// <summary> /// Reads the temperature in Celsius (°C). /// </summary> /// <param name="source">The temperature source to measure. See <see cref="TemperatureSources"/> for more information.</param> /// <returns>Temperature in Celsius (C) if successful, otherwise -999.999</returns> /// <example>Example usage: /// <code language = "C#"> /// var temp = _altitude.ReadTemperature(TemperatureSources.Ambient); /// Debug.Print("Temperature - " + temp + " °C\n"); /// </code> /// <code language = "VB"> /// Dim temp = _altitude.ReadTemperature(TemperatureSources.Ambient) /// Debug.Print("Temperature - " <![CDATA[&]]> temp <![CDATA[&]]> " <![CDATA[&]]> Microsoft.VisualBasic.Constants.vbCrLf) /// </code> /// </example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotImplementedException("The AltitudeClick does not provide Object temperature measurement. Use TemperatureSources.Ambient for Temperature measurement."); } var counter = 0; // We do not have to change modes to read temperature. ToggleOneShot(); while (!TemperatureDataReady()) { if (counter++ == MaxDataReadyAttempts) { return(float.MinValue); } Thread.Sleep(1); } // Wait here until new data is available. // read Temperature var mTemp = ReadByte(OUT_T_MSB); var lTemp = (ReadByte(OUT_T_LSB) >> 4) / 16.0; var temperature = (float)(mTemp + lTemp); return(Utilities.Temperature.ConvertTo(TemperatureUnits.Celsius, _temperatureUnit, temperature)); }
/// <inheritdoc cref="ITemperature" /> /// <summary> /// Reads the temperature from the Thermo 6 Click. /// </summary> /// <param name="source">The source temperature to read. In this case, only reading of ambient temperature is supported.</param> /// <returns>A <see cref="System.Single" /> precision number representing the temperature.</returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException will be thrown if attempting to read object temperature /// as this module does not support reading of object temperature. /// </exception> /// <remarks> /// If attempting to read temperature while in Low Power mode, will result in the temperature not getting updated. /// </remarks> /// <example> /// <code language="C#"> /// while (true) /// { /// Debug.Print("Temperature........: " + _sensor.ReadTemperature().ToString("F4") + " °F"); /// Thread.Sleep(1000); /// } /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotSupportedException("This module does not support reading of object temperatures."); } Int32 rawData = (this as ITemperature).RawData; Int32 integralPortion = ConvertTwosComplementToDecimal((Byte)(rawData >> 8)); Single fractionalPortion = ((rawData & 0xFF) >> 7) * 0.5F; switch (TemperatureUnit) { case TemperatureUnits.Celsius: { return(integralPortion + fractionalPortion); } case TemperatureUnits.Kelvin: { return(integralPortion + fractionalPortion + 273.13f); } case TemperatureUnits.Fahrenheit: { return((integralPortion + fractionalPortion) * 1.80f + 32F); } default: { throw new ArgumentOutOfRangeException(); } } }
/// <summary> /// Reads the temperature from the TempHum4 Click. /// </summary> /// <param name="source">The <see cref="TemperatureSources" /> to read the Temperature from.</param> /// <returns>The temperature measured in the unit specified in the TemperatureUnits property. Defaults to °C.</returns> /// <exception cref="InvalidOperationException"> /// an InvalidOperationException will be thrown if attempting to read /// <see cref="TemperatureSources.Object" /> as this module does not support object measurement. /// </exception> /// <example> /// Example usage: /// <code language="C#"> /// Debug.WriteLine("Temperature - " + _sensor.ReadTemperature()); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new InvalidOperationException( "Object temperature measurement not supported by the TempHum11 Click"); } if (AcquisitionMode == AcquisitionModes.Sequential) { throw new ApplicationException( "You cannot read temperature independantly while Acquisition Mode is set for sequential access. Use the ReadSensor method instead."); } WriteByte(TempRegister); while (_dataReadyPin.Read() == GpioPinValue.High) { } Byte[] readBuffer = ReadBytes(2); Single temperature = (Single)((readBuffer[0] << 8) / 65536.0 * 165.0 - 40.0); return(ConvertToScale(temperature)); }
/// <summary>Reads the temperature.</summary> /// <param name="source">The <see cref="TemperatureSources"/> to use.</param> /// <returns>A single representing the temperature read from the source, degrees Celsius.</returns> /// <example> /// <code language = "C#"> /// Debug.WriteLine("Temperature.......: " + _tempHum.ReadTemperature().ToString("F2") + " �F"); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotSupportedException("This module does not support reading object temperature. Use ambient instead."); } if ((ReadRegister(HTS221_CTRL_REG1) & 0x03) == 0x00) // If we are in one-shot mode, enable a one-shot conversion. { // Set one-shot enable while forcing the heater off also BOOT bit (bit 7) should be 0. WriteRegister(HTS221_CTRL_REG2, 0x01); } // Wait here for completion of conversion either in one-shot mode or via ODR cycle WaitForSensorData(HTS221_STATUS_REG, HTS221_TEMPERATURE_DATA_AVAILABLLE_BIT); sensorData = ReadRegister(HTS221_TEMP_OUT_L); sensorData |= (Int16)(ReadRegister(HTS221_TEMP_OUT_H) << 8); temperature = (sensorData - T0_OUT) / (Single)(T1_OUT - T0_OUT); temperature = T0_degC + temperature * (T1_degC - T0_degC); temperature /= 8; return(ScaleTemperature(temperature)); }
/// <summary> /// Returns the temperature as read from the HTU21D Click in degrees Celsius. /// </summary> /// <param name="source">The measurement source. See <see cref="TemperatureSources"/> for more information.</param> /// <returns>Temperature in degrees Celsius</returns> /// <exception cref="NotImplementedException">A NotImplementedException will be thrown is attempting to read <see cref="TemperatureSources.Object"/></exception> /// <example>Example usage: /// <code language = "C#"> /// Debug.Print("Temperature " + sensor.ReadTemperature(TemperatureSources.Ambient).ToString("n2") + " °C"); /// </code> /// <code language = "VB"> /// Debug.Print("Temperature " <![CDATA[&]]> sensor.ReadTemperature(TemperatureSources.Ambient).ToString("n2") <![CDATA[&]]> " °C"); /// </code> /// </example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotImplementedException("Object temperature measurement not supported. Use TemperatureSources.Ambient for temperature measurement."); } return(ReadSensor(_measurementMode, MeasurementType.Temperature)); }
/// <summary> /// Reads the temperature. /// </summary> /// <param name="source">The source.</param> /// <returns> /// A single representing the temperature read from the source, in the unit specified by the TemperatureUnit property. /// </returns> /// <example>Example usage: /// <code language = "C#"> /// Debug.Print("Thermocouple Temperature - " + _thermoClick.ReadTemperature(TemperatureSources.Object) + "°C"); /// Debug.Print("Internal IC Temp - " + _thermoClick.ReadTemperature() + "°C"); /// </code> /// <code language = "VB"> /// Debug.Print("Thermocouple Temperature - " <![CDATA[&]]> _thermoClick.ReadTemperature(TemperatureSources.Object) <![CDATA[&]]> "°C"); /// Debug.Print("Internal IC Temp - " <![CDATA[&]]> _thermoClick.ReadTemperature() <![CDATA[&]]> "°C"); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { var dataTmp = ReadData(); if (source == TemperatureSources.Ambient) { return(_temperatureUnit == TemperatureUnits.Celsius ? dataTmp.ColdJunctionTemperature : _temperatureUnit == TemperatureUnits.Fahrenheit ? (Single)((dataTmp.ColdJunctionTemperature * (9.0 / 5)) + 32) : (Single)(dataTmp.ColdJunctionTemperature + 273.15)); } return(_temperatureUnit == TemperatureUnits.Celsius ? dataTmp.ThermocoupleTemperature : _temperatureUnit == TemperatureUnits.Fahrenheit ? (Single)((dataTmp.ThermocoupleTemperature * (9.0 / 5)) + 32) : (Single)(dataTmp.ThermocoupleTemperature + 273.15)); }
/// <summary> /// Reads the temperature from the sensor. /// </summary> /// <param name="source">The source for the measurement.<see cref="TemperatureSources"/></param> /// <returns> /// A single representing the temperature read from the source, degrees Celsius /// </returns> /// <example> /// <code language="C#"> /// // Reads the ambient temperature /// Debug.Print ("Ambient temperature = "+_pres.ReadTemperature()); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { var rawValue = (Int16)ReadInteger(Registers.TEMP_OUT_L); _tempRawData = rawValue; var tempCelsius = (rawValue & 0x8000) == 0x8000 ? (Single)(((-1 * ~rawValue + 1) / 480.0) + 42.5) : (Single)((rawValue / 480.0) + 42.5); return(TemperatureUnit == TemperatureUnits.Celsius ? tempCelsius : TemperatureUnit == TemperatureUnits.Fahrenheit ? (Single)((tempCelsius * (9.0 / 5)) + 32) : (Single)(tempCelsius + 273.15)); }
/// <summary> /// Reads the temperature from the sensor. /// </summary> /// <param name="source">The source of the measurement : either "ambient" temperature or "object" temperature.</param> /// <returns> /// A single representing the temperature read from the source. /// </returns> /// <example> /// <code language="C#"> /// // Reads ambient temperature /// Debug.Print ("Ambient temperature = "+_ir.ReadTemperature()); /// /// // Reads object temperature /// Debug.Print ("Object temperature = "+_ir.ReadTemperature(TemperatureSources.Object)); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { var result = new Byte[3]; lock (_socket.LockI2c) { _ir.WriteRead(new[] { source == TemperatureSources.Ambient ? (Byte)0x06 : (Byte)0x07 }, result); } RawData = (result[1] << 8) + result[0]; var tempCelsius = (Single)((RawData * 0.02) - 273.15); return(TemperatureUnit == TemperatureUnits.Celsius ? tempCelsius : TemperatureUnit == TemperatureUnits.Fahrenheit ? (Single)((tempCelsius * (9.0 / 5)) + 32) : (Single)(tempCelsius + 273.15)); }
/// <summary> /// Reads the temperature from the sensor. /// </summary> /// <param name="source">The source of the measurement : either "ambient" temperature or "object" temperature.</param> /// <returns> /// A single representing the temperature read from the source. /// </returns> /// <example> /// <code language="C#"> /// // Reads ambient temperature /// Debug.Print ("Ambient temperature = "+_ir.ReadTemperature()); /// /// // Reads object temperature /// Debug.Print ("Object temperature = "+_ir.ReadTemperature(TemperatureSources.Object)); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { var result = new byte[3]; var actions = new I2CDevice.I2CTransaction[2]; actions[0] = I2CDevice.CreateWriteTransaction(new [] { source == TemperatureSources.Ambient ? (Byte)0x06 : (Byte)0x07 }); actions[1] = I2CDevice.CreateReadTransaction(result); Hardware.I2CBus.Execute(_config, actions, 1000); RawData = (result[1] << 8) + result[0]; var tempCelsius = (Single)((RawData * 0.02) - 273.15); return(_tempUnit == TemperatureUnits.Celsius ? tempCelsius : _tempUnit == TemperatureUnits.Fahrenheit ? (Single)((tempCelsius * (9.0 / 5)) + 32) : (Single)(tempCelsius + 273.15)); }
/// <summary> /// Return the temperature as read by the BMP180 module. /// </summary> /// <param name="source">The <see cref="TemperatureSources.Ambient"/> to measure.</param> /// <returns>The temperature in the unit specified by the <see cref="TemperatureUnits"/> property.</returns> /// <exception cref="NotImplementedException">A <see cref="NotImplementedException"/> will be thrown the source parameter is <see cref="TemperatureSources.Object"/>. The BMP180 does not support Object temperature measurement.</exception> /// <example>Example usage to read the Temperature: /// <code language = "C#"> /// Debug.Print("Temperature - " + _bmp180.ReadTemperature() + " °C"); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotImplementedException("The BMP180 module does not provide Object temperature measurement. Use TemperatureSources.Ambient for Temperature measurement."); } Int32 ut = (this as ITemperature).RawData; Int32 x1 = ((ut - _ac6) * _ac5) >> 15; Int32 x2 = (_mc << 11) / (x1 + _md); Int32 b5 = x1 + x2; Single temperature = (Single)((b5 + 8) >> 4) / 10; return(ScaleTemperature(temperature)); }
/// <summary> /// Reads the temperature from the sensor. /// </summary> /// <param name="source">The source for the measurement.<see cref="TemperatureSources"/></param> /// <returns> /// A single representing the temperature read from the source, degrees Celsius /// </returns> /// <example> /// <code language="C#"> /// // Reads the ambient temperature /// Debug.Print ("Ambient temperature = "+_pres.ReadTemperature()); /// </code> /// </example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { var rawValue = (Int16)ReadInteger(Registers.TEMP_OUT_L); _tempRawData = rawValue; float tempCelsius; if ((rawValue & 0x8000) == 0x8000) // Sign bit is 1, so use two's complement and negate the result { tempCelsius = (float)(((-1 * ~rawValue + 1) / 480.0) + 42.5); } else { tempCelsius = (float)((rawValue / 480.0) + 42.5); } return(_tempUnit == TemperatureUnits.Celsius ? tempCelsius : _tempUnit == TemperatureUnits.Fahrenheit ? (Single)((tempCelsius * (9.0 / 5)) + 32) : (Single)(tempCelsius + 273.15)); }
/// <summary> /// Reads the temperature from the SHT11 Click. /// </summary> /// <param name="source">The <see cref="TemperatureSources"/> to measure. The SHT11Click only supports <see cref="TemperatureSources.Ambient"/> measurement.</param>> /// <returns> /// A float representing the current temperature read from the SHT11 Click in °C. /// </returns> /// <exception cref="NotImplementedException">Will be raised if sources is <see cref="TemperatureSources.Object"/>.</exception> /// <example>Example usage: /// <code language="C#"> /// Debug.Print("Temperature - " + _sht11Click.ReadTemperature(TemperatureSources.Ambient)); /// </code> /// <code language="VB"> /// Debug.Print("Temperature - " <![CDATA[&]]> _sht11Click.ReadTemperature(TemperatureSources.Ambient)) /// </code> /// </example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotImplementedException("The SHT11 Click does not provide Object temperature measurement. Use TemperatureSources.Ambient for Humidity measurement."); } // determine d2 based on resolution var status = ReadStatusRegister(); var d2 = IsBitSet(status, 0) ? 0.04F : 0.01F; // Determine D1 based on VDD // The following formula (based on the slope of data in Table 8 of the DataSheet) is used to convert digital readout (sot) to actual temperature value. const float d1 = -0.28000000000000113f * VDD + -38.699999999999996f; return(d1 + d2 * ReadRaw(Commands.MeasureTemperature)); }
/// <summary> /// Return the temperature as read by the BMP180 module. /// </summary> /// <param name="source">The <see cref="TemperatureSources.Ambient"/> to measure.</param> /// <returns>The temperature in the unit specified by the <see cref="TemperatureUnit"/> property.</returns> /// <exception cref="NotImplementedException">A <see cref="NotImplementedException"/> will be thrown the source parameter is <see cref="TemperatureSources.Object"/>. The BMP180 does not support Object temperature measurement.</exception> /// <example>Example usage to read the Temperature: /// <code language = "C#"> /// Debug.Print("Temperature - " + _bmp180.ReadTemperature() + " °C"); /// </code> /// <code language = "VB"> /// Debug.Print("Temperature - " <![CDATA[&]]> _bmp180.ReadTemperature() <![CDATA[&]]> " °C") /// </code> /// </example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new NotImplementedException("The BMP180 module does not provide Object temperature measurement. Use TemperatureSources.Ambient for Temperature measurement."); } int ut = (this as ITemperature).RawData; int x1 = (ut - _ac6) * _ac5 >> 15; int x2 = (_mc << 11) / (x1 + _md); int b5 = x1 + x2; var temperature = ((float)((b5 + 8) >> 4)) / 10; return(Utilities.Temperature.ConvertTo(TemperatureUnits.Celsius, _temperatureUnit, temperature)); }
/// <summary> /// Reads the temperature from the HDC1000 Click. /// </summary> /// <param name="source">The <see cref="TemperatureSources"/> to read the Temperature from.</param> /// <returns>The temperature measured in °C.</returns> /// <exception cref="InvalidOperationException"> an InvalidOperationException will be thrown if attempting to read <see cref="TemperatureSources.Object"/> as this module does not support object measurement.</exception> /// <example>Example usage: /// <code language = "C#"> /// Debug.Print("Temperature - " + _tempHumidity.ReadTemperature()); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new InvalidOperationException("Object temperature measurement not supported by the HDC1000 Click"); } _dataAvailable = false; WriteRegister(TempRegister); while (_dataAvailable == false) { } Byte[] readBuffer = ReadRegister(2); Single temperature = (readBuffer[0] << 8) / 65536.0f * 165.0f - 40.0f; return(ConvertToScale(temperature)); }
/// <summary> /// Reads the temperature from the TempHum11 Click. /// </summary> /// <param name="source">The <see cref="TemperatureSources" /> to read the Temperature from.</param> /// <returns>The temperature measured in the unit specified in the TemperatureUnits property. Defaults to °C.</returns> /// <exception cref="InvalidOperationException"> /// an InvalidOperationException will be thrown if attempting to read /// <see cref="TemperatureSources.Object" /> as this module does not support object measurement. /// </exception> /// <example> /// Example usage: /// <code language="C#"> /// Debug.WriteLine("Temperature - " + _tempHumidity.ReadTemperature()); /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { if (source == TemperatureSources.Object) { throw new InvalidOperationException( "Object temperature measurement not supported by the TempHum11 Click"); } if (_acquisitionMode == AcquisitionMode.Sequential) { throw new ApplicationException( "You cannot read temperature independantly while Acquisition Mode is set for sequential access."); } WriteByte(TempRegister); Thread.Sleep(15); Byte[] readBuffer = ReadBytes(2); Single temperature = (Single)((readBuffer[0] << 8) / 65536.0 * 165.0 - 40.0); return(ConvertToScale(temperature)); }
/// <inheritdoc cref="ITemperature" /> /// <summary> /// Reads the temperature from the altitude3 Click. /// </summary> /// <param name="source">The <see cref="TemperatureSources"/> of which to measure.</param> /// <exception cref="NotImplementedException">A NotImplementedException will be thrown if attempting to read the temperature as this driver does not implement direct reading of temperature. Use the ReadSensor method instead.</exception> /// <example> /// Example usage: /// <code language="C#"> /// // None provided as this driver does not implement direct reading of temperature. Use the <exception cref="ReadSensor"> method instead.</exception> /// </code> /// <code language="VB"> /// ' None provided as this driver does not implement direct reading of temperature. Use the <exception cref="ReadSensor"> method instead.</exception> /// </code> /// </example> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { throw new NotImplementedException("Reading of temperature is not supported in this driver. Use ReadSensor method instead."); }
/// <summary> /// Reads the Temperature /// </summary> /// <param name="source">The <see cref="TemperatureSources"/> to use.</param> /// <exception cref="NotSupportedException">A NotSupportedException will be thrown if attempting to read the temperature with this method. /// Direct reading of temperature is not supported with this module. Use the <see cref="ReadSensor"/> method instead. /// </exception> public Single ReadTemperature(TemperatureSources source) { throw new NotSupportedException("This modules does not support direct reading of raw temperature data."); }
/// <summary> /// Reads the temperature. /// </summary> /// <param name="source">The source.</param> /// <exception cref="NotImplementedException">Not supported by this sensor.</exception> /// <returns>A single representing the temperature read from the source, degrees Celsius</returns> /// <example>None: Not supported.</example> public float ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { throw new NotImplementedException("This module does not support direct measurement of Temperature."); }
/// <inheritdoc /> /// <summary>Reads the temperature.</summary> /// <param name="source">The source.</param> /// <returns>A single representing the temperature read from the source, degrees Celsius</returns> /// <example> /// Example usage /// <code language="C#">// None provided as this module does not support reading raw data.</code> /// <code language="VB">'None provided as this module does not support reading raw data.</code> /// None provided as this module does not support reading raw data. /// </example> /// <exception cref="NotSupportedException"> /// A NotSupported Exception will be thrown when attempting to read Temperature as /// this module does not support direct reading of teperature. /// </exception> public Single ReadTemperature(TemperatureSources source = TemperatureSources.Ambient) { throw new NotSupportedException("Direct reading of temperature is not supported by this driver. Please "); }