Package com.dalsemi.onewire.container
Class OneWireContainer20
java.lang.Object
com.dalsemi.onewire.container.OneWireContainer
com.dalsemi.onewire.container.OneWireContainer20
- All Implemented Interfaces:
ADContainer
,OneWireSensor
1-Wire® container that encapsulates the functionality of the 1-Wire family type 20 (hex), Maxim Integrated Products part number: DS2450, 1-Wire Quad A/D Converter.
Features
- Four high-impedance inputs
- Programmable input range (2.56V, 5.12V), resolution (1 to 16 bits) and alarm thresholds
- 5V, single supply operation
- Very low power, 2.5 mW active, 25 @htmlonly invalid input: 'µ'W @endhtmlonly idle
- Unused analog inputs can serve as open drain digital outputs for closed-loop control
- Operating temperature range from -40@htmlonly invalid input: '°'C @endhtmlonly to +85@htmlonly invalid input: '°'C @endhtmlonly
Usage
Example device setup
byte[] state = owd.readDevice();
owd.setResolution(OneWireContainer20.CHANNELA, 16, state);
owd.setResolution(OneWireContainer20.CHANNELB, 8, state);
owd.setRange(OneWireContainer20.CHANNELA, 5.12, state);
owd.setRange(OneWireContainer20.CHANNELB, 2.56, state);
owd.writeDevice();
Example device read
owd.doADConvert(OneWireContainer20.CHANNELA, state);
owd.doADConvert(OneWireContainer20.CHANNELB, state);
double chAVolatge = owd.getADVoltage(OneWireContainer20.CHANNELA, state);
double chBVoltage = owd.getADVoltage(OneWireContainer20.CHANNELB, state);
Note
When converting analog voltages to digital, the user of the device must guarantee 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. There is NO way to know if the device is reading a higher than specified voltage or NO voltage.
DataSheet
http://pdfserv.maxim-ic.com/arpdf/DS2450.pdf-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Offset of ALARMS in array returned from read statestatic final int
Offset of BITMAP in array returned from read statestatic final int
Channel A numberstatic final int
Channel B numberstatic final int
Channel C numberstatic final int
Channel D numberstatic final int
Offset of external power offset in array returned from read statestatic final int
No preset valuestatic final int
Number of channelsstatic final int
Preset value to onesstatic final int
Preset value to zerosFields inherited from class com.dalsemi.onewire.container.OneWireContainer
adapter, address, speed, speedFallBackOK
Fields inherited from interface com.dalsemi.onewire.container.ADContainer
ALARM_HIGH, ALARM_LOW
-
Constructor Summary
ConstructorDescriptionDefault constructorOneWireContainer20
(DSPortAdapter sourceAdapter, byte[] newAddress) Creates a container with a provided adapter object and the address of the 1-Wire device.OneWireContainer20
(DSPortAdapter sourceAdapter, long newAddress) Creates a container with a provided adapter object and the address of the 1-Wire device.OneWireContainer20
(DSPortAdapter sourceAdapter, String newAddress) Creates a container with a provided adapter object and the address of the 1-Wire device. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Queries to see if this A/D supports doing multiple voltage conversions at the same time.void
doADConvert
(boolean[] doConvert, byte[] state) Performs voltage conversion on all specified channels.void
doADConvert
(boolean[] doConvert, int[] preset, byte[] state) Performs voltage conversion on all specified channels.void
doADConvert
(int channel, byte[] state) Performs voltage conversion on specified channel.void
doADConvert
(int channel, int preset, byte[] state) Performs voltage conversion on specified channel.double
getADAlarm
(int channel, int alarmType, byte[] state) Extracts the alarm voltage value of the specified channel from the provided state buffer.boolean
getADAlarmEnable
(int channel, int alarmType, byte[] state) Extracts the alarm enable value of the specified channel from the provided state buffer.double
getADRange
(int channel, byte[] state) Extracts the input voltage range of the specified channel from the provided state buffer.double[]
getADRanges
(int channel) Queries to get an array of available ranges for the specified A/D channel.double
getADResolution
(int channel, byte[] state) Extracts the conversion resolution of the specified channel from the provided state buffer expressed in volts.double[]
getADResolutions
(int channel, double range) Queries to get an array of available resolutions based on the specified range on the specified A/D channel.double[]
getADVoltage
(byte[] state) Reads the voltage values.double
getADVoltage
(int channel, byte[] state) Reads a channels voltage value.Gets any other possible names for this 1-Wire device.Gets a brief description of the functionality of this 1-Wire device.boolean
getDevicePOR
(byte[] state) Detects if this device has seen a Power-On-Reset (POR).int
Gets the maximum speed this 1-Wire device can communicate at.Gets an enumeration of memory banks.getName()
Gets the name of this 1-Wire device.int
Queries to get the number of channels supported by this A/D.boolean
getOutputState
(int channel, byte[] state) Detects if the output is enabled for the specified channel from the provided register buffer.boolean
hasADAlarmed
(int channel, int alarmType, byte[] state) Checks the alarm event value of the specified channel from the provided state buffer.boolean
Queries to see if this A/D measuring device has high/low alarms.static double
interpretVoltage
(long rawVoltage, double range) Converts a raw voltage long value for the DS2450 into a valid voltage.boolean
isOutputEnabled
(int channel, byte[] state) Detects if the output is enabled for the specified channel from the provided register buffer.boolean
isPowerExternal
(byte[] state) Extracts the state of the external power indicator from the provided register buffer.byte[]
Retrieves the entire A/D control/status and alarm pages.void
setADAlarm
(int channel, int alarmType, double alarm, byte[] state) Sets the alarm voltage value of the specified channel in the provided state buffer.void
setADAlarmEnable
(int channel, int alarmType, boolean alarmEnable, byte[] state) Sets the alarm enable value of the specified channel in the provided state buffer.void
setADRange
(int channel, double range, byte[] state) Sets the input range for the specified channel in the provided state buffer.void
setADResolution
(int channel, double resolution, byte[] state) Sets the conversion resolution value for the specified channel in the provided state buffer.void
setOutput
(int channel, boolean outputEnable, boolean outputState, byte[] state) Sets the output enable and state for the specified channel in the provided register buffer.void
setPower
(boolean external, byte[] state) Sets or clears the external power flag in the provided register buffer.static int
voltageToInt
(double voltage, double range) Converts a voltage double value to the DS2450 specific int value.void
writeDevice
(byte[] state) Writes 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, equals, getAdapter, getAddress, getAddressAsLong, getAddressAsString, hashCode, isAlarming, isPresent, setSpeed, setupContainer, setupContainer, setupContainer, toString
-
Field Details
-
BITMAP_OFFSET
public static final int BITMAP_OFFSETOffset of BITMAP in array returned from read state- See Also:
-
ALARM_OFFSET
public static final int ALARM_OFFSETOffset of ALARMS in array returned from read state- See Also:
-
EXPOWER_OFFSET
public static final int EXPOWER_OFFSETOffset of external power offset in array returned from read state- See Also:
-
CHANNELA
public static final int CHANNELAChannel A number- See Also:
-
CHANNELB
public static final int CHANNELBChannel B number- See Also:
-
CHANNELC
public static final int CHANNELCChannel C number- See Also:
-
CHANNELD
public static final int CHANNELDChannel D number- See Also:
-
NO_PRESET
public static final int NO_PRESETNo preset value- See Also:
-
PRESET_TO_ZEROS
public static final int PRESET_TO_ZEROSPreset value to zeros- See Also:
-
PRESET_TO_ONES
public static final int PRESET_TO_ONESPreset value to ones- See Also:
-
NUM_CHANNELS
public static final int NUM_CHANNELSNumber of channels- See Also:
-
-
Constructor Details
-
OneWireContainer20
public OneWireContainer20()Default constructor -
OneWireContainer20
Creates a container with a provided adapter object and the address of the 1-Wire device.- Parameters:
sourceAdapter
- adapter required to communicate with this devicenewAddress
- address of this 1-Wire device
-
OneWireContainer20
Creates a container with a provided adapter object and the address of the 1-Wire device.- Parameters:
sourceAdapter
- adapter required to communicate with this devicenewAddress
- address of this 1-Wire device
-
OneWireContainer20
Creates a container with a provided adapter object and the address of the 1-Wire device.- Parameters:
sourceAdapter
- adapter required to communicate with this devicenewAddress
- address of this 1-Wire device
-
-
Method Details
-
getName
Gets the name of this 1-Wire device.- Overrides:
getName
in classOneWireContainer
- Returns:
- representation of this 1-Wire device's name
-
getAlternateNames
Gets any other possible names for this 1-Wire device.- Overrides:
getAlternateNames
in classOneWireContainer
- Returns:
- representation of this 1-Wire device's other names
-
getDescription
Gets a brief description of the functionality of this 1-Wire device.- Overrides:
getDescription
in classOneWireContainer
- Returns:
- description of this 1-Wire device's functionality
-
getMaxSpeed
public int getMaxSpeed()Gets the maximum speed this 1-Wire device can communicate at.- Overrides:
getMaxSpeed
in classOneWireContainer
- Returns:
- maximum speed of this One-Wire device
- See Also:
-
getMemoryBanks
Gets an enumeration of memory banks.- Overrides:
getMemoryBanks
in classOneWireContainer
- Returns:
- enumeration of memory banks
- See Also:
-
getNumberADChannels
public int getNumberADChannels()Queries 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 interfaceADContainer
- Returns:
- the number of channels
-
hasADAlarms
public boolean hasADAlarms()Queries to see if this A/D measuring device has high/low alarms.- Specified by:
hasADAlarms
in interfaceADContainer
- Returns:
true
if it has high/low trips
-
getADRanges
public double[] getADRanges(int channel) Queries to get an array of available ranges for the specified A/D channel.- Specified by:
getADRanges
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
- Returns:
- available ranges starting from the largest range to the smallest range
- See Also:
-
getADResolutions
public double[] getADResolutions(int channel, double range) Queries to get an array of available resolutions based on the specified range on the specified A/D channel.- Specified by:
getADResolutions
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
range
- specified range- Returns:
- available resolutions
- See Also:
-
canADMultiChannelRead
public boolean canADMultiChannelRead()Queries to see if this A/D supports doing multiple voltage conversions at the same time.- Specified by:
canADMultiChannelRead
in interfaceADContainer
- Returns:
true
if can do multi-channel voltage reads- See Also:
-
readDevice
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 returned 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 thewriteADRegisters()
in conjunction with the 'set' methods to only write back the changed register bytes.- Specified by:
readDevice
in interfaceOneWireSensor
- Returns:
- register page contents verified with onboard CRC
- Throws:
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find part
-
writeDevice
Writes 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 interfaceOneWireSensor
- Parameters:
state
- register pages- Throws:
OneWireIOException
- Data was not written correctlyOneWireException
- Could not find part
-
getADVoltage
Reads the voltage values. Must be used after adoADConvert()
method call. Also must include the last valid state from thereadDevice()
method and this A/D must support multi-channel readcanMultiChannelRead()
if there are more then 1 channel.- Specified by:
getADVoltage
in interfaceADContainer
- Parameters:
state
- current state of this device returned fromreadDevice()
- Returns:
- voltage values for all channels
- Throws:
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find part- See Also:
-
getADVoltage
Reads a channels voltage value. Must be used after adoADConvert()
method call. Also must include the last valid state from thereadDevice()
method. Note, if more then one channel is to be read then it is more efficient to use thegetADVoltage(byte[])
method that returns all channel values.- Specified by:
getADVoltage
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of this device returned fromreadDevice()
- Returns:
- voltage value for the specified channel
- Throws:
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find partIllegalArgumentException
- Invalid channel number passed- See Also:
-
doADConvert
Performs voltage conversion on specified channel. The methodgetADVoltage()
can be used to read the result of the conversion.- Specified by:
doADConvert
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of this device returned fromreadDevice()
- Throws:
OneWireIOException
- Data was not written correctlyOneWireException
- Could not find part- See Also:
-
doADConvert
public void doADConvert(boolean[] doConvert, byte[] state) throws OneWireIOException, OneWireException Performs voltage conversion on all specified channels. The methodgetADVoltage()
can be used to read the result of the conversion. This A/D must support multi-channel readcanMultiChannelRead()
if there are more then 1 channel is specified.- Specified by:
doADConvert
in interfaceADContainer
- Parameters:
doConvert
- which channels to perform conversion on.state
- current state of this device returned fromreadDevice()
- Throws:
OneWireIOException
- Data was not written correctlyOneWireException
- Could not find part- See Also:
-
doADConvert
public void doADConvert(int channel, int preset, byte[] state) throws OneWireIOException, OneWireException, IllegalArgumentException Performs voltage conversion on specified channel. The methodgetADVoltage()
can be used to read the result of the conversion.- Parameters:
channel
- 0,1,2,3 representing the channels A,B,C,Dpreset
- preset value:NO_PRESET (0), PRESET_TO_ZEROS (1), and PRESET_TO_ONES (2)
state
- state of this device returned fromreadDevice()
- Throws:
OneWireIOException
- Data could not be written correctlyOneWireException
- Could not find partIllegalArgumentException
- Invalid channel number passed
-
doADConvert
public void doADConvert(boolean[] doConvert, int[] preset, byte[] state) throws OneWireIOException, OneWireException Performs voltage conversion on all specified channels. The methodgetADVoltage()
can be used to read the result of the conversion.- Parameters:
doConvert
- which channels to perform conversion onpreset
- preset valuesNO_PRESET (0), PRESET_TO_ZEROS (1), and PRESET_TO_ONES (2)
state
- current state of this device returned fromreadDevice()
- Throws:
OneWireIOException
- Data could not be written correctlyOneWireException
- Could not find part
-
getADAlarm
public double getADAlarm(int channel, int alarmType, byte[] state) Extracts the alarm voltage value of the specified channel from the provided state buffer. The state buffer is retrieved from thereadDevice()
method.- Specified by:
getADAlarm
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
alarmType
- desired alarm,ALARM_HIGH (1) or ALARM_LOW (0)
state
- current state of this device returned fromreadDevice()
- Returns:
- alarm value in volts
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
getADAlarmEnable
public boolean getADAlarmEnable(int channel, int alarmType, byte[] state) Extracts the alarm enable value of the specified channel from the provided state buffer. The state buffer is retrieved from thereadDevice()
method.- Specified by:
getADAlarmEnable
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
alarmType
- desired alarm,ALARM_HIGH (1) or ALARM_LOW (0)
state
- current state of the state returned fromreadDevice()
- Returns:
true
if specified alarm is enabled- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
hasADAlarmed
public boolean hasADAlarmed(int channel, int alarmType, byte[] state) Checks the alarm event value of the specified channel from the provided state buffer. The state buffer is retrieved from thereadDevice()
method.- Specified by:
hasADAlarmed
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
alarmType
- desired alarm,ALARM_HIGH (1) or ALARM_LOW (0)
state
- current state of the state returned fromreadDevice()
- Returns:
true
if specified alarm occurred- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
getADResolution
public double getADResolution(int channel, byte[] state) Extracts the conversion resolution of the specified channel from the provided state buffer expressed in volts. The state is retrieved from thereadDevice()
method.- Specified by:
getADResolution
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of the state returned fromreadDevice()
- Returns:
- resolution of channel in volts
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
getADRange
public double getADRange(int channel, byte[] state) Extracts the input voltage range of the specified channel from the provided state buffer. The state buffer is retrieved from thereadDevice()
method.- Specified by:
getADRange
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of the state returned fromreadDevice()
- Returns:
- A/D input voltage range
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
isOutputEnabled
Detects if the output is enabled for the specified channel from the provided register buffer. The register buffer is retrieved from thereadDevice()
method.- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of the device returned fromreadDevice()
- Returns:
true
if output is enabled on specified channel- Throws:
IllegalArgumentException
- Invalid channel number passed
-
getOutputState
Detects if the output is enabled for the specified channel from the provided register buffer. The register buffer is retrieved from thereadDevice()
method.- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
state
- current state of the device returned fromreadDevice()
- Returns:
false
if output is conducting to ground andtrue
if not conducting- Throws:
IllegalArgumentException
- Invalid channel number passed
-
getDevicePOR
public boolean getDevicePOR(byte[] state) Detects if this device has seen a Power-On-Reset (POR). If this has occurred it may be necessary to set the state of the device to the desired values. The register buffer is retrieved from thereadDevice()
method.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
false
if output is conducting to ground andtrue
if not conducting
-
isPowerExternal
public boolean isPowerExternal(byte[] state) Extracts 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 thereadDevice()
method.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
true
if set to external power operation
-
setADAlarm
public void setADAlarm(int channel, int alarmType, double alarm, byte[] state) Sets the alarm voltage value of the specified channel in the provided state buffer. The state buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Specified by:
setADAlarm
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
alarmType
- desired alarm,ALARM_HIGH (1) or ALARM_LOW (0)
alarm
- alarm value (will be reduced to 8 bit resolution)state
- current state of this device returned fromreadDevice()
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
setADAlarmEnable
public void setADAlarmEnable(int channel, int alarmType, boolean alarmEnable, byte[] state) Sets the alarm enable value of the specified channel in the provided state buffer. The state buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Specified by:
setADAlarmEnable
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
alarmType
- desired alarm,ALARM_HIGH (1) or ALARM_LOW (0)
alarmEnable
- alarm enable valuestate
- current state of this device returned fromreadDevice()
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
setADResolution
public void setADResolution(int channel, double resolution, byte[] state) Sets the conversion resolution value for the specified channel in the provided state buffer. The state buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Specified by:
setADResolution
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
resolution
- resolution to use in voltsstate
- current state of this device returned fromreadDevice()
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
setADRange
public void setADRange(int channel, double range, byte[] state) Sets the input range for the specified channel in the provided state buffer. The state buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Specified by:
setADRange
in interfaceADContainer
- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
range
- max volt range, use getRanges() method to get available rangesstate
- current state of this device returned fromreadDevice()
- Throws:
IllegalArgumentException
- Invalid channel number passed- See Also:
-
setOutput
public void setOutput(int channel, boolean outputEnable, boolean outputState, byte[] state) Sets the output enable and state for the specified channel in the provided register buffer. The register buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Parameters:
channel
- channel in the range[0 to (getNumberChannels() - 1)]
outputEnable
-true
if output is enabledoutputState
-false
if output is conducting to ground andtrue
if not conducting. This parameter is not used ifoutputEnable
isfalse
state
- current state of the device returned fromreadDevice()
-
setPower
public void setPower(boolean external, byte[] state) Sets or clears the external power flag in the provided register buffer. The register buffer is retrieved from thereadDevice()
method. The methodwriteDevice()
must be called to finalize these changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Parameters:
external
-true
if setting external power is usedstate
- current state of this device returned fromreadDevice()
-
interpretVoltage
public static double interpretVoltage(long rawVoltage, double range) Converts a raw voltage long value for the DS2450 into a valid voltage. Requires the max voltage value.- Parameters:
rawVoltage
- raw voltagerange
- max voltage- Returns:
- calculated voltage based on the range
-
voltageToInt
public static int voltageToInt(double voltage, double range) Converts a voltage double value to the DS2450 specific int value. Requires the max voltage value.- Parameters:
voltage
- voltagerange
- max voltage- Returns:
- the DS2450 voltage
-