Class OneWireContainer28

  • All Implemented Interfaces:
    OneWireSensor, TemperatureContainer
    Direct Known Subclasses:
    OneWireContainer22

    public class OneWireContainer28
    extends OneWireContainer
    implements TemperatureContainer

    1-Wire container for temperature iButton which measures temperatures from -55@htmlonly °C @endhtmlonly to +125@htmlonly °C @endhtmlonly, DS18B20. This container encapsulates the functionality of the iButton family type 28 (hex)

    Features

    • Measures temperatures from -55@htmlonly °C @endhtmlonly to +125@htmlonly °C @endhtmlonly. Fahrenheit equivalent is -67@htmlonly °F @endhtmlonly to +257@htmlonly °F @endhtmlonly
    • Power supply range is 3.0V to 5.5V
    • Zero standby power
    • +/- 0.5@htmlonly °C @endhtmlonly accuracy from -10@htmlonly °C @endhtmlonly to +85@htmlonly °C @endhtmlonly
    • Thermometer resolution programmable from 9 to 12 bits
    • Converts 12-bit temperature to digital word in 750 ms (max.)
    • User-definable, nonvolatile temperature alarm settings
    • Alarm search command identifies and addresses devices whose temperature is outside of programmed limits (temperature alarm condition)

    Usage

    See the usage example in TemperatureContainer for temperature specific operations.

    DataSheet

    http://pdfserv.maxim-ic.com/arpdf/DS18B20.pdf
    See Also:
    TemperatureContainer
    • Field Detail

      • WRITE_SCRATCHPAD_COMMAND

        public static final byte WRITE_SCRATCHPAD_COMMAND
        DS18B20 writes data to scratchpad command
        See Also:
        Constant Field Values
      • READ_SCRATCHPAD_COMMAND

        public static final byte READ_SCRATCHPAD_COMMAND
        DS18B20 reads data from scratchpad command
        See Also:
        Constant Field Values
      • COPY_SCRATCHPAD_COMMAND

        public static final byte COPY_SCRATCHPAD_COMMAND
        DS18B20 copies data from scratchpad to E-squared memory command
        See Also:
        Constant Field Values
      • CONVERT_TEMPERATURE_COMMAND

        public static final byte CONVERT_TEMPERATURE_COMMAND
        DS18B20 converts temperature command
        See Also:
        Constant Field Values
      • RECALL_E2MEMORY_COMMAND

        public static final byte RECALL_E2MEMORY_COMMAND
        DS18B20 recalls E-squared memory command
        See Also:
        Constant Field Values
      • READ_POWER_SUPPLY_COMMAND

        public static final byte READ_POWER_SUPPLY_COMMAND
        DS18B20 reads power supply command. This command is used to determine if external power is supplied.
        See Also:
        Constant Field Values
      • RESOLUTION_12_BIT

        public static final byte RESOLUTION_12_BIT
        DS18B20 12-bit resolution constant for CONFIG byte
        See Also:
        Constant Field Values
      • RESOLUTION_11_BIT

        public static final byte RESOLUTION_11_BIT
        DS18B20 11-bit resolution constant for CONFIG byte
        See Also:
        Constant Field Values
      • RESOLUTION_10_BIT

        public static final byte RESOLUTION_10_BIT
        DS18B20 10-bit resolution constant for CONFIG byte
        See Also:
        Constant Field Values
      • RESOLUTION_9_BIT

        public static final byte RESOLUTION_9_BIT
        DS18B20 9-bit resolution constant for CONFIG byte
        See Also:
        Constant Field Values
    • Method Detail

      • getName

        public java.lang.String getName()
        Retrieves the Maxim Integrated Products part number of this OneWireContainer28 as a String. For example 'DS18B20'.
        Overrides:
        getName in class OneWireContainer
        Returns:
        this OneWireContainer28 name
      • getAlternateNames

        public java.lang.String getAlternateNames()
        Retrieves the alternate Maxim Integrated Products part numbers or names. A 'family' of 1-Wire Network devices may have more than one part number depending on packaging. There can also be nicknames such as 'Crypto iButton'.
        Overrides:
        getAlternateNames in class OneWireContainer
        Returns:
        this OneWireContainer28 alternate names
      • getDescription

        public java.lang.String getDescription()
        Retrieves a short description of the function of this OneWireContainer28 type.
        Overrides:
        getDescription in class OneWireContainer
        Returns:
        OneWireContainer28 functional description
      • doTemperatureConvert

        public void doTemperatureConvert​(byte[] state)
                                  throws OneWireIOException,
                                         OneWireException
        Performs a temperature conversion on state information.
        Specified by:
        doTemperatureConvert in interface TemperatureContainer
        Parameters:
        state - byte array with device state information
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
        See Also:
        getTemperature(byte[])
      • getTemperature

        public double getTemperature​(byte[] state)
                              throws OneWireIOException
        Gets the temperature value in Celsius from the state data retrieved from the readDevice() method.
        Specified by:
        getTemperature in interface TemperatureContainer
        Parameters:
        state - byte array with device state information for this OneWireContainer28
        Returns:
        temperature in Celsius from the last doTemperatureConvert()
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        See Also:
        doTemperatureConvert(byte[])
      • getTemperatureAlarm

        public double getTemperatureAlarm​(int alarmType,
                                          byte[] state)
        Gets the specified temperature alarm value in Celsius from the state data retrieved from the readDevice() method.
        Specified by:
        getTemperatureAlarm in interface TemperatureContainer
        Parameters:
        alarmType - valid value: ALARM_HIGH or ALARM_LOW
        state - byte array with device state information
        Returns:
        temperature alarm trip values in Celsius for this OneWireContainer28
        See Also:
        hasTemperatureAlarms(), setTemperatureAlarm(int, double, byte[])
      • readDevice

        public byte[] readDevice()
                          throws OneWireIOException,
                                 OneWireException
        Retrieves this OneWireContainer28 state information. The state information is returned as a byte array. Pass this byte array to the 'get' and 'set' methods. If the device state needs to be changed, then call the writeDevice() to finalize the changes.
        Specified by:
        readDevice in interface OneWireSensor
        Returns:
        OneWireContainer28 state information. Device state looks like this:
           0 : temperature LSB
           1 : temperature MSB
           2 : trip high
           3 : trip low
           4 : configuration register (for resolution)
           5 : reserved
           6 : reserved
           7 : reserved
           8 : an 8 bit CRC of the previous 8 bytes
                 
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
        See Also:
        writeDevice(byte[])
      • writeDevice

        public void writeDevice​(byte[] state)
                         throws OneWireIOException,
                                OneWireException
        Writes to this OneWireContainer28 state information that have been changed by 'set' methods. Only the state registers that changed are updated. This is done by referencing a field information appended to the state data.
        Specified by:
        writeDevice in interface OneWireSensor
        Parameters:
        state - byte array with device state information
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
        See Also:
        readDevice()
      • readScratchpad

        public byte[] readScratchpad()
                              throws OneWireIOException,
                                     OneWireException
        Reads the Scratchpad of the DS18B20.
        Returns:
        9-byte buffer representing the scratchpad
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
      • writeScratchpad

        public void writeScratchpad​(byte[] data)
                             throws OneWireIOException,
                                    OneWireException
        Writes to the Scratchpad of the DS18B20.
        Parameters:
        data - data to be written to the scratchpad. First byte of data must be the temperature High Trip Point, the second byte must be the temperature Low Trip Point, and the third must be the Resolution (configuration register).
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
        java.lang.IllegalArgumentException - when data is of invalid length
      • copyScratchpad

        public void copyScratchpad()
                            throws OneWireIOException,
                                   OneWireException
        Copies the Scratchpad to the E-squared memory of the DS18B20.
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
      • recallE2

        public byte[] recallE2()
                        throws OneWireIOException,
                               OneWireException
        Recalls the DS18B20 temperature trigger values (ALARM_HIGH and ALARM_LOW) and the configuration register to the scratchpad and reads the scratchpad.
        Returns:
        byte array representing data in the device's scratchpad.
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
      • isExternalPowerSupplied

        public boolean isExternalPowerSupplied()
                                        throws OneWireIOException,
                                               OneWireException
        Reads the way power is supplied to the DS18B20.
        Returns:
        true for external power,
        false for parasite power
        Throws:
        OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from this OneWireContainer28. This could be caused by a physical interruption in the 1-Wire Network due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
        OneWireException - on a communication or setup error with the 1-Wire adapter
      • convertToFahrenheit

        public float convertToFahrenheit​(float celsiusTemperature)
        Deprecated.
        Replace with call to com.dalsemi.onewire.utils.Convert.toFahrenheit()
        Converts a temperature reading from Celsius to Fahrenheit.
        Parameters:
        celsiusTemperature - temperature value in Celsius
        Returns:
        the Fahrenheit conversion of the supplied temperature
        See Also:
        Convert.toFahrenheit(double)