Class OneWireContainer12

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

public class OneWireContainer12 extends OneWireContainer implements SwitchContainer

1-Wire® container for a Dual Addressable Switch, DS2406 or DS2407. This container encapsulates the functionality of the 1-Wire family type 12 (hex). The DS2406 replaces the DS2407, but does not have hidden mode or user programmable power-on settings.

Features

  • Open drain PIO pin controlled through 1-Wire communication
  • 1024-bits of user programmable OTP EPROM
  • Operating temperature range from -40@htmlonly invalid input: '&#176'C @endhtmlonly to +85@htmlonly invalid input: '&#176'C @endhtmlonly
  • On-chip CRC16 generator allows detection of data transfer errors
  • One or two channels with level sensing abilities
  • Supports activity sensing
  • Does not support 'Smart On' capabilities
  • TO-92 (1 channel) or TSOC (2 channel) packaging
  • Supports Conditional Search with user-selectable search options

Memory

The memory can be accessed through the objects that are returned from the getMemoryBanks method.

The following is a list of the MemoryBank instances that are returned:
  • Main Memory
    • Implements MemoryBank, PagedMemoryBank, OTPMemoryBank
    • Size 128 starting at physical address 0
    • Features Write-once general-purpose non-volatile needs-program-pulse
    • Pages 4 pages of length 32 bytes giving 29 bytes Packet data payload
    • Page Features page-device-CRC pages-redirectable pages-lockable
    • Extra information for each page Inverted redirection page, length 1
  • Write protect pages and Page redirection
    • Implements MemoryBank, PagedMemoryBank, OTPMemoryBank
    • Size 8 starting at physical address 0 (in STATUS memory area)
    • Features Write-once not-general-purpose non-volatile needs-program-pulse
    • Pages 1 pages of length 8 bytes
    • Page Features page-device-CRC

Usage

The DS2406 supports level sensing and activity sensing. The code below reports the flip-flop state, PIO level, and sensed activity while toggling every switch each time through the loop. It toggles every switch it finds, regardless if the device has one or two switches.

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

      OneWireContainer12 ds2406 = (OneWireContainer12) access.getDeviceContainer(ID);
      ds2406.setupContainer(access,ID);

      byte[] state = ds2406.readDevice();
      int numchannels = ds2406.getNumberChannels(state);
      System.out.println("Number of Channels: "+numchannels);
      boolean[] switches = new boolean[numchannels];

      ds2406.clearActivity();

      for (int j=0;jinvalid input: '<'10;j++)
      {
          //clear the activity latches halfway through the test
          if (j==5)
              ds2406.clearActivity();
          state = ds2406.readDevice();

          //first let's print out the status of all the latches
          for (int i=0;i < numchannels;i++)
          {
              System.out.println("---------------------------------------------------------\r\n");
              System.out.println("                       CHANNEL "+i);
              System.out.println("---------------------------------------------------------\r\n");

              System.out.println("           Latch state: "+ds2406.getLatchState(i,state));
              System.out.println("           Level      : "+ds2406.getLevel(i,state));
              System.out.println("           Activity   : "+ds2406.getSensedActivity(i, state));
              switches[i] = ds2406.getLatchState(i,state);
          }

          //now lets toggle the switch flip-flop
          for (int i=0;i < numchannels;i++)
          {
              ds2406.setLatchState(i,!switches[i],false,state);
          }
          ds2406.writeDevice(state);

          Thread.sleep(500);
      }

 

Also see the usage example in the SwithContainer interface.

For examples regarding memory operations,

DataSheet

