com.dalsemi.onewire.container
Class OneWireContainer20

java.lang.Object
  |
  +--com.dalsemi.onewire.container.OneWireContainer
        |
        +--com.dalsemi.onewire.container.OneWireContainer20
All Implemented Interfaces:
ADContainer, OneWireSensor

public class OneWireContainer20
extends OneWireContainer
implements ADContainer

iButton container for iButton family type 20 (hex). The DS2450 is a Quad A\D converter.

WARNING! When converting Analog voltages to digital, the user of the device must gaurantee that the voltage seen by the channel of the quad a\d does not exceed the selected input range of the device. If this happens, the device will default to reading 0 volts. The is NO way to know if the device is reading a higher than specified voltage or NO voltage.

Typical Setup:

Typical Read voltage:

Version:
0.00, 28 Aug 2000

Field Summary
static int ALARM_OFFSET
          Offset of ALARMS in array returned from read state
static int BITMAP_OFFSET
          Offset of BITMAP in array returned from read state
static int CHANNELA
          Channel A number
static int CHANNELB
          Channel B number
static int CHANNELC
          Channel C number
static int CHANNELD
          Channel D number
static int EXPOWER_OFFSET
          Offset of external power offset in array returned from read state
static int NO_PRESET
          No preset value
static int NUM_CHANNELS
          Number of channels
static int PRESET_TO_ONES
          Preset value to ones
static int PRESET_TO_ZEROS
          Preset value to zeros
 
Fields inherited from interface com.dalsemi.onewire.container.ADContainer
ALARM_HIGH, ALARM_LOW
 
Constructor Summary
OneWireContainer20()
          Default constructor
OneWireContainer20(DSPortAdapter sourceAdapter, byte[] newAddress)
          Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
OneWireContainer20(DSPortAdapter sourceAdapter, long newAddress)
          Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
OneWireContainer20(DSPortAdapter sourceAdapter, java.lang.String newAddress)
          Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
 
Method Summary
 boolean canADMultiChannelRead()
          Query to see if this A/D supports doing multiple voltage conversions at the same time.
 void doADConvert(boolean[] doConvert, byte[] state)
          This method is used to perform voltage conversion on all specified channels.
 void doADConvert(boolean[] doConvert, int[] preset, byte[] state)
          This method is used to perform voltage conversion on all specified channels.
 void doADConvert(int channel, byte[] state)
          This method is used to perform voltage conversion on all specified channels.
 void doADConvert(int channel, int preset, byte[] state)
          This method is used to perform voltage conversion on all specified channels.
 double getADAlarm(int channel, int alarmType, byte[] state)
          This method is used to extract the alarm voltage value of the specified channel from the provided state buffer.
 boolean getADAlarmEnable(int channel, int alarmType, byte[] state)
          This method is used to extract the alarm enable value of the specified channel from the provided state buffer.
 double getADRange(int channel, byte[] state)
          This method is used to extract the input voltage range of the specified channel from the provided state buffer.
 double[] getADRanges(int channel)
          Query to get an array of available ranges for the specified A/D channel.
 double getADResolution(int channel, byte[] state)
          This method is used to extract the conversion resolution of the specified channel from the provided state buffer expressed in volts.
 double[] getADResolutions(int channel, double range)
          Query to get an array of available resolutions based on the specified range on the specified A/D channel.
 double[] getADVoltage(byte[] state)
          This method is used to read the voltage values.
 double getADVoltage(int channel, byte[] state)
          This method is used to read a channels voltage value.
 java.lang.String getAlternateNames()
          getAlternateNames returns any other possible name for this iButton.
 java.lang.String getDescription()
          getDescription returns a String that contains a brief description of the functionalitly of this iButton.
 boolean getDevicePOR(byte[] state)
          This method is used to detect if the device has seen a Power-On-Reset (POR).
 int getMaxSpeed()
          Returns the maximum speed this iButton can communicate at.
 java.util.Enumeration getMemoryBanks()
          Return an enumeration of memory banks.
 java.lang.String getName()
          getName returns the name of the iButton that this class contains.
 int getNumberADChannels()
          Query to get the number of channels supported by this A/D.
 boolean getOutputState(int channel, byte[] state)
          This method is used to detect if the output is enabled for the specified channel from the provided register buffer.
 boolean hasADAlarmed(int channel, int alarmType, byte[] state)
          This method is used to check the alarm event value of the specified channel from the provided state buffer.
 boolean hasADAlarms()
          Query to see if this A/D measuring device has high/low alarms.
