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

📄 onewirecontainer2c.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------- * 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.container;// importsimport com.dalsemi.onewire.utils.CRC16;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.OneWireException;//----------------------------------------------------------------------------/** * <P>1-Wire&#174 container that encapsulates the functionality of the 1-Wire * family type <b>2C</B> (hex), Dallas Semiconductor part number: <B>DS2890, * 1-Wire Digital Potentiometer</B>.</P> * * * <H3>Features</H3> * <UL> *   <LI>Single element 256-position linear taper potentiometer *   <LI>Supports potentiometer terminal working voltages up to 11V *   <LI>Potentiometer terminal voltage independant of supply voltage *   <LI>100k Ohm resistor element value *   <LI>Operating temperature range from -40&#176C to *       +85&#176C *   <LI>2.8V - 6.0V operating voltage range * </UL> * * <H3>Data sheet</H3> * *   <A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2890.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2890.pdf</A> * * @version    0.00, 28 Aug 2000 * @author     KLA */public class OneWireContainer2C   extends OneWireContainer   implements PotentiometerContainer{   //--------   //-------- Variables   //--------   private byte[] buffer = new byte [4];   //--------   //-------- Finals   //--------   /**    * DS2890 1-Wire Write Control Register command constant.    *    * The Write Control Register command is used to manipulate DS2890 state bits    * located in the Control Register.    */   private static final byte WRITE_CONTROL = ( byte ) 0x55;   /**    * DS2890 1-Wire Read Control Register command constant.    *    * The Read Control Register command is used to obtain both the Control Register    * and potentiometer Feature Register.    */   private static final byte READ_CONTROL = ( byte ) 0xaa;   /**    * DS2890 1-Wire Write Position command constant.    *    * The Write Position command is used to set the position of the currently    * addressed potentiometer wiper.    */   private static final byte WRITE_POSITION = ( byte ) 0x0f;   /**    * DS2890 1-Wire Read Position command constant.    *    * The Read Position command is used to obtain the wipre setting of the    * potentiometer currently addressed by the control register.    */   private static final byte READ_POSITION = ( byte ) 0xf0;   /**    * DS2890 1-Wire Increment command constant.    *    * The Increment command is used for a one step position increase of the    * currently addressed potentiometer wiper.    */   private static final byte INCREMENT = ( byte ) 0xc3;   /**    * DS2890 1-Wire Decrement command constant.    *    * The Decrement command is used for a one setp position decrease of the    * currently addressed potentiometer wiper.    */   private static final byte DECREMENT = ( byte ) 0x99;   //--------   //-------- Constructors   //--------   /**    * Default constructor    */   public OneWireContainer2C ()   {      super();   }   /**    * Creates a container with a provided adapter object    * and the address of the 1-Wire device.    *    * @param  sourceAdapter adapter object required to communicate with    * this 1-Wire device    * @param  newAddress address of this 1-Wire device    */   public OneWireContainer2C (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Creates a container with a provided adapter object    * and the address of this 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    * this 1-Wire device    * @param  newAddress        address of this 1-Wire device    */   public OneWireContainer2C (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Creates a container with a provided adapter object    * and the address of this 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    * this 1-Wire device    * @param  newAddress        address of this 1-Wire device    */   public OneWireContainer2C (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);   }   //--------   //-------- Methods   //--------   /**    * Retrieves the Dallas Semiconductor part number of this 1-Wire device    * as a string.  For example 'DS2890'.    *    * @return  representation of this 1-Wire devices name    */   public String getName ()   {      return "DS2890";   }   /**    * Retrieves the alternate Dallas Semiconductor part numbers or names.    * A family of MicroLan devices may have more than one part number    * depending on packaging.    *    * @return  representation of the alternate names    */   public String getAlternateNames ()   {      return "Digital Potentiometer";   }   /**    * Retrieves a short description of the function of this 1-Wire Device.    *    * @return  representation of the function description    */   public String getDescription ()   {      return "1-Wire linear taper digitally controlled potentiometer "             + "with 256 wiper positions.  0-11 Volt working range.";   }   /**    * Gets the maximum speed this 1-Wire device can    * communicate at.    *    * @return maximum speed this device can communicate at    */   public int getMaxSpeed ()   {      return DSPortAdapter.SPEED_OVERDRIVE;   }   //--------   //-------- Potentiometer Feature methods   //--------   /**    * Queries to see if this Potentiometer One Wire Device    * has linear potentiometer element(s) or logarithmic    * potentiometer element(s).    *    * @param state state buffer of the Potentiometer One Wire Device    *              (returned by <CODE>readDevice()</CODE>)    * @return <CODE>true</CODE> if this device has linear potentiometer    *         element(s); <CODE>false</CODE> if this device has logarithmic    *         potentiometer element(s)    */   public boolean isLinear (byte[] state)   {      return ((state [0] & 0x01) == 0x01);   }   /**    * Queries to see if this 1-Wire Potentiometer device's    * wiper settings are volatile or non-volatile.    *    * @param state state buffer of the 1-Wire Potentiometer device    *              (returned by <CODE>readDevice()</CODE>)    * @return <CODE>true</CODE> if the wiper settings are volatile;    *         <CODE>false</CODE> if the wiper settings are non-volatile    */   public boolean wiperSettingsAreVolatile (byte[] state)   {      return ((state [0] & 0x02) == 0x02);   }   /**    * Queries to see how many potentiometers this    * Potentiometer One Wire Device has.    *    * @param state state buffer of this 1-Wire Potentiometer device    *             (returned by <CODE>readDevice()</CODE>)    * @return the number of potentiometers on this device    */   public int numberOfPotentiometers (byte[] state)   {      return (((state [0] >> 2) & 0x03) + 1);   }   /**    * Queries to find the number of wiper settings    * that any wiper on this Potentiometer One Wire    * Device can have.    *    * @param state state buffer of this 1-Wire Potentiometer device    *             (returned by <CODE>readDevice()</CODE>)    * @return number of wiper positions available    */   public int numberOfWiperSettings (byte[] state)   {      switch (state [0] & 0x30)      {         case 0x00 :            return 32;         case 0x10 :            return 64;         case 0x20 :            return 128;         default :            return 256;      }   }   /**    * Queries to find the resistance value of the potentiometer.    *    * @param state state buffer of this 1-Wire Potentiometer device    *             (returned by <CODE>readDevice()</CODE>)    * @return the resistance value in k-Ohms    */   public int potentiometerResistance (byte[] state)   {      switch (state [0] & 0xc0)      {         case 0x00 :            return 5;         case 0x40 :            return 10;         case 0x80 :            return 50;         default :            return 100;      }   }   /**    * Gets the currently selected wiper number.  All wiper actions    * affect this wiper.  The number of wipers is the same as    * <CODE>numberOfPotentiometers()</CODE>.    *

⌨️ 快捷键说明

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