⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dumbadapter.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.adapter;// importsimport java.util.Enumeration;import com.dalsemi.onewire.container.OneWireContainer;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.OneWireException;import java.util.Vector;import java.util.Hashtable;/** * <p>This <code>DSPortAdapter</code> class was designed to be used for * the iB-IDE's emulator.  The <code>DumbAdapter</code> allows * programmers to add and remove <code>OneWireContainer</code> * objects that will be found in its search.  The Java iButton * emulator works by creating a class that subclasses all of * <code>OneWireContainer16</code>'s relevant methods and redirecting them * to the emulation code.  That object is then added to this class's * list of <code>OneWireContainer</code>s.</p> * * <p>Note that methods such as <code>selectPort</code> and * <code>beginExclusive</code> 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 com.dalsemi.onewire.adapter.DSPortAdapter * @see com.dalsemi.onewire.container.OneWireContainer * * @version    0.00, 16 Mar 2001 * @author     K */public class DumbAdapter extends DSPortAdapter{   //--------   //-------- Variables   //--------   int containers_index = 0;   private Vector containers = new Vector();   /**    * Adds a <code>OneWireContainer</code> to the list of containers that    * this adapter object will find.    *    * @param c represents a 1-Wire device that this adapter will report from a search    */   public void addContainer(OneWireContainer c)   {        synchronized (containers)        {            containers.addElement(c);        }   }   /**    * Removes a <code>OneWireContainer</code> from the list of containers that    * this adapter object will find.    *    * @param c represents a 1-Wire device that this adapter should no longer    *        report as found by a search    */   public void removeContainer(OneWireContainer c)   {        synchronized (containers)        {            containers.removeElement(c);        }   }   /**    * Hashtable to contain the user replaced OneWireContainers    */   private Hashtable registeredOneWireContainerClasses = new Hashtable(5);   /**    * Byte array of families to include in search    */   private byte[] include;   /**    * Byte array of families to exclude from search    */   private byte[] exclude;   //--------   //-------- Methods   //--------   /**    * 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'.    *    * @return  <code>String</code> representation of the port adapter.    */   public String getAdapterName ()   {        return "DumbAdapter";   }   /**    * Retrieves a description of the port required by this port adapter.    * An example of a 'Port' would 'serial communication port'.    *    * @return  <code>String</code> description of the port type required.    */   public String getPortTypeDescription ()   {        return "Virtual Emulated Port";   }   /**    * Retrieves a version string for this class.    *    * @return  version string    */   public String getClassVersion ()   {        return "0.00";   }   //--------   //-------- Port Selection   //--------   /**    * 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 communcation method before 'selectPort' will result in    * a <code>OneWireException</code> exception.    *    * @return  <code>Enumeration</code> of type <code>String</code> that contains the port    * names    */   public Enumeration getPortNames ()   {        Vector portNames = new Vector();        portNames.addElement("NULL0");        return portNames.elements();   }   /**    * This method does nothing in <code>DumbAdapter</code>.    *    */   public void registerOneWireContainerClass (int family,  Class OneWireContainerClass)   {   }   /**    * This method does nothing in <code>DumbAdapter</code>.    *    * @param  portName  name of the target port, retrieved from    * getPortNames()    *    * @return always returns <code>true</code>    */   public boolean selectPort (String portName)   {        //be lazy, allow anything        return true;   }   /**    * This method does nothing in <code>DumbAdapter</code>.    */   public void freePort ()   {       //airball   }   /**    * Retrieves the name of the selected port as a <code>String</code>.    *    * @return  always returns the <code>String</code> "NULL0"    */   public String getPortName ()   {        return "NULL0";   }   //--------   //-------- Adapter detection   //--------   /**    * Detects adapter presence on the selected port.  In <code>DumbAdapter</code>,    * the adapter is always detected.    *    * @return  <code>true</code>    */   public boolean adapterDetected ()   {        return true;   }   //--------   //-------- Adapter features   //--------   /* The following interogative methods are provided so that client code    * can react selectively to underlying states without generating an    * exception.    */   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    *    */   public boolean canOverdrive ()   {      //don't want someone to bail because of this      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canHyperdrive ()   {      //don't want someone to bail because of this, although it doesn't exist yet      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canFlex ()   {      //don't want someone to bail because of this      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canProgram ()   {      //don't want someone to bail because of this      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canDeliverPower ()   {      //don't want someone to bail because of this      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canDeliverSmartPower ()   {      //don't want someone to bail because of this      return true;   }   /**    * Applications might check this method and not attempt operation unless this method    * returns <code>true</code>. To make sure that a wide variety of applications can use this class,    * this method always returns <code>true</code>.    *    * @return  <code>true</code>    */   public boolean canBreak ()   {      //don't want someone to bail because of this      return true;   }   //--------   //-------- Finding iButtons and 1-Wire devices   //--------   /**    * Returns an enumeration of <code>OneWireContainer</code> objects corresponding    * to all of the iButtons or 1-Wire devices found on the 1-Wire Network.  In the case of    * the <code>DumbAdapter</code>, this method returns a simple copy of the internal    * <code>java.util.Vector</code> that stores all the 1-Wire devices this class finds    * in a search.    *    * @return  <code>Enumeration</code> of <code>OneWireContainer</code> objects    * found on the 1-Wire Network.    */   public Enumeration getAllDeviceContainers ()   {        Vector copy_vector = new Vector();        synchronized (containers)        {            for (int i=0;i<containers.size();i++)            {                copy_vector.addElement(containers.elementAt(i));            }        }        return copy_vector.elements();   }   /**    * Returns a <code>OneWireContainer</code> object corresponding to the first iButton    * or 1-Wire device found on the 1-Wire Network. If no devices are found,    * then a <code>null</code> reference will be returned. In most cases, all further    * communication with the device is done through the <code>OneWireContainer</code>.    *    * @return  The first <code>OneWireContainer</code> object found on the    * 1-Wire Network, or <code>null</code> if no devices found.    */   public OneWireContainer getFirstDeviceContainer ()   {      synchronized(containers)      {        if (containers.size() > 0)        {            containers_index = 1;            return (OneWireContainer) containers.elementAt(0);        }        else            return null;      }   }   /**    * Returns a <code>OneWireContainer</code> 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 <code>null</code> reference will be returned. In most cases, all further    * communication with the device is done through the <code>OneWireContainer</code>.    *    * @return  The next <code>OneWireContainer</code> object found on the    * 1-Wire Network, or <code>null</code> if no iButtons found.    */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -