Class USerialAdapter

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

public class USerialAdapter extends DSPortAdapter
The USerialAdapter class implements the DSPortAdapter interface for a DS2480 based serial adapter such as the DS9097U-009 or DS9097U-S09.

Instances of valid USerialAdapter's are retrieved from methods in OneWireAccessProvider.

The DSPortAdapter methods can be organized into the following categories:

See Also:
  • Constructor Details

    • USerialAdapter

      public USerialAdapter()
      Constructs a DS9097U serial adapter class
  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • CleanUpByThread

      public static void CleanUpByThread(Thread t)
      Cleans up the resources used by the thread argument. If another thread starts communicating with this port, and then goes away, there is no way to relinquish the port without stopping the process. This method allows other threads to clean up.
      Parameters:
      thread - that may have used a USerialAdapter
    • getAdapterName

      public String getAdapterName()
      Retrieve 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()
      Retrieve 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()
      Retrieve a version string for this class.
      Specified by:
      getClassVersion in class DSPortAdapter
      Returns:
      version string
    • getPortNames

      public Enumeration<String> getPortNames()
      Retrieve 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
    • selectPort

      public boolean selectPort(String newPortName) throws OneWireIOException, OneWireException
      Specify a platform appropriate port name for this adapter. Note that even though the port has been selected, it's ownership may be relinquished if it is not currently held in a 'exclusive' block. This class will then try to re-acquire the port when needed. If the port cannot be re-acquired when the exception PortInUseException will be thrown.
      Specified by:
      selectPort in class DSPortAdapter
      Parameters:
      newPortName - name of the target port, retrieved from getPortNames()
      Returns:
      true if the port was acquired, false if the port is not available.
      Throws:
      OneWireIOException - If port does not exist, or unable to communicate with port.
      OneWireException - If port does not exist
    • getPortName

      public String getPortName() throws OneWireException
      Retrieve the name of the selected port as a String.
      Specified by:
      getPortName in class DSPortAdapter
      Returns:
      String of selected port
      Throws:
      OneWireException - if valid port not yet selected
    • freePort

      public void freePort() throws OneWireException
      Free ownership of the selected port if it is currently owned back to the system. This should only be called if the recently selected port does not have an adapter or at the end of your application's use of the port.
      Specified by:
      freePort in class DSPortAdapter
      Throws:
      OneWireException - If port does not exist
    • adapterDetected

      public boolean adapterDetected() throws OneWireIOException, OneWireException
      Detect adapter presence on the selected port.
      Specified by:
      adapterDetected in class DSPortAdapter
      Returns:
      true if the adapter is confirmed to be connected to the selected port, false if the adapter is not connected.
      Throws:
      OneWireIOException
      OneWireException
    • getAdapterVersion

      public String getAdapterVersion() throws OneWireIOException, OneWireException
      Retrieve the version of the adapter.
      Overrides:
      getAdapterVersion in class DSPortAdapter
      Returns:
      String of the adapter version. It will return "" if the adapter version is not or cannot be known.
      Throws:
      OneWireIOException - on a 1-Wire communication error such as no device present. 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
    • getAdapterAddress

      public String getAdapterAddress() throws OneWireIOException, OneWireException
      Retrieve the address of the adapter if it has one.
      Overrides:
      getAdapterAddress in class DSPortAdapter
      Returns:
      String of the adapter address. It will return "" if the adapter does not have an address. The address is a string representation of an 1-Wire address.
      Throws:
      OneWireIOException - on a 1-Wire communication error such as no device present. 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:
    • canOverdrive

      public boolean canOverdrive() throws OneWireIOException, OneWireException
      Returns whether adapter can physically support overdrive mode.
      Overrides:
      canOverdrive in class DSPortAdapter
      Returns:
      true if this port adapter can do OverDrive, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canHyperdrive

      public boolean canHyperdrive() throws OneWireIOException, OneWireException
      Returns whether the adapter can physically support hyperdrive mode.
      Overrides:
      canHyperdrive in class DSPortAdapter
      Returns:
      true if this port adapter can do HyperDrive, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canFlex

      public boolean canFlex() throws OneWireIOException, OneWireException
      Returns whether the adapter can physically support flex speed mode.
      Overrides:
      canFlex in class DSPortAdapter
      Returns:
      true if this port adapter can do flex speed, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canProgram

      public boolean canProgram() throws OneWireIOException, OneWireException
      Returns whether adapter can physically support 12 volt power mode.
      Overrides:
      canProgram in class DSPortAdapter
      Returns:
      true if this port adapter can do Program voltage, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canDeliverPower

      public boolean canDeliverPower() throws OneWireIOException, OneWireException
      Returns whether the adapter can physically support strong 5 volt power mode.
      Overrides:
      canDeliverPower in class DSPortAdapter
      Returns:
      true if this port adapter can do strong 5 volt mode, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canDeliverSmartPower

      public boolean canDeliverSmartPower() throws OneWireIOException, OneWireException
      Returns whether the adapter can physically support "smart" strong 5 volt power mode. "smart" power delivery is the ability to deliver power until it is no longer needed. The current drop it detected and power delivery is stopped.
      Overrides:
      canDeliverSmartPower in class DSPortAdapter
      Returns:
      true if this port adapter can do "smart" strong 5 volt mode, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • canBreak

      public boolean canBreak() throws OneWireIOException, OneWireException
      Returns whether adapter can physically support 0 volt 'break' mode.
      Overrides:
      canBreak in class DSPortAdapter
      Returns:
      true if this port adapter can do break, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error with the adapter
      OneWireException - on a setup error with the 1-Wire adapter
    • findFirstDevice

      public boolean findFirstDevice() throws OneWireIOException, OneWireException
      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.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • findNextDevice

      public boolean findNextDevice() throws OneWireIOException, OneWireException
      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.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getAddress

      public void getAddress(byte[] address)
      Copies the 'current' iButton address being used by the adapter into the array. This address is the last iButton or 1-Wire device found in a search (findNextDevice()...).
      Specified by:
      getAddress in class DSPortAdapter
      Parameters:
      address - An array to be filled with the current iButton address.
      See Also:
    • setAddress

      public void setAddress(byte[] address)
      Copies the provided 1-Wire device address into the 'current' array. This address will then be used in the getDeviceContainer() method. Permits the adapter instance to create containers of devices it did not find in a search.
      Parameters:
      address - An array to be copied into the current iButton address.
    • isPresent

      public boolean isPresent(byte[] address) throws OneWireIOException, OneWireException
      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.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
      See Also:
    • isAlarming

      public boolean isAlarming(byte[] address) throws OneWireIOException, OneWireException
      Verifies that the iButton or 1-Wire device specified is present on the 1-Wire Network and in an alarm state. This does not affect the 'current' device state information used in searches (findNextDevice...).
      Overrides:
      isAlarming in class DSPortAdapter
      Parameters:
      address - device address to verify is present and alarming
      Returns:
      true if device is present and alarming else false.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
      See Also:
    • setSearchOnlyAlarmingDevices

      public void setSearchOnlyAlarmingDevices()
      Set the 1-Wire Network search to find only iButtons and 1-Wire devices that are in an 'Alarm' state that signals a need for attention. Not all iButton types have this feature. Some that do: DS1994, DS1920, DS2407. This selective searching can be canceled with the 'setSearchAllDevices()' method.
      Specified by:
      setSearchOnlyAlarmingDevices in class DSPortAdapter
      See Also:
    • setNoResetSearch

      public void setNoResetSearch()
      Set the 1-Wire Network search to not perform a 1-Wire reset before a search. This feature is chiefly used with the DS2409 1-Wire coupler. The normal reset before each search can be restored with the 'setSearchAllDevices()' method.
      Specified by:
      setNoResetSearch in class DSPortAdapter
    • setSearchAllDevices

      public void setSearchAllDevices()
      Set the 1-Wire Network search to find all iButtons and 1-Wire devices whether they are in an 'Alarm' state or not and restores the default setting of providing a 1-Wire reset command before each search. (see setNoResetSearch() method).
      Specified by:
      setSearchAllDevices in class DSPortAdapter
      See Also:
    • targetAllFamilies

      public void targetAllFamilies()
      Removes any selectivity during a search for iButtons or 1-Wire devices by family type. The unique address for each iButton and 1-Wire device contains a family descriptor that indicates the capabilities of the device.
      Overrides:
      targetAllFamilies in class DSPortAdapter
      See Also:
    • targetFamily

      public void targetFamily(int familyID)
      Takes an integer to selectively search for this desired family type. If this method is used, then no devices of other families will be found by getFirstButton() invalid input: '&' getNextButton().
      Overrides:
      targetFamily in class DSPortAdapter
      Parameters:
      familyID - the code of the family type to target for searches
      family - the code of the family type to target for searches
      See Also:
    • targetFamily

      public void targetFamily(byte[] familyID)
      Takes an array of bytes to use for selectively searching for acceptable family codes. If used, only devices with family codes in this array will be found by any of the search methods.
      Overrides:
      targetFamily in class DSPortAdapter
      Parameters:
      familyID - array of the family types to target for searches
      family - array of the family types to target for searches
      See Also:
    • excludeFamily

      public void excludeFamily(int familyID)
      Takes an integer family code to avoid when searching for iButtons. or 1-Wire devices. If this method is used, then no devices of this family will be found by any of the search methods.
      Overrides:
      excludeFamily in class DSPortAdapter
      Parameters:
      familyID - the code of the family type NOT to target in searches
      family - the code of the family type NOT to target in searches
      See Also:
    • excludeFamily

      public void excludeFamily(byte[] familyID)
      Takes an array of bytes containing family codes to avoid when finding iButtons or 1-Wire devices. If used, then no devices with family codes in this array will be found by any of the search methods.
      Overrides:
      excludeFamily in class DSPortAdapter
      Parameters:
      familyID - array of family cods NOT to target for searches
      family - array of family cods NOT to target for searches
      See Also:
    • beginExclusive

      public boolean beginExclusive(boolean blocking) throws OneWireException
      Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device. This method should be used for critical sections of code where a sequence of commands must not be interrupted by communication of threads with other iButtons, and it is permissible to sustain a delay in the special case that another thread has already been granted exclusive access and this access has not yet been relinquished.

      Specified by:
      beginExclusive in class DSPortAdapter
      Parameters:
      blocking - true if want to block waiting for exclusive access to the adapter
      Returns:
      true if blocking was false and a exclusive session with the adapter was acquired
      Throws:
      OneWireException - on a setup error with the 1-Wire adapter
    • endExclusive

      public void endExclusive()
      Relinquishes exclusive control of the 1-Wire Network. This command dynamically marks the end of a critical section and should be used when exclusive control is no longer needed.
      Specified by:
      endExclusive in class DSPortAdapter
    • putBit

      public void putBit(boolean bitValue) throws OneWireIOException, OneWireException
      Sends a bit to the 1-Wire Network.
      Specified by:
      putBit in class DSPortAdapter
      Parameters:
      bitValue - the bit value to send to the 1-Wire Network.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getBit

      public boolean getBit() throws OneWireIOException, OneWireException
      Gets a bit from the 1-Wire Network.
      Specified by:
      getBit in class DSPortAdapter
      Returns:
      the bit value received from the the 1-Wire Network.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • putByte

      public void putByte(int byteValue) throws OneWireIOException, OneWireException
      Sends a byte to the 1-Wire Network.
      Specified by:
      putByte in class DSPortAdapter
      Parameters:
      byteValue - the byte value to send to the 1-Wire Network.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getByte

      public int getByte() throws OneWireIOException, OneWireException
      Gets a byte from the 1-Wire Network.
      Specified by:
      getByte in class DSPortAdapter
      Returns:
      the byte value received from the the 1-Wire Network.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getBlock

      public byte[] getBlock(int len) throws OneWireIOException, OneWireException
      Get a block of data from the 1-Wire Network.
      Specified by:
      getBlock in class DSPortAdapter
      Parameters:
      len - length of data bytes to receive
      Returns:
      the data received from the 1-Wire Network.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getBlock

      public void getBlock(byte[] arr, int len) throws OneWireIOException, OneWireException
      Get a block of data from the 1-Wire Network and write it into the provided array.
      Specified by:
      getBlock in class DSPortAdapter
      Parameters:
      arr - array in which to write the received bytes
      len - length of data bytes to receive
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • getBlock

      public void getBlock(byte[] arr, int off, int len) throws OneWireIOException, OneWireException
      Get a block of data from the 1-Wire Network and write it into the provided array.
      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
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • dataBlock

      public void dataBlock(byte[] dataBlock, int off, int len) throws OneWireIOException, OneWireException
      Sends a block of data and returns the data received in the same array. This method is used when sending a block that contains reads and writes. The 'read' portions of the data block need to be pre-loaded with 0xFF's. It starts sending data from the index at offset 'off' for length 'len'.
      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'
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • reset

      public int reset() throws OneWireIOException, OneWireException
      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.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • setPowerDuration

      public void setPowerDuration(int timeFactor) throws OneWireIOException, OneWireException
      Sets the duration to supply power to the 1-Wire Network. This method takes a time parameter that indicates the program pulse length when the method startPowerDelivery().

      Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.

      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 setBusNormal() method is called.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • startPowerDelivery

      public boolean startPowerDelivery(int changeCondition) throws OneWireIOException, OneWireException
      Sets the 1-Wire Network voltage to supply power to an iButton device. This method takes a time parameter that indicates whether the power delivery should be done immediately, or after certain conditions have been met.

      Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.

      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 if the voltage change was successful, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • setProgramPulseDuration

      public void setProgramPulseDuration(int timeFactor) throws OneWireIOException, OneWireException
      Sets the duration for providing a program pulse on the 1-Wire Network. This method takes a time parameter that indicates the program pulse length when the method startProgramPulse().

      Note: to avoid getting an exception, use the canDeliverPower() method to check it's availability.

      Overrides:
      setProgramPulseDuration in class DSPortAdapter
      Parameters:
      timeFactor -
      • 6 (DELIVERY_EPROM) provide program pulse for 480 microseconds
      • 5 (DELIVERY_INFINITE) provide power until the setBusNormal() method is called.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter
    • startProgramPulse

      public boolean startProgramPulse(int changeCondition) throws OneWireIOException, OneWireException
      Sets the 1-Wire Network voltage to eprom programming level. This method takes a time parameter that indicates whether the power delivery should be done immediately, or after certain conditions have been met.

      Note: to avoid getting an exception, use the canProgram() method to check it's availability.

      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 if the voltage change was successful, false otherwise.
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter or the adapter does not support this operation
    • startBreak

      public void startBreak() throws OneWireIOException, OneWireException
      Sets the 1-Wire Network voltage to 0 volts. This method is used rob all 1-Wire Network devices of parasite power delivery to force them into a hard reset.
      Overrides:
      startBreak in class DSPortAdapter
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter or the adapter does not support this operation
    • setPowerNormal

      public void setPowerNormal() throws OneWireIOException, OneWireException
      Sets the 1-Wire Network voltage to normal level. This method is used to disable 1-Wire conditions created by startPowerDelivery and startProgramPulse. This method will automatically be called if a communication method is called while an outstanding power command is taking place.
      Overrides:
      setPowerNormal in class DSPortAdapter
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter or the adapter does not support this operation
    • setSpeed

      public void setSpeed(int speed) throws OneWireIOException, OneWireException
      This method takes an int representing the new speed of data transfer on the 1-Wire Network.

      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
      Throws:
      OneWireIOException - on a 1-Wire communication error
      OneWireException - on a setup error with the 1-Wire adapter or the adapter does not support this operation
    • getSpeed

      public int getSpeed()
      This method returns the current data transfer speed through a port to a 1-Wire Network.

      Overrides:
      getSpeed in class DSPortAdapter
      Returns:
      • 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