Class OneWireContainer05

java.lang.Object
com.dalsemi.onewire.container.OneWireContainer
com.dalsemi.onewire.container.OneWireContainer05
All Implemented Interfaces:
OneWireSensor, SwitchContainer

public class OneWireContainer05 extends OneWireContainer implements SwitchContainer

1-Wire® container for a Single Addressable Switch, DS2405. This container encapsulates the functionality of the 1-Wire family type 05 (hex)

Features

  • Open drain PIO pin controlled through 1-Wire communication
  • Logic level sensing of the PIO pin can be sensed
  • Operating temperature range from -40 to +85
  • One channel with level sensing abilities
  • Does not support activity sensing or 'Smart On' capabilities

Memory

The DS2405 has no memory beyond its 64-bit registration number.

Usage

The DS2405 supports level sensing, but not activity sensing. The code below reads the state of the DS2405, extracting the latch state and the sensed level of the PIO pin, then in the loop it toggles the latch state.

 // "ID" is a byte array of size 8 with an address of a part we
 // have already found with family code 05 hex
 // "access" is a DSPortAdapter

 int i = 0;
 OneWireContainer05 ds2405 = (OneWireContainer05) access.getDeviceContainer(ID);
 ds2405.setupContainer(access, ID);

 byte[] state = ds2405.readDevice();

 // I know that the 2405 only has one channel (one switch)
 // and it doesn't support 'Smart On'

 boolean latch_state = ds2405.getLatchState(0, state);
 System.out.println("Current state of switch: " + latch_state);
 System.out.println("Current output level:    " + ds2405.getLevel(0, state));
 while (++i < 100) {
        System.out.println("Toggling switch");
        ds2405.setLatchState(0, !latch_state, false, state);
        ds2405.writeDevice(state);
        state = ds2405.readDevice();
        latch_state = ds2405.getLatchState(0, state);
        System.out.println("Current state of switch: " + latch_state);
        System.out.println("Current output level:    " + ds2405.getLevel(0, state));
        Thread.sleep(500);
 }

 

Also see the usage example in the SwithContainer interface.

DataSheet

