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

📄 onewirecontainer26.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.container;// importsimport com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.*;import com.dalsemi.onewire.adapter.*;import java.util.*;/** *  <P>1-Wire&#174 container that encapsulates the functionality of the 1-Wire *  family type <B>26</B> (hex), Dallas Semiconductor part number: <B>DS2438, *  Smart Battery Monitor</B>.</P> * * <H2>Features</H2> * <UL> *   <LI>direct-to-digital temperature sensor *   <LI>A/D converters which measures the battery voltage and current *   <LI>integrated current accumulator which keeps a running *       total of all current going into and out of the battery *   <LI>elapsed time meter *   <LI>40 bytes of nonvolatile EEPROM memory for storage of important parameters *   <LI>Operating temperature range from -40&#176C to *        +85&#176Ci * </UL> * * <H2>Note</H2> *  <P> *  Sometimes the VAD input will report 10.23 V even if nothing is attached. *  This value is also the maximum voltage that part can report. *  </P> * * <H3> DataSheet </H3> * <DL> * <DD>http://pdfserv.maxim-ic.com/arpdf/DS2438.pdf (not active yet, Sep-06-2001) * <DD><A HREF="http://www.ibutton.com/weather/humidity.html">http://www.ibutton.com/weather/humidity.html</A> * </DL> * *  @version    0.00, 28 Aug 2000 *  @author     COlmstea * */public class OneWireContainer26   extends OneWireContainer   implements ADContainer, TemperatureContainer, ClockContainer, HumidityContainer{   /**    * Memory commands.    */   private static final byte READ_SCRATCHPAD_COMMAND  = ( byte ) 0xBE;   private static final byte RECALL_MEMORY_COMMAND    = ( byte ) 0xB8;   private static final byte COPY_SCRATCHPAD_COMMAND  = ( byte ) 0x48;   private static final byte WRITE_SCRATCHPAD_COMMAND = ( byte ) 0x4E;   private static final byte CONVERT_TEMP_COMMAND     = ( byte ) 0x44;   private static final byte CONVERT_VOLTAGE_COMMAND  = ( byte ) 0xB4;   /**    * Channel selector for the VDD input.  Meant to be used with    * a battery.    */   public static final int CHANNEL_VDD = 0x00;   /**    * Channel selector for the VAD input.  This is the general purpose    * A-D input.    */   public static final int CHANNEL_VAD = 0x01;   /**    * Channel selectro the the IAD input.  Measures voltage across    * a resistor, Rsense, for calculating current.    */   public static final int CHANNEL_VSENSE = 0x02;   /**    * Flag to set/check the Current A/D Control bit with setFlag/getFlag. When    * this bit is true, the current A/D and the ICA are enabled and    * current measurements will be taken at the rate of 36.41 Hz.    */   public static final byte IAD_FLAG = 0x01;   /**    * Flag to set/check the Current Accumulator bit with setFlag/getFlag. When    * this bit is true, both the total discharging and charging current are    * integrated into seperate registers and can be used for determining    * full/empty levels.  When this bit is zero the memory (page 7) can be used    * as user memory.    */   public static final byte CA_FLAG = 0x02;   /**    * Flag to set/check the Current Accumulator Shadow Selector bit with    * setFlag/getFlag.  When this bit is true the CCA/DCA registers used to    * add up charging/discharging current are shadowed to EEPROM to protect    * against loss of data if the battery pack becomes discharged.    */   public static final byte EE_FLAG = 0x04;   /**    * Flag to set/check the voltage A/D Input Select Bit with setFlag/getFlag    * When this bit is true the battery input is (VDD) is selected as input for    * the voltage A/D input. When false the general purpose A/D input (VAD) is    * selected as the voltage A/D input.    */   public static final byte AD_FLAG = 0x08;   /**    * Flag to check whether or not a temperature conversion is in progress    * using getFlag().    */   public static final byte TB_FLAG = 0x10;   /**    * Flag to check whether or not an operation is being performed on the    * nonvolatile memory using getFlag.    */   public static final byte NVB_FLAG = 0x20;   /**    * Flag to check whether or not the A/D converter is busy using getFlag().    */   public static final byte ADB_FLAG = 0x40;   /**    * Holds the value of the sensor resistance.    */   private double Rsens = .05;   /**    * Flag to indicate need to check speed    */   private boolean    doSpeedEnable = true;   //--------   //-------- Constructors   //--------   /**    * Default constructor    */   public OneWireContainer26 ()   {      super();   }   /**    * Create 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 OneWireContainer26 (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Create 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 OneWireContainer26 (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Create 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 OneWireContainer26 (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Gets an enumeration of memory bank instances that implement one or more    * of the following interfaces:    * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank},    * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank},    * and {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank}.    * @return <CODE>Enumeration</CODE> of memory banks    */   public Enumeration getMemoryBanks ()   {      Vector bank_vector = new Vector(8);      // Status      bank_vector.addElement(new MemoryBankSBM(this));      // Temp/Volt/Current      MemoryBankSBM temp = new MemoryBankSBM(this);      temp.bankDescription      = "Temperature/Voltage/Current";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 1;      temp.size                 = 6;      temp.readWrite            = false;      temp.readOnly             = true;      temp.nonVolatile          = false;      temp.powerDelivery        = false;      bank_vector.addElement(temp);      // Threshold      temp = new MemoryBankSBM(this);      temp.bankDescription      = "Threshold";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 7;      temp.size                 = 1;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = true;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      // Elapsed Timer Meter      temp = new MemoryBankSBM(this);      temp.bankDescription      = "Elapsed Timer Meter";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 8;      temp.size                 = 5;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = false;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      // Current Offset      temp = new MemoryBankSBM(this);      temp.bankDescription      = "Current Offset";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 13;      temp.size                 = 2;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = true;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      // Disconnect / End of Charge      temp = new MemoryBankSBM(this);      temp.bankDescription      = "Disconnect / End of Charge";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 16;      temp.size                 = 8;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = false;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      // User Main Memory      temp = new MemoryBankSBM(this);      temp.bankDescription      = "User Main Memory";      temp.generalPurposeMemory = true;      temp.startPhysicalAddress = 24;      temp.size                 = 32;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = true;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      // User Memory / CCA / DCA      temp = new MemoryBankSBM(this);      temp.bankDescription      = "User Memory / CCA / DCA";      temp.generalPurposeMemory = false;      temp.startPhysicalAddress = 56;      temp.size                 = 8;      temp.readWrite            = true;      temp.readOnly             = false;      temp.nonVolatile          = true;      temp.powerDelivery        = true;      bank_vector.addElement(temp);      return bank_vector.elements();   }   /**    *  Returns the Dallas Semiconductor part number of this 1-Wire device    *  as a string.    *    *  @return representation of this 1-Wire device's name    *    */   public String getName ()   {      return "DS2438";   }   /**    *  Return the alternate Dallas Semiconductor part number or name.    *  ie. Smart Battery Monitor    *    *  @return representation of the alternate name(s)    */   public String getAlternateNames ()   {      return "Smart Battery Monitor";   }   /**    *  Return a short description of the function of this 1-Wire device type.    *    *  @return representation of the functional description    */   public String getDescription ()   {      return "1-Wire device that integrates the total current charging or "             + "discharging through a battery and stores it in a register. "             + "It also returns the temperature (accurate to 2 degrees celcius),"             + " as well as the instantaneous current and voltage and also "             + "provides 40 bytes of EEPROM storage.";   }   /**    * Set the value of the sense resistor used to determine    * battery current.  This value is used in the <CODE>getCurrent()</CODE> calculation.    * See the DS2438 datasheet for more information on sensing battery    * current.    *    * @param resistance Value of the sense resistor in Ohms.    */   public synchronized void setSenseResistor (double resistance)   {      Rsens = resistance;   }   /**    * Get the value used for the sense resistor in the <CODE>getCurrent()</CODE>    * calculations.    *    * @return currently stored value of the sense resistor in Ohms    */   public double getSenseResistor ()   {      return Rsens;   }   /**    * Directs the container to avoid the calls to doSpeed() in methods that communicate    * with the Thermocron. To ensure that all parts can talk to the 1-Wire bus    * at their desired speed, each method contains a call    * to <code>doSpeed()</code>.  However, this is an expensive operation.    * If a user manages the bus speed in an    * application,  call this method with <code>doSpeedCheck</code>    * as <code>false</code>.  The default behavior is    * to call <code>doSpeed()</code>.    *    * @param doSpeedCheck <code>true</code> for <code>doSpeed()</code> to be called before every    * 1-Wire bus access, <code>false</code> to skip this expensive call    *    * @see OneWireContainer#doSpeed()    */   public synchronized void setSpeedCheck (boolean doSpeedCheck)   {      doSpeedEnable = doSpeedCheck;   }   /**    * Reads the specified 8 byte page and returns the data in an array.    *    * @param page the page number to read    *    * @return  eight byte array that make up the page    *    * @throws OneWireIOException Error reading data    * @throws OneWireException Could not find part    * @throws IllegalArgumentException Bad parameters passed    */   public byte[] readPage (int page)

⌨️ 快捷键说明

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