static double interpretVoltage(long rawVoltage, double range)
          This method is used to convert a raw voltage long value for the DS2450 into a valid voltage.
 boolean isOutputEnabled(int channel, byte[] state)
          This method is used to detect if the output is enabled for the specified channel from the provided register buffer.
 boolean isPowerExternal(byte[] state)
          This method is used to extract the state of the external power indicator from the provided register buffer.
 byte[] readDevice()
          This method retrieves the entire A/D control/status and alarm pages.
 void setADAlarm(int channel, int alarmType, double alarm, byte[] state)
          This method is used to set the alarm voltage value of the specified channel in the provided state buffer.
 void setADAlarmEnable(int channel, int alarmType, boolean alarmEnable, byte[] state)
          This method is used to set the alarm enable value of the specified channel in the provided state buffer.
 void setADRange(int channel, double range, byte[] state)
          This method is used to set the input range for the specified channel in the provided state buffer.
 void setADResolution(int channel, double resolution, byte[] state)
          This method is used to set the conversion resolution value for the specified channel in the provided state buffer.
 void setOutput(int channel, boolean outputEnable, boolean outputState, byte[] state)
          This method is used to set the output enable and state for the specified channel in the provided register buffer.
 void setPower(boolean external, byte[] state)
          This method is used to set or clear the external power flag in the provided register buffer.
static int voltageToInt(double voltage, double range)
          This method is used to convert a voltage double value to the DS2450 specific int value.
 void writeDevice(byte[] state)
          This method write the bytes in the provided A/D register pages that have been changed by the 'set' methods.
 
Methods inherited from class com.dalsemi.onewire.container.OneWireContainer
doSpeed, getAdapter, getAddress, getAddressAsLong, getAddressAsString, isAlarming, isPresent, setSpeed, setupContainer, setupContainer, setupContainer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BITMAP_OFFSET

public static final int BITMAP_OFFSET
Offset of BITMAP in array returned from read state

ALARM_OFFSET

public static final int ALARM_OFFSET
Offset of ALARMS in array returned from read state

EXPOWER_OFFSET

public static final int EXPOWER_OFFSET
Offset of external power offset in array returned from read state

CHANNELA

public static final int CHANNELA
Channel A number

CHANNELB

public static final int CHANNELB
Channel B number

CHANNELC

public static final int CHANNELC
Channel C number

CHANNELD

public static final int CHANNELD
Channel D number

NO_PRESET

public static final int NO_PRESET
No preset value

PRESET_TO_ZEROS

public static final int PRESET_TO_ZEROS
Preset value to zeros

PRESET_TO_ONES

public static final int PRESET_TO_ONES
Preset value to ones

NUM_CHANNELS

public static final int NUM_CHANNELS
Number of channels
Constructor Detail

OneWireContainer20

public OneWireContainer20()
Default constructor

OneWireContainer20

public OneWireContainer20(DSPortAdapter sourceAdapter,
                          byte[] newAddress)
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
Parameters:
sourceAdapter - adapter object required to communicate with this iButton.
newAddress - address of this 1-Wire device

OneWireContainer20

public OneWireContainer20(DSPortAdapter sourceAdapter,
                          long newAddress)
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
Parameters:
sourceAdapter - adapter object required to communicate with this iButton.
newAddress - address of this 1-Wire device

OneWireContainer20

public OneWireContainer20(DSPortAdapter sourceAdapter,
                          java.lang.String newAddress)
Create a container with a provided adapter object and the address of the iButton or 1-Wire device.
Parameters:
sourceAdapter - adapter object required to communicate with this iButton.
newAddress - address of this 1-Wire device
Method Detail

getName

public java.lang.String getName()
getName returns the name of the iButton that this class contains.
Overrides:
getName in class OneWireContainer
Returns:
String representation of the iButtons name

getAlternateNames

public java.lang.String getAlternateNames()
getAlternateNames returns any other possible name for this iButton.
Overrides:
getAlternateNames in class OneWireContainer
Returns:
String representation of the iButtons other names

getDescription

public java.lang.String getDescription()
getDescription returns a String that contains a brief description of the functionalitly of this iButton.
Overrides:
getDescription in class OneWireContainer
Returns:
String containing a description of the functionalitly

