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

📄 onewirecontainer37.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 2002 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 java.util.*;import java.lang.reflect.*;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.*;import com.dalsemi.onewire.adapter.*;/** * <P> 1-Wire&#174 container for a 32K bytes of read-only and read/write password * protected memory, DS1977.  This container encapsulates the functionality * of the 1-Wire family type <B>37</B> (hex). * </P> * * <H3> Features </H3> * <UL> *   <LI> 32K bytes EEPROM organized as pages of 64 bytes. *   <LI> 512-bit scratchpad ensures integrity of data transfer *   <LI> On-chip 16-bit CRC generator * </UL> * * <H3> Memory </H3> * * <P> The memory can be accessed through the objects that are returned * from the {@link #getMemoryBanks() getMemoryBanks} method. </P> * * The following is a list of the MemoryBank instances that are returned: * * <UL> *   <LI> <B> Scratchpad with CRC and Password support </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 64 starting at physical address 0 *         <LI> <I> Features</I> Read/Write not-general-purpose volatile *         <LI> <I> Pages</I> 1 page of length 64 bytes *         <LI> <I> Page Features </I> page-device-CRC *         <li> <i> Extra information for each page</i>  Target address, offset, length 3 *         <LI> <i> Supports Copy Scratchpad With Password command </I> *      </UL> *   <LI> <B> Main Memory </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 32704 starting at physical address 0 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Pages</I> 511 pages of length 64 bytes giving 61 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC *         <LI> <I> Read-Only and Read/Write password </I> if enabled, passwords are required for *                  reading from and writing to the device. *      </UL> *   <LI> <B> Register control </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 64 starting at physical address 32704 *         <LI> <I> Features</I> Read/Write not-general-purpose non-volatile *         <LI> <I> Pages</I> 1 pages of length 64 bytes *         <LI> <I> Page Features </I> page-device-CRC *         <LI> <I> Read-Only and Read/Write password </I> if enabled, passwords are required for *                  reading from and writing to the device. *      </UL> * </UL> * * For examples regarding memory operations, * <uL> * <li> See the usage example in * {@link com.dalsemi.onewire.container.OneWireContainer OneWireContainer} * to enumerate the MemoryBanks. * <li> See the usage examples in * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank} and * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} * for bank specific operations. * </uL> * * @see com.dalsemi.onewire.container.PasswordContainer * * @version    1.00, 18 Aug 2003 * @author     jevans * */public class OneWireContainer37 extends OneWireContainer   implements PasswordContainer{   // enables/disables debugging   private static final boolean DEBUG = false;   // when reading a page, the memory bank may throw a crc exception if the device   // is sampling or starts sampling during the read.  This value sets how many   // times the device retries before passing the exception on to the application.   private static final int MAX_READ_RETRY_CNT = 15;   // the length of the Read-Only and Read/Write password registers   private static final int PASSWORD_LENGTH = 8;   // memory bank for scratchpad   private MemoryBankScratchCRCPW scratch = null;   // memory bank for general-purpose user data   private MemoryBankNVCRCPW userDataMemory = null;   // memory bank for control register   private MemoryBankNVCRCPW register = null;   // Maxim/Dallas Semiconductor Part number   private String partNumber = "DS1977";   // Letter appended at end of partNumber (S/H/L/T)    private char partLetter = '0';   // should we check the speed   private boolean doSpeedEnable = true;   /**    * The current password for readingfrom this device.    */   protected final byte[] readPassword = new byte[8];   protected boolean readPasswordSet = false;   /**    * The current password for reading/writing from/to this device.    */   protected final byte[] readWritePassword = new byte[8];   protected boolean readWritePasswordSet = false;   // used to tell if the passwords have been enabled   private boolean readOnlyPasswordEnabled = false;   private boolean readWritePasswordEnabled = false;   // used to 'enable' passwords   private static final byte ENABLE_BYTE = (byte)0xAA;   // used to 'disable' passwords   private static final byte DISABLE_BYTE = 0x00;   private String descriptionString =       "Rugged, self-sufficient 1-Wire device that, once setup can "       + "store 32KB of password protected memory with a read only "       + "and a read/write password.";// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// 1-Wire Commands//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *****************************************************************************   /** 1-Wire command for Write Scratchpad */   public static final byte WRITE_SCRATCHPAD_COMMAND   = (byte)0x0F;   /** 1-Wire command for Read Scratchpad */   public static final byte READ_SCRATCHPAD_COMMAND    = (byte)0xAA;   /** 1-Wire command for Copy Scratchpad With Password */   public static final byte COPY_SCRATCHPAD_PW_COMMAND = (byte)0x99;   /** 1-Wire command for Read Memory With Password */   public static final byte READ_MEMORY_PW_COMMAND     = (byte)0x69;   /** 1-Wire command for Verifing the Password */   public static final byte VERIFY_PSW_COMMAND         = (byte)0xC3;   /** 1-Wire command for getting Read Version */   public static final byte READ_VERSION               = (byte)0xCC;// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Register addresses and control bits//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *****************************************************************************   // 1 byte, alternating ones and zeroes indicates passwords are enabled   /** Address of the Password Control Register. */   public static final int PASSWORD_CONTROL_REGISTER = 0x7FD0;   // 8 bytes, write only, for setting the Read Access Password   /** Address of Read Access Password. */   public static final int READ_ACCESS_PASSWORD = 0x7FC0;   // 8 bytes, write only, for setting the Read Access Password   /** Address of the Read Write Access Password. */   public static final int READ_WRITE_ACCESS_PASSWORD = 0x7FC8;   public static final int READ_WRITE_PWD = 0;   public static final int READ_ONLY_PWD  = 1;// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Constructors and Initializers//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *****************************************************************************   /**    * Creates a new <code>OneWireContainer</code> for communication with a    * DS1977.    * Note that the method <code>setupContainer(DSPortAdapter,byte[])</code>    * must be called to set the correct <code>DSPortAdapter</code> device address.    *    * @see com.dalsemi.onewire.container.OneWireContainer#setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) setupContainer(DSPortAdapter,byte[])    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer37(DSPortAdapter,byte[])    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer37(DSPortAdapter,long)    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer37(DSPortAdapter,String)    */   public OneWireContainer37()   {      super();      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a    * DS1977.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1977    *    * @see #OneWireContainer37()    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer37(DSPortAdapter,long)    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer37(DSPortAdapter,String)    */   public OneWireContainer37(DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a    * DS1977.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1977    *    * @see #OneWireContainer37()    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer37(DSPortAdapter,byte[])    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer37(DSPortAdapter,String)    */   public OneWireContainer37(DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a    * DS1977.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1977    *    * @see #OneWireContainer37()    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer37(DSPortAdapter,long)    * @see #OneWireContainer37(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer37(DSPortAdapter,String)    */   public OneWireContainer37(DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);      // initialize the memory banks      initMem();   }   /**    * Provides this container with the adapter object used to access this device and    * the address of the iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton    * @param  newAddress        address of this 1-Wire device    * @see com.dalsemi.onewire.utils.Address    */   public void setupContainer(DSPortAdapter sourceAdapter, byte[] newAddress)   {      super.setupContainer(sourceAdapter, newAddress);      // initialize the memory banks      initMem();   }   /**    * Provides this container with the adapter object used to access this device and    * the address of the iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton    * @param  newAddress        address of this 1-Wire device    * @see com.dalsemi.onewire.utils.Address    */   public void setupContainer(DSPortAdapter sourceAdapter, long newAddress)   {      super.setupContainer(sourceAdapter, newAddress);      // initialize the memory banks

⌨️ 快捷键说明

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