public interface TemperatureContainer extends OneWireSensor
The TemperatureContainer methods can be organized into the following categories:
tc
':
// Read High and Low Alarms
if (!tc.hasTemperatureAlarms())
System.out.println("Temperature alarms not supported");
else
{
byte[] state = tc.readDevice();
double alarmLow = tc.getTemperatureAlarm(TemperatureContainer.ALARM_LOW, state);
double alarmHigh = tc.getTemperatureAlarm(TemperatureContainer.ALARM_HIGH, state);
System.out.println("Alarm: High = " + alarmHigh + ", Low = " + alarmLow);
} }
tc
':
double lastTemperature;
// get the current resolution and other settings of the device (done only once)
byte[] state = tc.readDevice();
do // loop to read the temp
{
// perform a temperature conversion
tc.doTemperatureConvert(state);
// read the result of the conversion
state = tc.readDevice();
// extract the result out of state
lastTemperature = tc.getTemperature(state);
...
}while (!done);
The reason the conversion and the reading are separated
is that one may want to do a conversion without reading
the result. One could take advantage of the alarm features
of a device by setting a threshold and doing conversions
until the device is alarming. For example:
// get the current resolution of the device
byte [] state = tc.readDevice();
// set the trips
tc.setTemperatureAlarm(TemperatureContainer.ALARM_HIGH, 50, state);
tc.setTemperatureAlarm(TemperatureContainer.ALARM_LOW, 20, state);
tc.writeDevice(state);
do // loop on conversions until an alarm occurs
{
tc.doTemperatureConvert(state);
} while (!tc.isAlarming());
tc
':
byte[] state = tc.readDevice();
if (tc.hasSelectableTemperatureResolution())
{
double[] resolution = tc.getTemperatureResolutions();
tc.setTemperatureResolution(resolution [resolution.length - 1], state);
tc.writeDevice(state);
}
OneWireContainer10
,
OneWireContainer21
,
OneWireContainer26
,
OneWireContainer28
,
OneWireContainer30
Modifier and Type | Field and Description |
---|---|
static int |
ALARM_HIGH
high temperature alarm
|
static int |
ALARM_LOW
low temperature alarm
|
Modifier and Type | Method and Description |
---|---|
void |
doTemperatureConvert(byte[] state)
Performs a temperature conversion.
|
double |
getMaxTemperature()
Gets the maximum temperature in Celsius.
|
double |
getMinTemperature()
Gets the minimum temperature in Celsius.
|
double |
getTemperature(byte[] state)
Gets the temperature value in Celsius from the
state
data retrieved from the readDevice() method. |
double |
getTemperatureAlarm(int alarmType,
byte[] state)
Gets the specified temperature alarm value in Celsius from the
state data retrieved from the
readDevice() method. |
double |
getTemperatureAlarmResolution()
Gets the temperature alarm resolution in Celsius.
|
double |
getTemperatureResolution(byte[] state)
Gets the current temperature resolution in Celsius from the
state data retrieved from the readDevice()
method. |
double[] |
getTemperatureResolutions()
Get an array of available temperature resolutions in Celsius.
|
boolean |
hasSelectableTemperatureResolution()
Checks to see if this device has selectable temperature resolution.
|
boolean |
hasTemperatureAlarms()
Checks to see if this temperature measuring device has high/low
trip alarms.
|
void |
setTemperatureAlarm(int alarmType,
double alarmValue,
byte[] state)
Sets the temperature alarm value in Celsius in the provided
state data. |
void |
setTemperatureResolution(double resolution,
byte[] state)
Sets the current temperature resolution in Celsius in the provided
state data. |
readDevice, writeDevice
static final int ALARM_HIGH
static final int ALARM_LOW
boolean hasTemperatureAlarms()
true
if this TemperatureContainer
has high/low trip alarmsgetTemperatureAlarm(int, byte[])
,
setTemperatureAlarm(int, double, byte[])
boolean hasSelectableTemperatureResolution()
true
if this TemperatureContainer
has selectable temperature resolutiongetTemperatureResolution(byte[])
,
getTemperatureResolutions()
,
setTemperatureResolution(double, byte[])
double[] getTemperatureResolutions()
hasSelectableTemperatureResolution()
,
getTemperatureResolution(byte[])
,
setTemperatureResolution(double, byte[])
double getTemperatureAlarmResolution() throws OneWireException
OneWireException
- Device does not support temperature
alarmshasTemperatureAlarms()
,
getTemperatureAlarm(int, byte[])
,
setTemperatureAlarm(int, double, byte[])
double getMaxTemperature()
double getMinTemperature()
void doTemperatureConvert(byte[] state) throws OneWireIOException, OneWireException
state
- byte array with device state informationOneWireException
- Part could not be found [ fatal ]OneWireIOException
- Data wasn't transferred properly [ recoverable ]double getTemperature(byte[] state) throws OneWireIOException
state
data retrieved from the readDevice()
method.state
- byte array with device state informationdoTemperatureConvert()
OneWireIOException
- In the case of invalid temperature datadouble getTemperatureAlarm(int alarmType, byte[] state) throws OneWireException
state
data retrieved from the
readDevice()
method.alarmType
- valid value: ALARM_HIGH
or
ALARM_LOW
state
- byte array with device state informationOneWireException
- Device does not support temperature
alarmshasTemperatureAlarms()
,
setTemperatureAlarm(int, double, byte[])
double getTemperatureResolution(byte[] state)
state
data retrieved from the readDevice()
method.state
- byte array with device state informationhasSelectableTemperatureResolution()
,
getTemperatureResolutions()
,
setTemperatureResolution(double, byte[])
void setTemperatureAlarm(int alarmType, double alarmValue, byte[] state) throws OneWireException
state
data.
Use the method writeDevice()
with
this data to finalize the change to the device.alarmType
- valid value: ALARM_HIGH
or
ALARM_LOW
alarmValue
- alarm trip value in Celsiusstate
- byte array with device state informationOneWireException
- Device does not support temperature
alarmshasTemperatureAlarms()
,
getTemperatureAlarm(int, byte[])
void setTemperatureResolution(double resolution, byte[] state) throws OneWireException
state
data. Use the method writeDevice()
with this data to finalize the change to the device.resolution
- temperature resolution in Celsiusstate
- byte array with device state informationOneWireException
- Device does not support selectable
temperature resolutionhasSelectableTemperatureResolution()
,
getTemperatureResolution(byte[])
,
getTemperatureResolutions()
Copyright © 1999-2012 Maxim Integrated Products. All Rights Reserved.