getMaxSpeed

public int getMaxSpeed()
Returns the maximum speed this iButton can communicate at.
Overrides:
getMaxSpeed in class OneWireContainer

getMemoryBanks

public java.util.Enumeration getMemoryBanks()
Return an enumeration of memory banks. Look at the MemoryBank, PagedMemoryBank and OTPMemoryBank classes.
Overrides:
getMemoryBanks in class OneWireContainer
Following copied from class: com.dalsemi.onewire.container.OneWireContainer
Returns:
enumeration of memory banks to read and write memory on this iButton or 1-Wire device.

getNumberADChannels

public int getNumberADChannels()
Query to get the number of channels supported by this A/D. Channel specific methods will use a channel number specified by an integer from [0 to (getNumberChannels() - 1)].
Specified by:
getNumberADChannels in interface ADContainer
Returns:
int containing the number of channels

hasADAlarms

public boolean hasADAlarms()
Query to see if this A/D measuring device has high/low alarms.
Specified by:
hasADAlarms in interface ADContainer
Returns:
boolean, true if has high/low trips

getADRanges

public double[] getADRanges(int channel)
Query to get an array of available ranges for the specified A/D channel.
Specified by:
getADRanges in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
Returns:
array of double indicated the available ranges starting from the largest range to the smallest range.

getADResolutions

public double[] getADResolutions(int channel,
                                 double range)
Query to get an array of available resolutions based on the specified range on the specified A/D channel.
Specified by:
getADResolutions in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
range -  
Returns:
array of double, indicated the available resolutions

canADMultiChannelRead

public boolean canADMultiChannelRead()
Query to see if this A/D supports doing multiple voltage conversions at the same time.
Specified by:
canADMultiChannelRead in interface ADContainer
Returns:
boolean, true if can do multi-channel voltage reads.

readDevice

public byte[] readDevice()
                  throws OneWireIOException,
                         OneWireException
This method retrieves the entire A/D control/status and alarm pages. It reads this and verifies the data with the onboard CRC generator. Use the byte array return from this method with static utility methods to extract the status, alarm and other register values. Appended to the data is 2 bytes that represent a bitmap of changed bytes. These bytes are used in the 'writeADRegisters()' in conjuction with the 'set' methods to only write back the changed register bytes.
Specified by:
readDevice in interface OneWireSensor
Returns:
byte[]<\code> register page contents verified with onboard CRC
Throws:
OneWireIOException -  
OneWireException -  

writeDevice

public void writeDevice(byte[] state)
                 throws OneWireIOException,
                        OneWireException
This method write the bytes in the provided A/D register pages that have been changed by the 'set' methods. It knows which state has changed by looking at the bitmap fields appended to the register data. Any alarm flags will be automatically cleared. Only VCC powered indicator byte in physical location 0x1C can be written in the calibration memory bank.
Specified by:
writeDevice in interface OneWireSensor
Parameters:
state - - byte array of register pages
Throws:
OneWireIOException -  
OneWireException -  

getADVoltage

public double[] getADVoltage(byte[] state)
                      throws OneWireIOException,
                             OneWireException
This method is used to read the voltage values. Must be used after a 'doADConvert()' method call. Also must include the last valid state from the 'readDevice()' method and this A/D must support multi-channel read 'canMultiChannelRead()' if there are more then 1 channel.
Specified by:
getADVoltage in interface ADContainer
Parameters:
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- double[] representing the voltage values for all channels
Throws:
OneWireIOException -  
OneWireException -  

getADVoltage

public double getADVoltage(int channel,
                           byte[] state)
                    throws OneWireIOException,
                           OneWireException
This method is used to read a channels voltage value. Must be used after a 'doADConvert()' method call. Also must include the last valid state from the 'readDevice()' method. Note, if more then one channel is to be read then it is more efficient to use the 'getVoltage()' method that returns all channel values.
Specified by:
getADVoltage in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- double representing the voltage value for the specified channel
Throws:
OneWireIOException -  
OneWireException -  

doADConvert

public void doADConvert(int channel,
                        byte[] state)
                 throws OneWireIOException,
                        OneWireException
This method is used to perform voltage conversion on all specified channels. The method 'getVoltage()' can be used to read the result of the conversion.
Specified by:
doADConvert in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the device returned from 'readDevice()'.
Throws:
OneWireIOException -  
OneWireException -  

