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

📄 onewirecontainer1d.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    * This is one of the methods to construct a container.  The other is    * through creating a OneWireContainer with NO parameters.    *    * @param  sourceAdapter     adapter instance used to communicate with    * this 1-Wire device    * @param  newAddress        {@link com.dalsemi.onewire.utils.Address Address}    *                            of this 1-Wire device    *    * @see #OneWireContainer1D() OneWireContainer1D     * @see com.dalsemi.onewire.utils.Address utils.Address    */   public OneWireContainer1D (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);   }   /**    * Create a container with the provided adapter instance    * and the address of the iButton or 1-Wire device.<p>    *    * This is one of the methods to construct a container.  The other is    * through creating a OneWireContainer with NO parameters.    *    * @param  sourceAdapter     adapter instance used to communicate with    * this 1-Wire device    * @param  newAddress        {@link com.dalsemi.onewire.utils.Address Address}    *                            of this 1-Wire device    *    * @see #OneWireContainer1D() OneWireContainer1D     * @see com.dalsemi.onewire.utils.Address utils.Address    */   public OneWireContainer1D (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);   }   //--------   //-------- Information methods   //--------   /**    * Get the Dallas Semiconductor part number of the iButton    * or 1-Wire Device as a string.  For example 'DS1992'.    *    * @return iButton or 1-Wire device name    */   public String getName ()   {      return "DS2423";   }   /**    * Get a short description of the function of this iButton     * or 1-Wire Device type.    *    * @return device description    */   public String getDescription ()   {      return "1-Wire counter with 4096 bits of read/write, nonvolatile "             + "memory.  Memory is partitioned into sixteen pages of 256 bits each.  "             + "256 bit scratchpad ensures data transfer integrity.  "             + "Has overdrive mode.  Last four pages each have 32 bit "             + "read-only non rolling-over counter.  The first two counters "             + "increment on a page write cycle and the second two have "             + "active-low external triggers.";   }   /**    * Get the maximum speed this iButton or 1-Wire device can    * communicate at.    * Override this method if derived iButton type can go faster then    * SPEED_REGULAR(0).    *    * @return maximum speed    * @see com.dalsemi.onewire.container.OneWireContainer#setSpeed super.setSpeed    * @see com.dalsemi.onewire.adapter.DSPortAdapter#SPEED_REGULAR DSPortAdapter.SPEED_REGULAR    * @see com.dalsemi.onewire.adapter.DSPortAdapter#SPEED_OVERDRIVE DSPortAdapter.SPEED_OVERDRIVE    * @see com.dalsemi.onewire.adapter.DSPortAdapter#SPEED_FLEX DSPortAdapter.SPEED_FLEX    */   public int getMaxSpeed ()   {      return DSPortAdapter.SPEED_OVERDRIVE;   }   /**    * Get 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(4);      // scratchpad      MemoryBankScratchEx scratch = new MemoryBankScratchEx(this);      bank_vector.addElement(scratch);      // NVRAM       MemoryBankNVCRC nv = new MemoryBankNVCRC(this, scratch);      nv.numberPages          = 12;      nv.size                 = 384;      nv.extraInfoLength      = 8;      nv.readContinuePossible = false;      nv.numVerifyBytes       = 8;      bank_vector.addElement(nv);      // NVRAM (with write cycle counters)      nv                      = new MemoryBankNVCRC(this, scratch);      nv.numberPages          = 2;      nv.size                 = 64;      nv.bankDescription      = "Memory with write cycle counter";      nv.startPhysicalAddress = 384;      nv.extraInfo            = true;      nv.extraInfoDescription = "Write cycle counter";      nv.extraInfoLength      = 8;      nv.readContinuePossible = false;      nv.numVerifyBytes       = 8;      bank_vector.addElement(nv);      // NVRAM (with external counters)      nv                      = new MemoryBankNVCRC(this, scratch);      nv.numberPages          = 2;      nv.size                 = 64;      nv.bankDescription      = "Memory with externally triggered counter";      nv.startPhysicalAddress = 448;      nv.extraInfo            = true;      nv.extraInfoDescription = "Externally triggered counter";      nv.extraInfoLength      = 8;      bank_vector.addElement(nv);      return bank_vector.elements();   }   //--------   //-------- Custom Methods for this 1-Wire Device Type     //--------   /**    * Read the counter value associated with a page on this     * 1-Wire Device.    *    * @param  counterPage    page number of the counter to read    *    * @return  4 byte value counter stored in a long integer    *    * @throws OneWireIOException on a 1-Wire communication error such as     *         no 1-Wire device present.  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    */   public long readCounter (int counterPage)      throws OneWireIOException, OneWireException   {      // check if counter page provided is valid      if ((counterPage < 12) || (counterPage > 15))         throw new OneWireException(            "OneWireContainer1D-invalid counter page");      // select the device       if (adapter.select(address))      {         int crc16;         // read memory command         buffer [0] = READ_MEMORY_COMMAND;         crc16      = CRC16.compute(READ_MEMORY_COMMAND);         // address of last data byte before counter         int address = (counterPage << 5) + 31;         // append the address         buffer [1] = ( byte ) address;         crc16      = CRC16.compute(buffer [1], crc16);         buffer [2] = ( byte ) (address >>> 8);         crc16      = CRC16.compute(buffer [2], crc16);         // now add the read bytes for data byte,counter,zero bits, crc16         for (int i = 3; i < 14; i++)            buffer [i] = ( byte ) 0xFF;         // send the block         adapter.dataBlock(buffer, 0, 14);         // calculate the CRC16 on the result and check if correct         if (CRC16.compute(buffer, 3, 11, crc16) == 0xB001)         {            // extract the counter out of this verified packet            long return_count = 0;            for (int i = 4; i >= 1; i--)            {               return_count <<= 8;               return_count |= (buffer [i + 3] & 0xFF);            }            // return the result count            return return_count;         }      }      // device must not have been present      throw new OneWireIOException("OneWireContainer1D-device not present");   }}

⌨️ 快捷键说明

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