com.dalsemi.onewire.container
Interface OneWireSensor

All Known Subinterfaces:
ADContainer, ClockContainer, HumidityContainer, PotentiometerContainer, SwitchContainer, TemperatureContainer

public interface OneWireSensor

1-Wire sensor interface class for basic sensor operations.

Typically the operations of 1-Wire Sensors are memory mapped so writing to a particular location causes the state to change. To accommodate this type of architecture and reduce the number of 1- Wire operations that need to take place, a 'read-modify-write' technique is used. Each Sensor interface is derived from this super-interface that contain just two methods: readDevice, writeDevice. The read returns a byte array and the write takes a byte array. The byte array is the state of the device. The interfaces that extend this interface have 'get' and 'set' methods that manipulate the byte array. So a OneWireSensor operation is:

  1. state = readDevice()
  2. 'get' and 'set' methods on state
  3. writeDevice(state)

Usage

Example 1

Read the sensed level of a SwitchContainer instance 'sw':
 
  byte[] state = sw.readDevice();
  if (sw.hasLevelSensing())
  {
     for (int ch = 0; ch < sw.getNumberChannels(state); ch++)
     {
        System.out.print("Level for channel " + ch + " is : ");
        if (sw.getLevel(ch, state))
           System.out.println("HIGH");
        else
           System.out.println("HIGH");
     }
  }
  else
      System.out.println("This SwitchContainer can not sense level");
  

Example 2

Set the clock of a ClockContainer instance 'cl':
 
  byte[] state = cl.readDevice();
  cl.setClock((new Date().getTime()), state);
  cl.setClockRunEnable(true, state);
  cl.writeDevice(state);
  

Version:
0.00, 28 Aug 2000
See Also:
ADContainer, ClockContainer, PotentiometerContainer, SwitchContainer, TemperatureContainer

Method Summary
 byte[] readDevice()
          Retrieves the 1-Wire device sensor state.
 void writeDevice(byte[] state)
          Writes the 1-Wire device sensor state that have been changed by 'set' methods.
 

Method Detail

readDevice

public byte[] readDevice()
                  throws OneWireIOException,
                         OneWireException
Retrieves the 1-Wire device sensor state. This state 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.
Returns:
1-Wire device sensor state
Throws:
OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. 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

writeDevice

public void writeDevice(byte[] state)
                 throws OneWireIOException,
                        OneWireException
Writes the 1-Wire device sensor state 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.
Parameters:
state - 1-Wire device sensor state
Throws:
OneWireIOException - on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. 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