doADConvert

public void doADConvert(boolean[] doConvert,
                        byte[] state)
                 throws OneWireIOException,
                        OneWireException
This method is used to perform voltage conversion on all specified channels. The method 'getVoltage()' can be used to read the result of the conversion. This A/D must support multi-channel read 'canMultiChannelRead()' if there are more then 1 channel is specified.
Specified by:
doADConvert in interface ADContainer
Parameters:
doConvert - - boolean array representing which channels to perform conversion on.
state - - byte array of the current state of the device returned from 'readDevice()'.
Throws:
OneWireIOException -  
OneWireException -  

doADConvert

public void doADConvert(int channel,
                        int preset,
                        byte[] state)
                 throws OneWireIOException,
                        OneWireException,
                        java.lang.IllegalArgumentException
This method is used to perform voltage conversion on all specified channels. The method 'getVoltage()' can be used to read the result of the conversion.
Parameters:
channel - - integer 0,1,2,3 representing the channels A,B,C,D.
preset - - int representing the preset value: NO_PRESET (0), PRESET_TO_ZEROS (1), and PRESET_TO_ONES (2).
state - - byte array of the current state of the device returned from 'readDevice()'.
Throws:
OneWireIOException -  
OneWireException -  
java.lang.IllegalArgumentException -  

doADConvert

public void doADConvert(boolean[] doConvert,
                        int[] preset,
                        byte[] state)
                 throws OneWireIOException,
                        OneWireException
This method is used to perform voltage conversion on all specified channels. The method 'getVoltage()' can be used to read the result of the conversion.
Parameters:
doConvert - - boolean array representing which channels to perform conversion on.
preset - - int array representing the preset values: NO_PRESET (0), PRESET_TO_ZEROS (1), and PRESET_TO_ONES (2).
state - - byte array of the current state of the device returned from 'readDevice()'.
Throws:
OneWireIOException -  
OneWireException -  

getADAlarm

public double getADAlarm(int channel,
                         int alarmType,
                         byte[] state)
This method is used to extract the alarm voltage value of the specified channel from the provided state buffer. The state buffer is retrieved from the 'readDevice()' method.
Specified by:
getADAlarm in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
alarmType - - int, representing the desired alarm, ALARM_HIGH (1) or ALARM_LOW (0)
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- double representing the alarm_value in volts

getADAlarmEnable

public boolean getADAlarmEnable(int channel,
                                int alarmType,
                                byte[] state)
This method is used to extract the alarm enable value of the specified channel from the provided state buffer. The state buffer is retrieved from the 'readDevice()' method.
Specified by:
getADAlarmEnable in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
alarmType - - int, representing the desired alarm, ALARM_HIGH (1) or ALARM_LOW (0)
state - - byte array of the current state of the state returned from 'readDevice()'.
Returns:
- boolean, true if specified alarm is enabled

hasADAlarmed

public boolean hasADAlarmed(int channel,
                            int alarmType,
                            byte[] state)
This method is used to check the alarm event value of the specified channel from the provided state buffer. The state buffer is retrieved from the 'readDevice()' method.
Specified by:
hasADAlarmed in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
alarmType - - int, representing the desired alarm, ALARM_HIGH (1) or ALARM_LOW (0)
state - - byte array of the current state of the state returned from 'readDevice()'.
Returns:
- boolean, true if specified alarm occurred

getADResolution

public double getADResolution(int channel,
                              byte[] state)
This method is used to extract the conversion resolution of the specified channel from the provided state buffer expressed in volts. The state is retrieved from the 'readDevice()' method.
Specified by:
getADResolution in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the state returned from 'readDevice()'.
Returns:
- double, resolution of channel in volts

getADRange

public double getADRange(int channel,
                         byte[] state)
This method is used to extract the input voltage range of the specified channel from the provided state buffer. The state buffer is retrieved from the 'readDevice()' method.
Specified by:
getADRange in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the state returned from 'readDevice()'.
Returns:
- double representing the input voltage range

isOutputEnabled

public boolean isOutputEnabled(int channel,
                               byte[] state)
                        throws java.lang.IllegalArgumentException
This method is used to detect if the output is enabled for the specified channel from the provided register buffer. The register buffer is retrieved from the 'readDevice()' method.
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- boolean, true if output is enabled on specified channel
Throws:
java.lang.IllegalArgumentException -  

