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

📄 dsportadapter.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------- * 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;/** * The abstract base class for all 1-Wire port * adapter objects.  An implementation class of this type is therefore * independent of the adapter type.  Instances of valid DSPortAdapter's are * retrieved from methods in * {@link com.dalsemi.onewire.OneWireAccessProvider OneWireAccessProvider}. * * <P>The DSPortAdapter methods can be organized into the following categories: </P> * <UL> *   <LI> <B> Information </B> *     <UL> *       <LI> {@link #getAdapterName() getAdapterName} *       <LI> {@link #getPortTypeDescription() getPortTypeDescription} *       <LI> {@link #getClassVersion() getClassVersion} *       <LI> {@link #adapterDetected() adapterDetected} *       <LI> {@link #getAdapterVersion() getAdapterVersion} *       <LI> {@link #getAdapterAddress() getAdapterAddress} *     </UL> *   <LI> <B> Port Selection </B> *     <UL> *       <LI> {@link #getPortNames() getPortNames} *       <LI> {@link #selectPort(String) selectPort} *       <LI> {@link #getPortName() getPortName} *       <LI> {@link #freePort() freePort} *     </UL> *   <LI> <B> Adapter Capabilities </B> *     <UL> *       <LI> {@link #canOverdrive() canOverdrive} *       <LI> {@link #canHyperdrive() canHyperdrive} *       <LI> {@link #canFlex() canFlex} *       <LI> {@link #canProgram() canProgram} *       <LI> {@link #canDeliverPower() canDeliverPower} *       <LI> {@link #canDeliverSmartPower() canDeliverSmartPower} *       <LI> {@link #canBreak() canBreak} *     </UL> *   <LI> <B> 1-Wire Network Semaphore </B> *     <UL> *       <LI> {@link #beginExclusive(boolean) beginExclusive} *       <LI> {@link #endExclusive() endExclusive} *     </UL> *   <LI> <B> 1-Wire Device Discovery </B> *     <UL> *       <LI> Selective Search Options *         <UL> *          <LI> {@link #targetAllFamilies() targetAllFamilies} *          <LI> {@link #targetFamily(int) targetFamily(int)} *          <LI> {@link #targetFamily(byte[]) targetFamily(byte[])} *          <LI> {@link #excludeFamily(int) excludeFamily(int)} *          <LI> {@link #excludeFamily(byte[]) excludeFamily(byte[])} *          <LI> {@link #setSearchOnlyAlarmingDevices() setSearchOnlyAlarmingDevices} *          <LI> {@link #setNoResetSearch() setNoResetSearch} *          <LI> {@link #setSearchAllDevices() setSearchAllDevices} *         </UL> *       <LI> Search With Automatic 1-Wire Container creation *         <UL> *          <LI> {@link #getAllDeviceContainers() getAllDeviceContainers} *          <LI> {@link #getFirstDeviceContainer() getFirstDeviceContainer} *          <LI> {@link #getNextDeviceContainer() getNextDeviceContainer} *         </UL> *       <LI> Search With NO 1-Wire Container creation *         <UL> *          <LI> {@link #findFirstDevice() findFirstDevice} *          <LI> {@link #findNextDevice() findNextDevice} *          <LI> {@link #getAddress(byte[]) getAddress(byte[])} *          <LI> {@link #getAddressAsLong() getAddressAsLong} *          <LI> {@link #getAddressAsString() getAddressAsString} *         </UL> *       <LI> Manual 1-Wire Container creation *         <UL> *          <LI> {@link #getDeviceContainer(byte[]) getDeviceContainer(byte[])} *          <LI> {@link #getDeviceContainer(long) getDeviceContainer(long)} *          <LI> {@link #getDeviceContainer(String) getDeviceContainer(String)} *          <LI> {@link #getDeviceContainer() getDeviceContainer()} *         </UL> *     </UL> *   <LI> <B> 1-Wire Network low level access (usually not called directly) </B> *     <UL> *       <LI> Device Selection and Presence Detect *         <UL> *          <LI> {@link #isPresent(byte[]) isPresent(byte[])} *          <LI> {@link #isPresent(long) isPresent(long)} *          <LI> {@link #isPresent(String) isPresent(String)} *          <LI> {@link #isAlarming(byte[]) isAlarming(byte[])} *          <LI> {@link #isAlarming(long) isAlarming(long)} *          <LI> {@link #isAlarming(String) isAlarming(String)} *          <LI> {@link #select(byte[]) select(byte[])} *          <LI> {@link #select(long) select(long)} *          <LI> {@link #select(String) select(String)} *         </UL> *       <LI> Raw 1-Wire IO *         <UL> *          <LI> {@link #reset() reset} *          <LI> {@link #putBit(boolean) putBit} *          <LI> {@link #getBit() getBit} *          <LI> {@link #putByte(int) putByte} *          <LI> {@link #getByte() getByte} *          <LI> {@link #getBlock(int) getBlock(int)} *          <LI> {@link #getBlock(byte[], int) getBlock(byte[], int)} *          <LI> {@link #getBlock(byte[], int, int) getBlock(byte[], int, int)} *          <LI> {@link #dataBlock(byte[], int, int) dataBlock(byte[], int, int)} *         </UL> *       <LI> 1-Wire Speed and Power Selection *         <UL> *          <LI> {@link #setPowerDuration(int) setPowerDuration} *          <LI> {@link #startPowerDelivery(int) startPowerDelivery} *          <LI> {@link #setProgramPulseDuration(int) setProgramPulseDuration} *          <LI> {@link #startProgramPulse(int) startProgramPulse} *          <LI> {@link #startBreak() startBreak} *          <LI> {@link #setPowerNormal() setPowerNormal} *          <LI> {@link #setSpeed(int) setSpeed} *          <LI> {@link #getSpeed() getSpeed} *         </UL> *     </UL> *   <LI> <B> Advanced </B> *     <UL> *        <LI> {@link #registerOneWireContainerClass(int, Class) registerOneWireContainerClass} *     </UL> *  </UL> * * @see com.dalsemi.onewire.OneWireAccessProvider * @see com.dalsemi.onewire.container.OneWireContainer * * @version    0.00, 28 Aug 2000 * @author     DS */public abstract class DSPortAdapter{   //--------   //-------- Finals   //--------   /** Speed modes for 1-Wire Network, regular                    */   public static final int SPEED_REGULAR = 0;   /** Speed modes for 1-Wire Network, flexible for long lines    */   public static final int SPEED_FLEX = 1;   /** Speed modes for 1-Wire Network, overdrive                  */   public static final int SPEED_OVERDRIVE = 2;   /** Speed modes for 1-Wire Network, hyperdrive                 */   public static final int SPEED_HYPERDRIVE = 3;   /** 1-Wire Network level, normal (weak 5Volt pullup)                            */   public static final char LEVEL_NORMAL = 0;   /** 1-Wire Network level, (strong 5Volt pullup, used for power delivery) */   public static final char LEVEL_POWER_DELIVERY = 1;   /** 1-Wire Network level, (strong pulldown to 0Volts, reset 1-Wire)      */   public static final char LEVEL_BREAK = 2;   /** 1-Wire Network level, (strong 12Volt pullup, used to program eprom ) */   public static final char LEVEL_PROGRAM = 3;   /** 1-Wire Network reset result = no presence */   public static final int RESET_NOPRESENCE = 0x00;   /** 1-Wire Network reset result = presence    */   public static final int RESET_PRESENCE = 0x01;   /** 1-Wire Network reset result = alarm       */   public static final int RESET_ALARM = 0x02;   /** 1-Wire Network reset result = shorted     */   public static final int RESET_SHORT = 0x03;   /** Condition for power state change, immediate                      */   public static final int CONDITION_NOW = 0;   /** Condition for power state change, after next bit communication   */   public static final int CONDITION_AFTER_BIT = 1;   /** Condition for power state change, after next byte communication  */   public static final int CONDITION_AFTER_BYTE = 2;   /** Duration used in delivering power to the 1-Wire, 1/2 second         */   public static final int DELIVERY_HALF_SECOND = 0;   /** Duration used in delivering power to the 1-Wire, 1 second           */   public static final int DELIVERY_ONE_SECOND = 1;   /** Duration used in delivering power to the 1-Wire, 2 seconds          */   public static final int DELIVERY_TWO_SECONDS = 2;   /** Duration used in delivering power to the 1-Wire, 4 second           */   public static final int DELIVERY_FOUR_SECONDS = 3;   /** Duration used in delivering power to the 1-Wire, smart complete     */   public static final int DELIVERY_SMART_DONE = 4;   /** Duration used in delivering power to the 1-Wire, infinite           */   public static final int DELIVERY_INFINITE = 5;   /** Duration used in delivering power to the 1-Wire, current detect     */   public static final int DELIVERY_CURRENT_DETECT = 6;   /** Duration used in delivering power to the 1-Wire, 480 us             */   public static final int DELIVERY_EPROM = 7;   //--------   //-------- Variables   //--------   /**    * 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 abstract String getAdapterName ();   /**    * 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 abstract String getPortTypeDescription ();   /**    * Retrieves a version string for this class.    *    * @return  version string    */   public abstract String getClassVersion ();   //--------   //-------- 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 abstract Enumeration getPortNames ();   /**    * Registers a user provided <code>OneWireContainer</code> class.    * Using this method will override the Dallas Semiconductor provided    * container class when using the getDeviceContainer() method.  The    * registered container state is only stored for the current    * instance of <code>DSPortAdapter</code>, and is not statically shared.    * The <code>OneWireContainerClass</code> must extend    * <code>com.dalsemi.onewire.container.OneWireContainer</code> otherwise a <code>ClassCastException</code>    * will be thrown.    * The older duplicate family will be removed from registration when    * a collision occurs.    * Passing null as a parameter for the <code>OneWireContainerClass</code> will result    * in the removal of any entry associated with the family.    *    * @param family   the code of the family type to associate with this class.    * @param OneWireContainerClass  User provided class    *    * @throws OneWireException If <code>OneWireContainerClass</code> is not found.    * @throws ClassCastException If user supplied <code>OneWireContainer</code> does not    * extend <code>com.dalsemi.onewire.container.OneWireContainer</code>.    */   public void registerOneWireContainerClass (int family,                                              Class OneWireContainerClass)      throws OneWireException   {      Class defaultibc = null;      try      {         defaultibc =            Class.forName("com.dalsemi.onewire.container.OneWireContainer");      }      catch (ClassNotFoundException e)      {         throw new OneWireException("Could not find OneWireContainer class");      }      Integer familyInt = new Integer(family);      if (OneWireContainerClass == null)      {         // If a null is passed, remove the old container class.         registeredOneWireContainerClasses.remove(familyInt);      }      else      {         if (defaultibc.isAssignableFrom(OneWireContainerClass))         {            // Put the new container class in the hashtable, replacing any old one.            registeredOneWireContainerClasses.put(familyInt,                                                  OneWireContainerClass);         }         else         {            throw new ClassCastException(               "Does not extend com.dalsemi.onewire.container.OneWireContainer");         }      }   }   /**    * Specifies 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-aquire the port when needed.  If the port cannot be re-aquired    * ehen the exception <code>PortInUseException</code> will be thrown.    *    * @param  portName  name of the target port, retrieved from

⌨️ 快捷键说明

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