public class OneWireContainer20 extends OneWireContainer implements ADContainer
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.
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);
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. There is NO way to know if the device is reading a higher than specified voltage or NO voltage.
Modifier and Type | Field and Description |
---|---|
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
|
ALARM_HIGH, ALARM_LOW
Constructor and Description |
---|
OneWireContainer20()
Default constructor
|
OneWireContainer20(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,
java.lang.String newAddress)
Creates a container with a provided adapter object
and the address of the 1-Wire device.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canADMultiChannelRead()
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.
|
java.lang.String |
getAlternateNames()
Gets any other possible names for this 1-Wire device.
|
java.lang.String |
getDescription()
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 |
getMaxSpeed()
Gets the maximum speed this 1-Wire device can communicate at.
|
java.util.Enumeration |
getMemoryBanks()
Gets an enumeration of memory banks.
|
java.lang.String |
getName()
Gets the name of this 1-Wire device.
|
int |
getNumberADChannels()
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 |
hasADAlarms()
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[] |
readDevice()
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.
|
doSpeed, equals, getAdapter, getAddress, getAddressAsLong, getAddressAsString, hashCode, isAlarming, isPresent, setSpeed, setupContainer, setupContainer, setupContainer, toString
public static final int BITMAP_OFFSET
public static final int ALARM_OFFSET
public static final int EXPOWER_OFFSET
public static final int CHANNELA
public static final int CHANNELB
public static final int CHANNELC
public static final int CHANNELD
public static final int NO_PRESET
public static final int PRESET_TO_ZEROS
public static final int PRESET_TO_ONES
public static final int NUM_CHANNELS
public OneWireContainer20()
public OneWireContainer20(DSPortAdapter sourceAdapter, byte[] newAddress)
sourceAdapter
- adapter required to communicate with
this devicenewAddress
- address of this 1-Wire devicepublic OneWireContainer20(DSPortAdapter sourceAdapter, long newAddress)
sourceAdapter
- adapter required to communicate with
this devicenewAddress
- address of this 1-Wire devicepublic OneWireContainer20(DSPortAdapter sourceAdapter, java.lang.String newAddress)
sourceAdapter
- adapter required to communicate with
this devicenewAddress
- address of this 1-Wire devicepublic java.lang.String getName()
getName
in class OneWireContainer
public java.lang.String getAlternateNames()
getAlternateNames
in class OneWireContainer
public java.lang.String getDescription()
getDescription
in class OneWireContainer
public int getMaxSpeed()
getMaxSpeed
in class OneWireContainer
DSPortAdapter.setSpeed(int)
public java.util.Enumeration getMemoryBanks()
getMemoryBanks
in class OneWireContainer
MemoryBank
,
PagedMemoryBank
,
OTPMemoryBank
public int getNumberADChannels()
[0 to (getNumberChannels() - 1)]
.getNumberADChannels
in interface ADContainer
public boolean hasADAlarms()
hasADAlarms
in interface ADContainer
true
if it has high/low tripspublic double[] getADRanges(int channel)
getADRanges
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
ADContainer.getNumberADChannels()
public double[] getADResolutions(int channel, double range)
getADResolutions
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
range
- specified rangeADContainer.getNumberADChannels()
,
ADContainer.getADRanges(int)
public boolean canADMultiChannelRead()
canADMultiChannelRead
in interface ADContainer
true
if can do multi-channel voltage readsADContainer.doADConvert(boolean[],byte[])
public byte[] readDevice() throws OneWireIOException, OneWireException
writeADRegisters()
in conjuction with the 'set' methods to only write back the changed
register bytes.readDevice
in interface OneWireSensor
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find partpublic void writeDevice(byte[] state) throws OneWireIOException, OneWireException
writeDevice
in interface OneWireSensor
state
- register pagesOneWireIOException
- Data was not written correctlyOneWireException
- Could not find partpublic double[] getADVoltage(byte[] state) throws OneWireIOException, OneWireException
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.getADVoltage
in interface ADContainer
state
- current state of this device returned from
readDevice()
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find partADContainer.doADConvert(boolean[],byte[])
public double getADVoltage(int channel, byte[] state) throws OneWireIOException, OneWireException
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 getADVoltage(byte[])
method that returns
all channel values.getADVoltage
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of this
device returned from readDevice()
OneWireIOException
- Data was not read correctlyOneWireException
- Could not find partjava.lang.IllegalArgumentException
- Invalid channel number passedADContainer.doADConvert(int,byte[])
,
ADContainer.getADVoltage(byte[])
public void doADConvert(int channel, byte[] state) throws OneWireIOException, OneWireException
getADVoltage()
can be used to read the result
of the conversion.doADConvert
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of this
device returned from readDevice()
OneWireIOException
- Data was not written correctlyOneWireException
- Could not find partOneWireSensor.readDevice()
,
ADContainer.getADVoltage(int,byte[])
public void doADConvert(boolean[] doConvert, byte[] state) throws OneWireIOException, OneWireException
getADVoltage()
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.doADConvert
in interface ADContainer
doConvert
- which channels to perform conversion on.state
- current state of this
device returned from readDevice()
OneWireIOException
- Data was not written correctlyOneWireException
- Could not find partOneWireSensor.readDevice()
,
ADContainer.getADVoltage(byte[])
,
ADContainer.canADMultiChannelRead()
public void doADConvert(int channel, int preset, byte[] state) throws OneWireIOException, OneWireException, java.lang.IllegalArgumentException
getADVoltage()
can be used to read the result
of the conversion.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 from readDevice()
OneWireIOException
- Data could not be written correctlyOneWireException
- Could not find partjava.lang.IllegalArgumentException
- Invalid channel number passedpublic void doADConvert(boolean[] doConvert, int[] preset, byte[] state) throws OneWireIOException, OneWireException
getADVoltage()
can be used to read the result
of the conversion.doConvert
- which channels to perform conversion onpreset
- preset values
NO_PRESET (0), PRESET_TO_ZEROS (1), and PRESET_TO_ONES (2)
state
- current state of this
device returned from readDevice()
OneWireIOException
- Data could not be written correctlyOneWireException
- Could not find partpublic double getADAlarm(int channel, int alarmType, byte[] state)
readDevice()
method.getADAlarm
in interface ADContainer
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 from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedOneWireSensor.readDevice()
,
ADContainer.hasADAlarms()
public boolean getADAlarmEnable(int channel, int alarmType, byte[] state)
readDevice()
method.getADAlarmEnable
in interface ADContainer
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 from readDevice()
true
if specified alarm is enabledjava.lang.IllegalArgumentException
- Invalid channel number passedOneWireSensor.readDevice()
,
ADContainer.hasADAlarms()
public boolean hasADAlarmed(int channel, int alarmType, byte[] state)
readDevice()
method.hasADAlarmed
in interface ADContainer
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 from readDevice()
true
if specified alarm occurredjava.lang.IllegalArgumentException
- Invalid channel number passedOneWireSensor.readDevice()
,
ADContainer.hasADAlarms()
,
ADContainer.getADAlarmEnable(int,int,byte[])
,
ADContainer.setADAlarmEnable(int,int,boolean,byte[])
public double getADResolution(int channel, byte[] state)
readDevice()
method.getADResolution
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of the state
returned from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedADContainer.getADResolutions(int,double)
,
ADContainer.setADResolution(int,double,byte[])
public double getADRange(int channel, byte[] state)
readDevice()
method.getADRange
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of the state
returned from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedADContainer.getADRanges(int)
,
ADContainer.setADRange(int,double,byte[])
public boolean isOutputEnabled(int channel, byte[] state) throws java.lang.IllegalArgumentException
readDevice()
method.channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of the device
returned from readDevice()
true
if output is enabled on specified channeljava.lang.IllegalArgumentException
- Invalid channel number passedpublic boolean getOutputState(int channel, byte[] state) throws java.lang.IllegalArgumentException
readDevice()
method.channel
- channel in the range
[0 to (getNumberChannels() - 1)]
state
- current state of the device
returned from readDevice()
false
if output is conducting to ground and
true
if not conductingjava.lang.IllegalArgumentException
- Invalid channel number passedpublic boolean getDevicePOR(byte[] state)
readDevice()
method.state
- current state of the device
returned from readDevice()
false
if output is conducting to ground and
true
if not conductingpublic boolean isPowerExternal(byte[] state)
readDevice()
method.state
- current state of the
device returned from readDevice()
true
if set to external power operationpublic void setADAlarm(int channel, int alarmType, double alarm, byte[] state)
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()
.setADAlarm
in interface ADContainer
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 from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedOneWireSensor.writeDevice(byte[])
,
ADContainer.hasADAlarms()
,
ADContainer.getADAlarm(int,int,byte[])
,
ADContainer.getADAlarmEnable(int,int,byte[])
,
ADContainer.setADAlarmEnable(int,int,boolean,byte[])
,
ADContainer.hasADAlarmed(int,int,byte[])
public void setADAlarmEnable(int channel, int alarmType, boolean alarmEnable, byte[] state)
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()
.setADAlarmEnable
in interface ADContainer
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 from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedOneWireSensor.writeDevice(byte[])
,
ADContainer.hasADAlarms()
,
ADContainer.getADAlarm(int,int,byte[])
,
ADContainer.setADAlarm(int,int,double,byte[])
,
ADContainer.getADAlarmEnable(int,int,byte[])
,
ADContainer.hasADAlarmed(int,int,byte[])
public void setADResolution(int channel, double resolution, byte[] state)
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()
.setADResolution
in interface ADContainer
channel
- channel in the range
[0 to (getNumberChannels() - 1)]
resolution
- resolution to use in voltsstate
- current state of this
device returned from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedADContainer.getADResolutions(int,double)
,
ADContainer.getADResolution(int,byte[])
public void setADRange(int channel, double range, byte[] state)
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()
.setADRange
in interface ADContainer
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 from readDevice()
java.lang.IllegalArgumentException
- Invalid channel number passedADContainer.getADRanges(int)
,
ADContainer.getADRange(int,byte[])
public void setOutput(int channel, boolean outputEnable, boolean outputState, byte[] state)
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()
.channel
- channel in the range
[0 to (getNumberChannels() - 1)]
outputEnable
- true
if output is enabledoutputState
- false
if output is conducting to
ground and true
if not conducting. This
parameter is not used if outputEnable
is
false
state
- current state of the
device returned from readDevice()
public void setPower(boolean external, byte[] state)
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()
.external
- true
if setting external power is usedstate
- current state of this
device returned from readDevice()
public static double interpretVoltage(long rawVoltage, double range)
rawVoltage
- raw voltagerange
- max voltagepublic static int voltageToInt(double voltage, double range)
voltage
- voltagerange
- max voltageCopyright © 1999-2012 Maxim Integrated Products. All Rights Reserved.