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

📄 onewirecontainer10.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.*;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.adapter.*;/** * <P> 1-Wire container for temperature iButton which measures temperatures * from -55&#176C to +100&#176C, DS1920 or DS18S20.  This container encapsulates the * functionality of the iButton family type <B>10</B> (hex)</P> * * <H3> Features </H3> * <UL> *   <LI> Measures temperatures from -55&#176C to +100&#176C in typically 0.2 seconds *   <LI> Zero standby power *   <LI> 0.5&#176C resolution, digital temperature reading in two抯 complement *   <LI> Increased resolution through interpolation in internal counters *   <LI> 8-bit device-generated CRC for data integrity *   <LI> Special command set allows user to skip ROM section and do temperature *        measurements simultaneously for all devices on the bus *   <LI> 2 bytes of EEPROM to be used either as alarm triggers or user memory *   <LI> Alarm search directly indicates which device senses alarming temperatures * </UL> * * <H3> Usage </H3> * * <DL> * <DD> See the usage example in * {@link com.dalsemi.onewire.container.TemperatureContainer TemperatureContainer} * for temperature specific operations. * </DL> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS1920.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS1920.pdf</A> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS18S20.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS18S20.pdf</A> * </DL> * * @see com.dalsemi.onewire.container.TemperatureContainer * * @version    1.00, 1 Sep 2000 * @author     DS,JK * Converted to use TemperatureContainer interface 9-1-2000 KLA */public class OneWireContainer10   extends OneWireContainer   implements TemperatureContainer{   private boolean normalResolution = true;   //--------   //-------- Static Final Variables   //--------   /**    * default temperature resolution for this <code>OneWireContainer10</code>    * device.    */   public static final double RESOLUTION_NORMAL = 0.5;   /**    * maximum temperature resolution for this <code>OneWireContainer10</code>    * device. Use <code>RESOLUTION_MAXIMUM</code> in    * <code>setResolution()</code> if higher resolution is desired.    */   public static final double RESOLUTION_MAXIMUM = 0.1;   /** DS1920 convert temperature command  */   private static final byte CONVERT_TEMPERATURE_COMMAND = 0x44;   /** DS1920 read data from scratchpad command      */   private static final byte READ_SCRATCHPAD_COMMAND = ( byte ) 0xBE;   /** DS1920 write data to scratchpad command     */   private static final byte WRITE_SCRATCHPAD_COMMAND = ( byte ) 0x4E;   /** DS1920 copy data from scratchpad to EEPROM command     */   private static final byte COPY_SCRATCHPAD_COMMAND = ( byte ) 0x48;   /** DS1920 recall EEPROM command       */   private static final byte RECALL_EEPROM_COMMAND = ( byte ) 0xB8;   /**    * Creates an empty <code>OneWireContainer10</code>.  Must call    * <code>setupContainer()</code> before using this new container.<p>    *    * This is one of the methods to construct a <code>OneWireContainer10</code>.    * The others are through creating a <code>OneWireContainer10</code> with    * parameters.    *    * @see #OneWireContainer10(DSPortAdapter,byte[])    * @see #OneWireContainer10(DSPortAdapter,long)    * @see #OneWireContainer10(DSPortAdapter,String)    */   public OneWireContainer10 ()   {      super();   }   /**    * Creates a <code>OneWireContainer10</code> with the provided adapter    * object and the address of this One-Wire device.    *    * This is one of the methods to construct a <code>OneWireContainer10</code>.    * The others are through creating a <code>OneWireContainer10</code> with    * different parameters types.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this One-Wire device    * @param  newAddress        address of this One-Wire device    *    * @see com.dalsemi.onewire.utils.Address    * @see #OneWireContainer10()    * @see #OneWireContainer10(DSPortAdapter,long)    * @see #OneWireContainer10(DSPortAdapter,String)    */   public OneWireContainer10 (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Creates a <code>OneWireContainer10</code> with the provided adapter    * object and the address of this One-Wire device.    *    * This is one of the methods to construct a <code>OneWireContainer10</code>.    * The others are through creating a <code>OneWireContainer10</code> with    * different parameters types.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this One-Wire device    * @param  newAddress        address of this One-Wire device    *    * @see com.dalsemi.onewire.utils.Address    * @see #OneWireContainer10()    * @see #OneWireContainer10(DSPortAdapter,byte[])    * @see #OneWireContainer10(DSPortAdapter,String)    */   public OneWireContainer10 (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Creates a <code>OneWireContainer10</code> with the provided adapter    * object and the address of this One-Wire device.    *    * This is one of the methods to construct a <code>OneWireContainer10</code>.    * The others are through creating a <code>OneWireContainer10</code> with    * different parameters types.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this One-Wire device    * @param  newAddress        address of this One-Wire device    *    * @see com.dalsemi.onewire.utils.Address    * @see #OneWireContainer10()    * @see #OneWireContainer10(DSPortAdapter,byte[])    * @see #OneWireContainer10(DSPortAdapter,long)    */   public OneWireContainer10 (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);   }   //--------   //-------- Information methods   //--------   /**    * Retrieves the Dallas Semiconductor part number of this    * <code>OneWireContainer10</code> as a <code>String</code>.    * For example 'DS1920'.    *    * @return this <code>OneWireContainer10</code> name    */   public String getName ()   {      return "DS1920";   }   /**    * Retrieves the alternate Dallas Semiconductor part numbers or names.    * A 'family' of 1-Wire Network devices may have more than one part number    * depending on packaging.  There can also be nicknames such as    * 'Crypto iButton'.    *    * @return this <code>OneWireContainer10</code> alternate names    */   public String getAlternateNames ()   {      return "DS18S20";   }   /**    * Retrieves a short description of the function of this    * <code>OneWireContainer10</code> type.    *    * @return <code>OneWireContainer10</code> functional description    */   public String getDescription ()   {      return "Digital thermometer measures temperatures from "             + "-55C to 100C in typically 0.2 seconds.  +/- 0.5C "             + "Accuracy between 0C and 70C. 0.5C standard "             + "resolution, higher resolution through interpolation.  "             + "Contains high and low temperature set points for "             + "generation of alarm.";   }   //--------   //-------- Custom Methods for OneWireContainer10   //--------   //--------   //-------- Temperature Feature methods   //--------   /**    * Checks to see if this temperature measuring device has high/low    * trip alarms.    *    * @return <code>true</code> if this <code>OneWireContainer10</code>    *         has high/low trip alarms    *    * @see    #getTemperatureAlarm    * @see    #setTemperatureAlarm    */   public boolean hasTemperatureAlarms ()   {      return true;   }   /**    * Checks to see if this device has selectable temperature resolution.    *    * @return <code>true</code> if this <code>OneWireContainer10</code>    *         has selectable temperature resolution    *    * @see    #getTemperatureResolution    * @see    #getTemperatureResolutions    * @see    #setTemperatureResolution    */   public boolean hasSelectableTemperatureResolution ()   {      return true;   }   /**    * Gets an array of available temperature resolutions in Celsius.    *    * @return byte array of available temperature resolutions in Celsius for    *         this <code>OneWireContainer10</code>. The minimum resolution is    *         returned as the first element and maximum resolution as the last    *         element.    *    * @see    #hasSelectableTemperatureResolution    * @see    #getTemperatureResolution    * @see    #setTemperatureResolution    */   public double[] getTemperatureResolutions ()   {      double[] resolutions = new double [2];      resolutions [0] = RESOLUTION_NORMAL;      resolutions [1] = RESOLUTION_MAXIMUM;      return resolutions;   }   /**    * Gets the temperature alarm resolution in Celsius.    *    * @return temperature alarm resolution in Celsius for this    *         <code>OneWireContainer10</code>    *    * @see    #hasTemperatureAlarms    * @see    #getTemperatureAlarm    * @see    #setTemperatureAlarm    *    */   public double getTemperatureAlarmResolution ()   {      return 1.0;   }   /**    * Gets the maximum temperature in Celsius.    *    * @return maximum temperature in Celsius for this    *         <code>OneWireContainer10</code>    *    * @see    #getMinTemperature    */   public double getMaxTemperature ()   {      return 100.0;   }   /**    * Gets the minimum temperature in Celsius.    *    * @return minimum temperature in Celsius for this    *         <code>OneWireContainer10</code>    *    * @see    #getMaxTemperature    */   public double getMinTemperature ()   {      return -55.0;   }   //--------   //-------- Temperature I/O Methods   //--------   /**    * Performs a temperature conversion on <code>state</code> information.    *    * @param  state byte array with device state information    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from this <code>OneWireContainer10</code>.    *         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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see    #getTemperature    */   public void doTemperatureConvert (byte[] state)      throws OneWireIOException, OneWireException   {      doSpeed();      // select the device      if (adapter.select(address))      {         // Setup Power Delivery         adapter.setPowerDuration(adapter.DELIVERY_INFINITE);         adapter.startPowerDelivery(adapter.CONDITION_AFTER_BYTE);         // send the convert temperature command         adapter.putByte(CONVERT_TEMPERATURE_COMMAND);         // delay for 750 ms         try         {            Thread.sleep(750);         }         catch (InterruptedException e){}         // Turn power back to normal.         adapter.setPowerNormal();         // check to see if the temperature conversion is over         if (adapter.getByte() != 0x0FF)            throw new OneWireIOException(address, "OneWireContainer10-temperature conversion not complete");         // read the result         byte mode = state [4];   //preserve the resolution in the state         adapter.select(address);         readScratch(state);         state [4] = mode;      }      else         // device must not have been present         throw new OneWireIOException(address, "OneWireContainer10-device not present");   }   //--------   //-------- Temperature 'get' Methods   //--------   /**    * Gets the temperature value in Celsius from the <code>state</code>    * data retrieved from the <code>readDevice()</code> method.    *    * @param  state byte array with device state information for this    *         <code>OneWireContainer10</code>    *    * @return temperature in Celsius from the last    *                     <code>doTemperatureConvert()</code>    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from this <code>OneWireContainer10</code>.    *         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'.

⌨️ 快捷键说明

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