http://pdfserv.maxim-ic.com/arpdf/DS2406.pdf for the DS2406
http://pdfserv.maxim-ic.com/arpdf/DS2407.pdf for the DS2407
Also see the DS2405, a single addressable switch (OneWireContainer05).
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
    channelMode for the channelAccess method.
    static final byte
    channelMode for the channelAccess method.
    static final byte
    channelMode for the channelAccess method.
    static final byte
    Used to select neither channel as the source for alarm conditions in the setSearchConditions() method.
    static final byte
    CRCMode for the channelAccess method.
    static final byte
    CRCMode for the channelAccess method.
    static final byte
    CRCMode for the channelAccess method.
    static final byte
    CRCMode for the channelAccess method.
    static final byte
    Used for options in the setSearchConditions() to make sure the specified option is not changes from its current value.
    static final byte
    Used to set the polarity to logical '1' for conditional search checking in the setSearchConditions() method.
    static final byte
    Used to set the polarity to logical '0' for conditional search checking in the setSearchConditions() method.
    static final byte
    Used to set the source to the activity latch for conditional searches in the setSearchConditions() method.
    static final byte
    Used to set the source to the flip-flop state for conditional searches in the setSearchConditions() method.
    static final byte
    Used to set the source to the PIO status for conditional searches in the setSearchConditions() method.

    Fields inherited from class com.dalsemi.onewire.container.OneWireContainer

    adapter, address, speed, speedFallBackOK
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new OneWireContainer for communication with a DS2406/2407.
    OneWireContainer12(DSPortAdapter sourceAdapter, byte[] newAddress)
    Creates a new OneWireContainer for communication with a DS2406/2407.
    OneWireContainer12(DSPortAdapter sourceAdapter, long newAddress)
    Creates a new OneWireContainer for communication with a DS2406/2407.
    OneWireContainer12(DSPortAdapter sourceAdapter, String newAddress)
    Creates a new OneWireContainer for communication with a DS2406/2407.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    channelAccess(byte[] inbuffer, boolean toggleRW, boolean readInitially, int CRCMode, int channelMode, boolean clearActivity, boolean interleave)
    Accesses the PIO channels to sense the logical status of the output node.
    void
    Clears the activity latches the next time possible.
    Retrieves the alternate Maxim Integrated Products part numbers or names.
    Gets a short description of the function of this iButton or 1-Wire Device type.
    boolean
    getLatchState(int channel, byte[] state)
    Checks the latch state of the indicated channel.
    boolean
    getLevel(int channel, byte[] state)
    Checks the sensed level on the indicated channel.
    Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank.
    Gets the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String.
    int
    getNumberChannels(byte[] state)
    Gets the number of channels supported by this switch.
    boolean
    getSensedActivity(int channel, byte[] state)
    Checks if the indicated channel has experienced activity.
    boolean
    Checks if the channels of this switch support activity sensing.
    boolean
    Checks if the channels of this switch support level sensing.
    boolean
    Checks if the channels of this switch support 'smart on'.
    boolean
    Checks if the channels of this switch are 'high side' switches.
    boolean
    isPowerSupplied(byte[] state)
    Checks to see how the DS2406 is being supplied with power.
    boolean
    Checks if the channels of this switch require that only one channel is on at any one time.
    byte[]
    Retrieves the 1-Wire device sensor state.
    void
    setLatchState(int channel, boolean latchState, boolean doSmart, byte[] state)
    Sets the latch state of the indicated channel.
    void
    setSearchConditions(byte channel, byte source, byte polarity, byte[] state)
    Programs the Conditional Search options for the DS2406/2407.
    void
    setSpeedCheck(boolean doSpeedCheck)
    Directs the container to avoid the calls to doSpeed() in methods that communicate with the Thermocron.
    void
    writeDevice(byte[] state)
    Writes the 1-Wire device sensor state that have been changed by 'set' methods.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • 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
    • getMemoryBanks

      public Enumeration<MemoryBank> getMemoryBanks()
      Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank.
      Overrides:
      getMemoryBanks in class OneWireContainer
      Returns:
      Enumeration of memory banks
      See Also:
    • isPowerSupplied

      public boolean isPowerSupplied(byte[] state)
      Checks to see how the DS2406 is being supplied with power. The 6-pin (2 channel) package of the DS2406 can be powered by an outside source, but will still function on parasite power only.
      Parameters:
      state - current state of the device returned from readDevice()
      Returns:
      true if the device is getting supplied with power and false if the device is parasite powered
      See Also:
    • 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)
      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
      See Also:
    • clearActivity

      public void clearActivity()

      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().

      The activity latches will only be cleared once. With the DS2406/07, this means that only the first call to readDevice() will clear the activity latches. Subsequent calls to readDevice() will leave the activity latch states intact, unless this method has been invoked since the last call to readDevice().

      Specified by:
      clearActivity in interface SwitchContainer
      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
    • setSpeedCheck

      public void setSpeedCheck(boolean doSpeedCheck)
      Directs the container to avoid the calls to doSpeed() in methods that communicate with the Thermocron. To ensure that all parts can talk to the 1-Wire bus at their desired speed, each method contains a call to doSpeed(). However, this is an expensive operation. If a user manages the bus speed in an application, call this method with doSpeedCheck as false. The default behavior is to call doSpeed().
      Parameters:
      doSpeedCheck - true for doSpeed() to be called before every 1-Wire bus access, false to skip this expensive call
      See Also:
    • setSearchConditions

      public void setSearchConditions(byte channel, byte source, byte polarity, byte[] state)

      Programs the Conditional Search options for the DS2406/2407.

      The DS2406/2407 supports Conditional Searches with user programmable search conditions. This means that the part can alarm on several kinds of conditions, programmable by the user.

      The user can select a channel and a source to compare to a polarity. If the source's logical value is equal to the polarity, the device alarms (responds to a Conditional Search). For instance, if channel is CHANNEL_A, source is SOURCE_ACTIVITY_LATCH, and polarity is POLARITY_ONE, then the device will respond to a Conditional Search when the activity latch on channel A is 1 (when activity has been detected on channel A). When channel is CHANNEL_BOTH, the selected source signals are ORed for comparison with the polarity. When channel is CHANNEL_NONE, the selected source signal is considered a logical '0'. In other words, if channel is CHANNEL_NONE, if polarity is POLARITY_ZERO, the device always responds to a Conditional Search. If polarity is POLARITY_ONE, the device never responds to a Conditional Search.

      Note that for any of these options, the value DONT_CHANGE will insure that the value previously used by the DS2406/2407 will not be altered.

      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().

      Also note that the Hidden Mode of the DS2407 is not supported in this implementation as an option for source selection. Hidden Mode was phased out for the newer DS2406. See the datasheet for the DS2407 for more information on Hidden Mode.

      Parameters:
      channel - the channel of interest for the source of the conditional check (valid values are CHANNEL_NONE, CHANNEL_A_ONLY, CHANNEL_B_ONLY, CHANNEL_BOTH, and DONT_CHANGE)
      source - the source selection for the conditional check (valid values are SOURCE_ACTIVITY_LATCH, SOURCE_FLIP_FLOP, SOURCE_PIO, and DONT_CHANGE)
      polarity - the polarity selection for the conditional check (valid values are POLARITY_ZERO, POLARITY_ONE, and DONT_CHANGE)
      state - current state of the device returned from readDevice()
      See Also:
    • channelAccess

      public byte[] channelAccess(byte[] inbuffer, boolean toggleRW, boolean readInitially, int CRCMode, int channelMode, boolean clearActivity, boolean interleave) throws OneWireException, OneWireIOException

      Accesses the PIO channels to sense the logical status of the output node. This method supports all the modes of communication with the part as described in the datasheet for the DS2406/2407.

      Parameters:
      inbuffer - The input buffer. Depending on the other options chosen to this method, this will contain data to be written to the channels or it will hold space for data that will be read.
      toggleRW - By selecting toggleRW to be true, the part will alternately read and write bytes from and to this channel. Setting toggleRW to false means that only one operation will occur, whichever operation is selected by readInitially.
      NOTE: When toggleRW is true the 'read' bytes are automatically provided and only the results of the read bytes are returned.
      readInitially - If readInitially is true, the first operation to occur will be a read, else it will be a write. If toggleRW is false, the operation chosen by this flag is the only operation that will occur. If toggleRW is true, this operation is the one that will occur first, then the other will occur. For example, if toggleRW is true and readInitially is false (and you only have one channel communication), 8 bits will be written to channel A and then 8 bits will be read from channel A.
      CRCMode - The 2406/7 supports 4 CRC generation modes for error detection when performing channel access. This argument should have one of the following values:
       
           CRC_DISABLE        Never generate a CRC
           CRC_EVERY_BYTE     Generate a CRC after every byte transmission.
           CRC_EVERY_8_BYTES  Generate a CRC after every 8 bytes.
           CRC_EVERY_32_BYTES Generate a CRC after every 32 bytes.
       
                            
      Invalid values will be masked to valid values. The CRC is 16 bits, and does not get passed back with the output. This method returns null on a CRC failure.
      channelMode - The 2406/7 supports 3 modes of channel communication. This argument should take one of the following values:
       
           CHANNEL_A_ONLY  Only communicate with PIO A
           CHANNEL_B_ONLY  Only communicate with PIO B
           CHANNEL_BOTH    Communicate with both PIO's
       
                            
      If CHANNEL_BOTH is selected, data is written and read from the input buffer to the two channels. See the datasheet for a description of operation in this mode. If communicating with both channels, it is up to the caller to format the data correctly in the input buffer so the correct channel gets the correct data. Similarly, any return data must be parsed by the user.
      clearActivity - true to reset the activity latch
      interleave - The value for the Interleave Control bit. If true, operates in synchronous mode. If false, operates in asynchronous mode. See the datasheet for a discussion of asynchronous and synchronous mode. This argument only matters if communicating with both channels.
      Returns:
      If any bytes were read, this returns a byte array of data read from the channel access. If no bytes were read, it will return the input buffer that was to be written.
      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
      See Also: