Class DumbAdapter

java.lang.Object
com.dalsemi.onewire.adapter.DSPortAdapter
com.dalsemi.onewire.adapter.DumbAdapter

public class DumbAdapter extends DSPortAdapter

This DSPortAdapter class was designed to be used for the iB-IDE's emulator. The DumbAdapter allows programmers to add and remove OneWireContainer objects that will be found in its search. The Java iButton emulator works by creating a class that subclasses all of OneWireContainer16's relevant methods and redirecting them to the emulation code. That object is then added to this class's list of OneWireContainers.

Note that methods such as selectPort and beginExclusive by default do nothing. This class is mainly meant for debugging using an emulated iButton. It will do a poor job of debugging any multi-threading, port-sharing issues.

See Also:
  • Constructor Details

    • DumbAdapter

      public DumbAdapter()
  • Method Details

    • addContainer

      public void addContainer(OneWireContainer c)
      Adds a OneWireContainer to the list of containers that this adapter object will find.
      Parameters:
      c - represents a 1-Wire device that this adapter will report from a search
    • removeContainer

      public void removeContainer(OneWireContainer c)
      Removes a OneWireContainer from the list of containers that this adapter object will find.
      Parameters:
      c - represents a 1-Wire device that this adapter should no longer report as found by a search
    • getAdapterName

      public String getAdapterName()
      Retrieves the name of the port adapter as a string. The 'Adapter' is a device that connects to a 'port' that allows one to communicate with an iButton or other 1-Wire device. As example of this is 'DS9097U'.
      Specified by:
      getAdapterName in class DSPortAdapter
      Returns:
      String representation of the port adapter.
    • getPortTypeDescription

      public String getPortTypeDescription()
      Retrieves a description of the port required by this port adapter. An example of a 'Port' would 'serial communication port'.
      Specified by:
      getPortTypeDescription in class DSPortAdapter
      Returns:
      String description of the port type required.
    • getClassVersion

      public String getClassVersion()
      Retrieves a version string for this class.
      Specified by:
      getClassVersion in class DSPortAdapter
      Returns:
      version string
    • getPortNames

      public Enumeration<String> getPortNames()
      Retrieves a list of the platform appropriate port names for this adapter. A port must be selected with the method 'selectPort' before any other communication methods can be used. Using a communication method before 'selectPort' will result in a OneWireException exception.
      Specified by:
      getPortNames in class DSPortAdapter
      Returns:
      Enumeration of type String that contains the port names
    • registerOneWireContainerClass

      public void registerOneWireContainerClass(int family, Class<?> OneWireContainerClass)
      This method does nothing in DumbAdapter.
      Overrides:
      registerOneWireContainerClass in class DSPortAdapter
      Parameters:
      family - the code of the family type to associate with this class.
      OneWireContainerClass - User provided class
    • selectPort

      public boolean selectPort(String portName)
      This method does nothing in DumbAdapter.
      Specified by:
      selectPort in class DSPortAdapter
      Parameters:
      portName - name of the target port, retrieved from getPortNames()
      Returns:
      always returns true
    • freePort

      public void freePort()
      This method does nothing in DumbAdapter.
      Specified by:
      freePort in class DSPortAdapter
    • getPortName

      public String getPortName()
      Retrieves the name of the selected port as a String.
      Specified by:
      getPortName in class DSPortAdapter
      Returns:
      always returns the String "NULL0"
    • adapterDetected

      public boolean adapterDetected()
      Detects adapter presence on the selected port. In DumbAdapter, the adapter is always detected.
      Specified by:
      adapterDetected in class DSPortAdapter
      Returns:
      true
    • canOverdrive

      public boolean canOverdrive()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canOverdrive in class DSPortAdapter
      Returns:
      true
    • canHyperdrive

      public boolean canHyperdrive()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canHyperdrive in class DSPortAdapter
      Returns:
      true
    • canFlex

      public boolean canFlex()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canFlex in class DSPortAdapter
      Returns:
      true
    • canProgram

      public boolean canProgram()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canProgram in class DSPortAdapter
      Returns:
      true
    • canDeliverPower

      public boolean canDeliverPower()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canDeliverPower in class DSPortAdapter
      Returns:
      true
    • canDeliverSmartPower

      public boolean canDeliverSmartPower()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canDeliverSmartPower in class DSPortAdapter
      Returns:
      true
    • canBreak

      public boolean canBreak()
      Applications might check this method and not attempt operation unless this method returns true. To make sure that a wide variety of applications can use this class, this method always returns true.
      Overrides:
      canBreak in class DSPortAdapter
      Returns:
      true
    • getAllDeviceContainers

      public Enumeration<OneWireContainer> getAllDeviceContainers()
      Returns an enumeration of OneWireContainer objects corresponding to all of the iButtons or 1-Wire devices found on the 1-Wire Network. In the case of the DumbAdapter, this method returns a simple copy of the internal java.util.Vector that stores all the 1-Wire devices this class finds in a search.
      Overrides:
      getAllDeviceContainers in class DSPortAdapter
      Returns:
      Enumeration of OneWireContainer objects found on the 1-Wire Network.
    • getFirstDeviceContainer

      public OneWireContainer getFirstDeviceContainer()
      Returns a OneWireContainer object corresponding to the first iButton or 1-Wire device found on the 1-Wire Network. If no devices are found, then a null reference will be returned. In most cases, all further communication with the device is done through the OneWireContainer.
      Overrides:
      getFirstDeviceContainer in class DSPortAdapter
      Returns:
      The first OneWireContainer object found on the 1-Wire Network, or null if no devices found.
    • getNextDeviceContainer

      public OneWireContainer getNextDeviceContainer()
      Returns a OneWireContainer object corresponding to the next iButton or 1-Wire device found. The previous 1-Wire device found is used as a starting point in the search. If no devices are found, then a null reference will be returned. In most cases, all further communication with the device is done through the OneWireContainer.
      Overrides:
      getNextDeviceContainer in class DSPortAdapter
      Returns:
      The next OneWireContainer object found on the 1-Wire Network, or null if no iButtons found.
    • findFirstDevice

      public boolean findFirstDevice()
      Returns true if the first iButton or 1-Wire device is found on the 1-Wire Network. If no devices are found, then false will be returned.
      Specified by:
      findFirstDevice in class DSPortAdapter
      Returns:
      true if an iButton or 1-Wire device is found.
    • findNextDevice

      public boolean findNextDevice()
      Returns true if the next iButton or 1-Wire device is found. The previous 1-Wire device found is used as a starting point in the search. If no more devices are found then false will be returned.
      Specified by:
      findNextDevice in class DSPortAdapter
      Returns:
      true if an iButton or 1-Wire device is found.
    • getAddress

      public void getAddress(byte[] address)
      Copies the 'current' 1-Wire device address being used by the adapter into the array. This address is the last iButton or 1-Wire device found in a search (findNextDevice()...). This method copies into a user generated array to allow the reuse of the buffer. When searching many iButtons on the one wire network, this will reduce the memory burn rate.
      Specified by:
      getAddress in class DSPortAdapter
      Parameters:
      address - An array to be filled with the current iButton address.
      See Also:
    • getAddressAsLong

      public long getAddressAsLong()
      Gets the 'current' 1-Wire device address being used by the adapter as a long. This address is the last iButton or 1-Wire device found in a search (findNextDevice()...).
      Overrides:
      getAddressAsLong in class DSPortAdapter
      Returns:
      long representation of the iButton address
      See Also:
    • getAddressAsString

      public String getAddressAsString()
      Gets the 'current' 1-Wire device address being used by the adapter as a String. This address is the last iButton or 1-Wire device found in a search (findNextDevice()...).
      Overrides:
      getAddressAsString in class DSPortAdapter
      Returns:
      String representation of the iButton address
      See Also:
    • isPresent

      public boolean isPresent(byte[] address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network. This does not affect the 'current' device state information used in searches (findNextDevice...).
      Overrides:
      isPresent in class DSPortAdapter
      Parameters:
      address - device address to verify is present
      Returns:
      true if device is present, else false.
      See Also:
    • isPresent

      public boolean isPresent(long address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network. This does not affect the 'current' device state information used in searches (findNextDevice...).
      Overrides:
      isPresent in class DSPortAdapter
      Parameters:
      address - device address to verify is present
      Returns:
      true if device is present, else false.
      See Also:
    • isPresent

      public boolean isPresent(String address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network. This does not affect the 'current' device state information used in searches (findNextDevice...).
      Overrides:
      isPresent in class DSPortAdapter
      Parameters:
      address - device address to verify is present
      Returns:
      true if device is present, else false.
      See Also:
    • isAlarming

      public boolean isAlarming(byte[] address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network and in an alarm state. This method is currently not implemented in DumbAdapter.
      Overrides:
      isAlarming in class DSPortAdapter
      Parameters:
      address - device address to verify is present and alarming
      Returns:
      false
      See Also:
    • isAlarming

      public boolean isAlarming(long address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network and in an alarm state. This method is currently not implemented in DumbAdapter.
      Overrides:
      isAlarming in class DSPortAdapter
      Parameters:
      address - device address to verify is present and alarming
      Returns:
      false
      See Also:
    • isAlarming

      public boolean isAlarming(String address)
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network and in an alarm state. This method is currently not implemented in DumbAdapter.
      Overrides:
      isAlarming in class DSPortAdapter
      Parameters:
      address - device address to verify is present and alarming
      Returns:
      false
      See Also:
    • select

      public boolean select(byte[] address)
      Selects the specified iButton or 1-Wire device by broadcasting its address. With a DumbAdapter, this method simply returns true. Warning, this does not verify that the device is currently present on the 1-Wire Network (See isPresent).
      Overrides:
      select in class DSPortAdapter
      Parameters:
      address - address of iButton or 1-Wire device to select
      Returns:
      true if device address was sent, false otherwise.
      See Also:
    • select

      public boolean select(long address) throws OneWireIOException, OneWireException
      Selects the specified iButton or 1-Wire device by broadcasting its address. With a DumbAdapter, this method simply returns true. Warning, this does not verify that the device is currently present on the 1-Wire Network (See isPresent).
      Overrides:
      select in class DSPortAdapter
      Parameters:
      address - address of iButton or 1-Wire device to select
      Returns:
      true if device address was sent, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
      See Also:
    • select

      public boolean select(String address) throws OneWireIOException, OneWireException
      Selects the specified iButton or 1-Wire device by broadcasting its address. With a DumbAdapter, this method simply returns true. Warning, this does not verify that the device is currently present on the 1-Wire Network (See isPresent).
      Overrides:
      select in class DSPortAdapter
      Parameters:
      address - address of iButton or 1-Wire device to select
      Returns:
      true if device address was sent, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
      See Also:
    • setSearchOnlyAlarmingDevices

      public void setSearchOnlyAlarmingDevices()
      This method does nothing in DumbAdapter.
      Specified by:
      setSearchOnlyAlarmingDevices in class DSPortAdapter
      See Also:
    • setNoResetSearch

      public void setNoResetSearch()
      This method does nothing in DumbAdapter.
      Specified by:
      setNoResetSearch in class DSPortAdapter
    • setSearchAllDevices

      public void setSearchAllDevices()
      This method does nothing in DumbAdapter.
      Specified by:
      setSearchAllDevices in class DSPortAdapter
      See Also:
    • targetAllFamilies

      public void targetAllFamilies()
      This method does nothing in DumbAdapter.
      Overrides:
      targetAllFamilies in class DSPortAdapter
      See Also:
    • targetFamily

      public void targetFamily(int family)
      This method does nothing in DumbAdapter.
      Overrides:
      targetFamily in class DSPortAdapter
      Parameters:
      family - the code of the family type to target for searches
      See Also:
    • targetFamily

      public void targetFamily(byte[] family)
      This method does nothing in DumbAdapter.
      Overrides:
      targetFamily in class DSPortAdapter
      Parameters:
      family - array of the family types to target for searches
      See Also:
    • excludeFamily

      public void excludeFamily(int family)
      This method does nothing in DumbAdapter.
      Overrides:
      excludeFamily in class DSPortAdapter
      Parameters:
      family - the code of the family type NOT to target in searches
      See Also:
    • excludeFamily

      public void excludeFamily(byte[] family)
      This method does nothing in DumbAdapter.
      Overrides:
      excludeFamily in class DSPortAdapter
      Parameters:
      family - array of family cods NOT to target for searches
      See Also:
    • beginExclusive

      public boolean beginExclusive(boolean blocking)
      This method does nothing in DumbAdapter.
      Specified by:
      beginExclusive in class DSPortAdapter
      Parameters:
      blocking - true if want to block waiting for exclusive access to the adapter
      Returns:
      true
    • endExclusive

      public void endExclusive()
      This method does nothing in DumbAdapter.
      Specified by:
      endExclusive in class DSPortAdapter
    • putBit

      public void putBit(boolean bitValue)
      Sends a bit to the 1-Wire Network. This method does nothing in DumbAdapter.
      Specified by:
      putBit in class DSPortAdapter
      Parameters:
      bitValue - the bit value to send to the 1-Wire Network.
    • getBit

      public boolean getBit()
      Gets a bit from the 1-Wire Network. This method does nothing in DumbAdapter.
      Specified by:
      getBit in class DSPortAdapter
      Returns:
      true
    • putByte

      public void putByte(int byteValue)
      This method does nothing in DumbAdapter.
      Specified by:
      putByte in class DSPortAdapter
      Parameters:
      byteValue - the byte value to send to the 1-Wire Network.
    • getByte

      public int getByte()
      This method does nothing in DumbAdapter.
      Specified by:
      getByte in class DSPortAdapter
      Returns:
      the value 0x0ff
    • getBlock

      public byte[] getBlock(int len)
      This method does nothing in DumbAdapter.
      Specified by:
      getBlock in class DSPortAdapter
      Parameters:
      len - length of data bytes to receive
      Returns:
      a new byte array of length len
    • getBlock

      public void getBlock(byte[] arr, int len)
      This method does nothing in DumbAdapter.
      Specified by:
      getBlock in class DSPortAdapter
      Parameters:
      arr - array in which to write the received bytes
      len - length of data bytes to receive
    • getBlock

      public void getBlock(byte[] arr, int off, int len)
      This method does nothing in DumbAdapter.
      Specified by:
      getBlock in class DSPortAdapter
      Parameters:
      arr - array in which to write the received bytes
      off - offset into the array to start
      len - length of data bytes to receive
    • dataBlock

      public void dataBlock(byte[] dataBlock, int off, int len)
      This method does nothing in DumbAdapter.
      Specified by:
      dataBlock in class DSPortAdapter
      Parameters:
      dataBlock - array of data to transfer to and from the 1-Wire Network.
      off - offset into the array of data to start
      len - length of data to send / receive starting at 'off'
    • reset

      public int reset()
      Sends a Reset to the 1-Wire Network.
      Specified by:
      reset in class DSPortAdapter
      Returns:
      the result of the reset. Potential results are:
      • 0 (RESET_NOPRESENCE) no devices present on the 1-Wire Network.
      • 1 (RESET_PRESENCE) normal presence pulse detected on the 1-Wire Network indicating there is a device present.
      • 2 (RESET_ALARM) alarming presence pulse detected on the 1-Wire Network indicating there is a device present and it is in the alarm condition. This is only provided by the DS1994/DS2404 devices.
      • 3 (RESET_SHORT) inticates 1-Wire appears shorted. This can be transient conditions in a 1-Wire Network. Not all adapter types can detect this condition.
      Note that in DumbAdapter, the only possible results are 0 and 1.
    • setPowerDuration

      public void setPowerDuration(int timeFactor)
      This method does nothing in DumbAdapter.
      Overrides:
      setPowerDuration in class DSPortAdapter
      Parameters:
      timeFactor -
      • 0 (DELIVERY_HALF_SECOND) provide power for 1/2 second.
      • 1 (DELIVERY_ONE_SECOND) provide power for 1 second.
      • 2 (DELIVERY_TWO_SECONDS) provide power for 2 seconds.
      • 3 (DELIVERY_FOUR_SECONDS) provide power for 4 seconds.
      • 4 (DELIVERY_SMART_DONE) provide power until the the device is no longer drawing significant power.
      • 5 (DELIVERY_INFINITE) provide power until the setPowerNormal() method is called.
    • startPowerDelivery

      public boolean startPowerDelivery(int changeCondition)
      This method does nothing in DumbAdapter.
      Overrides:
      startPowerDelivery in class DSPortAdapter
      Parameters:
      changeCondition -
      • 0 (CONDITION_NOW) operation should occur immediately.
      • 1 (CONDITION_AFTER_BIT) operation should be pending execution immediately after the next bit is sent.
      • 2 (CONDITION_AFTER_BYTE) operation should be pending execution immediately after next byte is sent.
      Returns:
      true
    • setProgramPulseDuration

      public void setProgramPulseDuration(int timeFactor)
      This method does nothing in DumbAdapter.
      Overrides:
      setProgramPulseDuration in class DSPortAdapter
      Parameters:
      timeFactor -
      • 7 (DELIVERY_EPROM) provide program pulse for 480 microseconds
      • 5 (DELIVERY_INFINITE) provide power until the setPowerNormal() method is called.
    • startProgramPulse

      public boolean startProgramPulse(int changeCondition)
      This method does nothing in DumbAdapter.
      Overrides:
      startProgramPulse in class DSPortAdapter
      Parameters:
      changeCondition -
      • 0 (CONDITION_NOW) operation should occur immediately.
      • 1 (CONDITION_AFTER_BIT) operation should be pending execution immediately after the next bit is sent.
      • 2 (CONDITION_AFTER_BYTE) operation should be pending execution immediately after next byte is sent.
      Returns:
      true
    • startBreak

      public void startBreak()
      This method does nothing in DumbAdapter.
      Overrides:
      startBreak in class DSPortAdapter
    • setPowerNormal

      public void setPowerNormal()
      This method does nothing in DumbAdapter.
      Overrides:
      setPowerNormal in class DSPortAdapter
    • setSpeed

      public void setSpeed(int speed)
      This method does nothing in DumbAdapter.
      Overrides:
      setSpeed in class DSPortAdapter
      Parameters:
      speed -
      • 0 (SPEED_REGULAR) set to normal communication speed
      • 1 (SPEED_FLEX) set to flexible communication speed used for long lines
      • 2 (SPEED_OVERDRIVE) set to normal communication speed to overdrive
      • 3 (SPEED_HYPERDRIVE) set to normal communication speed to hyperdrive
      • >3 future speeds
    • getSpeed

      public int getSpeed()
      This method does nothing in DumbAdapter.
      Overrides:
      getSpeed in class DSPortAdapter
      Returns:
      invalid input: '<'the last value passed to the setSpeed(int) method, or 0
    • getDeviceContainer

      public OneWireContainer getDeviceContainer(byte[] address)
      Gets the container from this adapter whose address matches the address of a container in the DumbAdapter's internal java.util.Vector.
      Overrides:
      getDeviceContainer in class DSPortAdapter
      Parameters:
      address - device address with which to find a container
      Returns:
      The OneWireContainer object, or null if no match could be found.
      See Also:
    • getDeviceContainer

      public OneWireContainer getDeviceContainer(long address)
      Gets the container from this adapter whose address matches the address of a container in the DumbAdapter's internal java.util.Vector.
      Overrides:
      getDeviceContainer in class DSPortAdapter
      Parameters:
      address - device address with which to find a container
      Returns:
      The OneWireContainer object, or null if no match could be found.
      See Also:
    • getDeviceContainer

      public OneWireContainer getDeviceContainer(String address)
      Gets the container from this adapter whose address matches the address of a container in the DumbAdapter's internal java.util.Vector.
      Overrides:
      getDeviceContainer in class DSPortAdapter
      Parameters:
      address - device address with which to find a container
      Returns:
      The OneWireContainer object, or null if no match could be found.
      See Also:
    • getDeviceContainer

      public OneWireContainer getDeviceContainer()
      Returns a OneWireContainer object using the current 1-Wire network address. The internal state of the port adapter keeps track of the last address found and is able to create container objects from this state.
      Overrides:
      getDeviceContainer in class DSPortAdapter
      Returns:
      the OneWireContainer object
    • isValidFamily

      protected boolean isValidFamily(byte[] address)
      Checks to see if the family found is in the desired include group.
      Overrides:
      isValidFamily in class DSPortAdapter
      Returns:
      true if in include group