getOutputState

public boolean getOutputState(int channel,
                              byte[] state)
                       throws java.lang.IllegalArgumentException
This method is used to detect if the output is enabled for the specified channel from the provided register buffer. The register buffer is retrieved from the 'readDevice()' method.
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- boolean, false if output is conducting to ground and true not conducting.
Throws:
java.lang.IllegalArgumentException -  

getDevicePOR

public boolean getDevicePOR(byte[] state)
This method is used to detect if the device has seen a Power-On-Reset (POR). If this has occured it may be necessary set the state of the device to the desired values. The register buffer is retrieved from the 'readDevice()' method.
Parameters:
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- boolean, false if output is conducting to ground and true not conducting.

isPowerExternal

public boolean isPowerExternal(byte[] state)
This method is used to extract the state of the external power indicator from the provided register buffer. Use 'setPower' to set or clear the external power indicator flag. The register buffer is retrieved from the 'readDevice()' method.
Parameters:
state - - byte array of the current state of the device returned from 'readDevice()'.
Returns:
- boolean, true if set to external power operation.

setADAlarm

public void setADAlarm(int channel,
                       int alarmType,
                       double alarm,
                       byte[] state)
This method is used to set the alarm voltage value of the specified channel in the provided state buffer. The state buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Specified by:
setADAlarm in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
alarmType - - int, representing the desired alarm, ALARM_HIGH (1) or ALARM_LOW (0)
alarm - - double, alarm value (will be reduced to 8 bit resolution).
state - - byte array of the current state of the device returned from 'readDevice()'.

setADAlarmEnable

public void setADAlarmEnable(int channel,
                             int alarmType,
                             boolean alarmEnable,
                             byte[] state)
This method is used to set the alarm enable value of the specified channel in the provided state buffer. The state buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Specified by:
setADAlarmEnable in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
alarmType - - int, representing the desired alarm, ALARM_HIGH (1) or ALARM_LOW (0)
alarmEnable - - boolean, alarm enable value
state - - byte array of the current state of the device returned from 'readDevice()'.

setADResolution

public void setADResolution(int channel,
                            double resolution,
                            byte[] state)
This method is used to set the conversion resolution value for the specified channel in the provided state buffer. The state buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Specified by:
setADResolution in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
resolution - - double, resolution to use in volts
state - - byte array of the current state of the device returned from 'readDevice()'.

setADRange

public void setADRange(int channel,
                       double range,
                       byte[] state)
This method is used to set the input range for the specified channel in the provided state buffer. The state buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Specified by:
setADRange in interface ADContainer
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
range - - double, representing the max volt range, use 'getRanges()' method to get available ranges
state - - byte array of the current state of the device returned from 'readDevice()'.

setOutput

public void setOutput(int channel,
                      boolean outputEnable,
                      boolean outputState,
                      byte[] state)
This method is used to set the output enable and state for the specified channel in the provided register buffer. The register buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Parameters:
channel - - integer specifying channel in the range [0 to (getNumberChannels() - 1)].
outputEnable - - boolean, true if output is enabled
outputState - - boolean, false if output is conducting to ground and true not conducting. This parameter is not used if outputEnable is false.
state - - byte array of the current state of the device returned from 'readDevice()'.

setPower

public void setPower(boolean external,
                     byte[] state)
This method is used to set or clear the external power flag in the provided register buffer. The register buffer is retrieved from the 'readDevice()' method. The method 'writeDevice()' must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call to 'writeDevice()'.
Parameters:
external - - boolean, true if setting external power is used
state - - byte array of the current state of the device returned from 'readDevice()'.

interpretVoltage

public static double interpretVoltage(long rawVoltage,
                                      double range)
This method is used to convert a raw voltage long value for the DS2450 into a valid voltage. Requires the max voltage value.
Parameters:
rawVoltage - - long of the raw voltage
range - - max voltage
Returns:
- float representing the calculated voltage based on the range

voltageToInt

public static int voltageToInt(double voltage,
                               double range)
This method is used to convert a voltage double value to the DS2450 specific int value. Requires the max voltage value.
Parameters:
rawVoltage - - long of the raw voltage
voltage -  
range - - max voltage
Returns:
- int representing the DS2450 voltage