http://pdfserv.maxim-ic.com/arpdf/DS2405.pdf
Also see the DS2406, a dual addressable switch (OneWireContainer12).
See Also:
  • Constructor Details

  • Method Details

    • getName

      public String getName()
      Gets the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String. For example "DS1992".
      Overrides:
      getName in class OneWireContainer
      Returns:
      iButton or 1-Wire device name
    • getAlternateNames

      public String getAlternateNames()
      Retrieves the alternate Maxim Integrated Products part numbers or names. A 'family' of MicroLAN devices may have more than one part number depending on packaging. There can also be nicknames such as "Crypto iButton".
      Overrides:
      getAlternateNames in class OneWireContainer
      Returns:
      the alternate names for this iButton or 1-Wire device
    • getDescription

      public String getDescription()
      Gets a short description of the function of this iButton or 1-Wire Device type.
      Overrides:
      getDescription in class OneWireContainer
      Returns:
      device description
    • getNumberChannels

      public int getNumberChannels(byte[] state)
      Gets the number of channels supported by this switch. Channel specific methods will use a channel number specified by an integer from [0 to (getNumberChannels(byte[]) - 1)]. Note that all devices of the same family will not necessarily have the same number of channels.
      Specified by:
      getNumberChannels in interface SwitchContainer
      Parameters:
      state - current state of the device returned from readDevice()
      Returns:
      the number of channels for this device
      See Also:
    • isHighSideSwitch

      public boolean isHighSideSwitch()
      Checks if the channels of this switch are 'high side' switches. This indicates that when 'on' or true, the switch output is connect to the 1-Wire data. If this method returns false then when the switch is 'on' or true, the switch is connected to ground.
      Specified by:
      isHighSideSwitch in interface SwitchContainer
      Returns:
      true if the switch is a 'high side' switch, false if the switch is a 'low side' switch
      See Also:
    • hasActivitySensing

      public boolean hasActivitySensing()
      Checks if the channels of this switch support activity sensing. If this method returns true then the method getSensedActivity(int,byte[]) can be used.
      Specified by:
      hasActivitySensing in interface SwitchContainer
      Returns:
      true if channels support activity sensing
      See Also:
    • hasLevelSensing

      public boolean hasLevelSensing()
      Checks if the channels of this switch support level sensing. If this method returns true then the method getLevel(int,byte[]) can be used.
      Specified by:
      hasLevelSensing in interface SwitchContainer
      Returns:
      true if channels support level sensing
      See Also:
    • hasSmartOn

      public boolean hasSmartOn()
      Checks if the channels of this switch support 'smart on'. Smart on is the ability to turn on a channel such that only 1-Wire device on this channel are awake and ready to do an operation. This greatly reduces the time to discover the device down a branch. If this method returns true then the method setLatchState(int,boolean,boolean,byte[]) can be used with the doSmart parameter true.
      Specified by:
      hasSmartOn in interface SwitchContainer
      Returns:
      true if channels support 'smart on'
      See Also:
    • onlySingleChannelOn

      public boolean onlySingleChannelOn()
      Checks if the channels of this switch require that only one channel is on at any one time. If this method returns true then the method setLatchState(int,boolean,boolean,byte[]) will not only affect the state of the given channel but may affect the state of the other channels as well to insure that only one channel is on at a time.
      Specified by:
      onlySingleChannelOn in interface SwitchContainer
      Returns:
      true if only one channel can be on at a time.
      See Also:
    • getLevel

      public boolean getLevel(int channel, byte[] state)
      Checks the sensed level on the indicated channel. To avoid an exception, verify that this switch has level sensing with the hasLevelSensing(). Level sensing means that the device can sense the logic level on its PIO pin.
      Specified by:
      getLevel in interface SwitchContainer
      Parameters:
      channel - channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)]
      state - current state of the device returned from readDevice()
      Returns:
      true if level sensed is 'high' and false if level sensed is 'low'
      See Also:
    • getLatchState

      public boolean getLatchState(int channel, byte[] state)
      Checks the latch state of the indicated channel.
      Specified by:
      getLatchState in interface SwitchContainer
      Parameters:
      channel - channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)]
      state - current state of the device returned from readDevice()
      Returns:
      true if channel latch is 'on' or conducting and false if channel latch is 'off' and not conducting. Note that the actual output when the latch is 'on' is returned from the isHighSideSwitch() method.
      See Also:
    • getSensedActivity

      public boolean getSensedActivity(int channel, byte[] state) throws OneWireException
      Checks if the indicated channel has experienced activity. This occurs when the level on the PIO pins changes. To clear the activity that is reported, call clearActivity(). To avoid an exception, verify that this device supports activity sensing by calling the method hasActivitySensing().
      Specified by:
      getSensedActivity in interface SwitchContainer
      Parameters:
      channel - channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)]
      state - current state of the device returned from readDevice()
      Returns:
      true if activity was detected and false if no activity was detected
      Throws:
      OneWireException - if this device does not have activity sensing
      See Also:
    • clearActivity

      public void clearActivity() throws OneWireException
      Clears the activity latches the next time possible. For example, on a DS2406/07, this happens the next time the status is read with readDevice().
      Specified by:
      clearActivity in interface SwitchContainer
      Throws:
      OneWireException - if this device does not support activity sensing
      See Also:
    • setLatchState

      public void setLatchState(int channel, boolean latchState, boolean doSmart, byte[] state)
      Sets the latch state of the indicated channel. The method writeDevice() must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call to writeDevice().
      Specified by:
      setLatchState in interface SwitchContainer
      Parameters:
      channel - channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)]
      latchState - true to set the channel latch 'on' (conducting) and false to set the channel latch 'off' (not conducting). Note that the actual output when the latch is 'on' is returned from the isHighSideSwitch() method.
      doSmart - If latchState is 'on'/true then doSmart indicates if a 'smart on' is to be done. To avoid an exception check the capabilities of this device using the hasSmartOn() method.
      state - current state of the device returned from readDevice()
      See Also:
    • 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.
      Specified by:
      readDevice in interface OneWireSensor
      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.
      Specified by:
      writeDevice in interface OneWireSensor
      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