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

📄 memorybankeepromblock.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    * the Extra Informationed return when reading pages in the current    * memory bank.  See 'hasExtraInfo()'.    *    * @return string describing extra information.    */   public String getExtraInfoDescription ()   {      return null;   }   /**    * Set the write verification for the 'write()' method.    *    * @param  doReadVerf   true (default) verify write in 'write'    *                      false, don't verify write (used on    *                      Write-Once bit manipulation)    */   public void setWriteVerification (boolean doReadVerf)   {      writeVerification = doReadVerf;   }   //--------   //-------- OTPMemoryBank query methods   //--------   /**    * Query to see if current memory bank pages can be redirected    * to another pages.  This is mostly used in Write-Once memory    * to provide a means to update.    *    * @return  'true' if current memory bank pages can be redirected    *          to a new page.    */   public boolean canRedirectPage ()   {      return false;   }   /**    * Query to see if current memory bank pages can be locked.  A    * locked page would prevent any changes to the memory.    *    * @return  'true' if current memory bank pages can be redirected    *          to a new page.    */   public boolean canLockPage ()   {      return true;   }   /**    * Query to see if current memory bank pages can be locked from    * being redirected.  This would prevent a Write-Once memory from    * being updated.    *    * @return  'true' if current memory bank pages can be locked from    *          being redirected to a new page.    */   public boolean canLockRedirectPage ()   {      return false;   }   //--------   //-------- MemoryBank I/O methods   //--------   /**    * Read  memory in the current bank with no CRC checking (device or    * data). The resulting data from this API may or may not be what is on    * the 1-Wire device.  It is recommends that the data contain some kind    * of checking (CRC) like in the readPagePacket() method or have    * the 1-Wire device provide the CRC as in readPageCRC().  readPageCRC()    * however is not supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    *    * @param  startAddr     starting physical address    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       read() continious where the last one led off    *                       and it is inside a 'beginExclusive/endExclusive'    *                       block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    * @param  len           length in bytes to read    *    * @throws OneWireIOException    * @throws OneWireException    */   public void read (int startAddr, boolean readContinue, byte[] readBuf,                     int offset, int len)      throws OneWireIOException, OneWireException   {      int i;      byte[] buffer = new byte[18];      if((startAddr+len) > 32)         throw new OneWireException("Read exceeds memory bank end");      // calculate the address (32 and 48 are valid addresses)      byte memAddr;      if(startAddr < 16)         memAddr = (byte) startPhysicalAddress;      else         memAddr = (byte) (startPhysicalAddress + 16);      /* perform the recall/read and verification */      ib.doSpeed();      ib.adapter.reset();      if (ib.adapter.select(ib.address))      {         /* first recall the memory to shadow ram */         buffer [0] = RECALL_DATA_COMMAND;         buffer [1] = memAddr;         ib.adapter.dataBlock(buffer, 0, 2);         /* now read the shadow ram */         ib.adapter.reset();         ib.adapter.select(ib.address);         buffer [0] = READ_DATA_COMMAND;         // buffer[1] should still hold memAddr         System.arraycopy(ffBlock,0,buffer,2,16);         ib.adapter.dataBlock(buffer, 0, 18);         //user can re-read for verification         if((startAddr < 16) && (startAddr+len < 16))         {            for(i=startAddr;i<(startAddr+len);i++)               readBuf[offset+i-startAddr] = buffer[i+2];         }         else if(startAddr >= 16)         {            for(i=startAddr;i<(startAddr+len);i++)               readBuf[offset+i-startAddr] = buffer[i-startAddr+2+(startAddr-16)];         }         else         {            for(i=startAddr;i<16;i++)               readBuf[offset+i-startAddr] = buffer[i+2];            ib.adapter.reset();            ib.adapter.select(ib.address);            buffer[0] = RECALL_DATA_COMMAND;            buffer[1] = (byte) (memAddr + 16);            ib.adapter.dataBlock(buffer,0,2);            /* now read the shadow ram */            ib.adapter.reset();            ib.adapter.select(ib.address);            buffer[0] = READ_DATA_COMMAND;            // buffer[1] should still hold memAddr            System.arraycopy(ffBlock,0,buffer,2,16);            ib.adapter.dataBlock(buffer, 0, 18);            //user can re-read for verification            for(i=16;i<(startAddr+len);i++)               readBuf[i+offset-startAddr] = buffer[i-14];         }      }      else         throw new OneWireException("OneWireContainer30-Device not found.");   }   /**    * Write  memory in the current bank.  It is recommended that    * when writing  data that some structure in the data is created    * to provide error free reading back with read().  Or the    * method 'writePagePacket()' could be used which automatically    * wraps the data in a length and CRC.    *    * When using on Write-Once devices care must be taken to write into    * into empty space.  If write() is used to write over an unlocked    * page on a Write-Once device it will fail.  If write verification    * is turned off with the method 'setWriteVerification(false)' then    * the result will be an 'AND' of the existing data and the new data.    *    * @param  startAddr     starting address    * @param  writeBuf      byte array containing data to write    * @param  offset        offset into writeBuf to get data    * @param  len           length in bytes to write    *    * @throws OneWireIOException    * @throws OneWireException    */   public void write (int startAddr, byte[] writeBuf, int offset, int len)      throws OneWireIOException, OneWireException   {      byte[] buffer = new byte [18];      byte[] memory = new byte [32];      int modify;      int i;      if(startAddr+len > 32)         throw new OneWireException("Write exceeds memory bank end");      // the first block is at address 32 and the second is at address 48      byte memAddr;      if(startAddr < 16)         memAddr = (byte) startPhysicalAddress;      else         memAddr = (byte) (startPhysicalAddress + 16);      // if the EEPROM block is locked throw a OneWireIOException      if ((lockPage0 && (memAddr == 32)) || (lockPage1 && (memAddr == 48)))         throw new OneWireIOException(            "OneWireContainer30-Cant write data to locked EEPROM block.");      // read memory that is already there      read(0, false, memory, 0, 32);      System.arraycopy(writeBuf,offset,memory,startAddr,len);      /* perform the write/verification and copy */      ib.doSpeed();      ib.adapter.reset();      if (ib.adapter.select(ib.address))      {         /* first write to shadow rom */         buffer[0] = WRITE_DATA_COMMAND;         buffer[1] = memAddr;         if(memAddr == 32)         {            System.arraycopy(memory,0,buffer,2,16);            modify = 0;         }         else         {            System.arraycopy(memory,16,buffer,2,16);            modify = 16;         }         ib.adapter.dataBlock(buffer, 0, 18);         /* read the shadow ram back for verification */         ib.adapter.reset();         ib.adapter.select(ib.address);         buffer[0] = READ_DATA_COMMAND;         // buffer[1] should still hold memAddr         System.arraycopy(ffBlock,0,buffer,2,16);         ib.adapter.dataBlock(buffer, 0, 18);         // verify data         for (i = 0; i < 16; i++)            if (buffer [i + 2] != memory[i+modify])               throw new OneWireIOException(                  "Error writing EEPROM memory bank");         /* now perform the copy to EEPROM */         ib.adapter.reset();         ib.adapter.select(ib.address);         buffer[0] = COPY_DATA_COMMAND;         // buffer[1] should still hold memAddr         ib.adapter.dataBlock(buffer, 0, 2);         if((startAddr < 16) && ((startAddr+len) >= 16))         {            memAddr = 48;            ib.adapter.reset();            if(ib.adapter.select(ib.address))            {               /* first write to shadow rom */               buffer[0] = WRITE_DATA_COMMAND;               buffer[1] = memAddr;               System.arraycopy(memory,16,buffer,2,16);               ib.adapter.dataBlock(buffer,0,18);               /* read the shadow ram back for verification */               ib.adapter.reset();               ib.adapter.select(ib.address);               buffer[0] = READ_DATA_COMMAND;               // buffer[1] should still hold memAddr               System.arraycopy(ffBlock,0,buffer,2,16);               ib.adapter.dataBlock(buffer,0,18);               // verify data               for(i=0; i<16; i++)                  if(buffer[i+2] != memory[i+16])                     throw new OneWireIOException(                        "Error writing EEPROM memory bank");               /* now perfomr the copy to EEPROM */               ib.adapter.reset();               ib.adapter.select(ib.address);               buffer[0] = COPY_DATA_COMMAND;               ib.adapter.dataBlock(buffer, 0, 2);            }         }      }      else         throw new OneWireException("OneWireContainer30-Device not found.");   }   //--------   //-------- PagedMemoryBank I/O methods   //--------   /**    * Read  page in the current bank with no    * CRC checking (device or data). The resulting data from this API    * may or may not be what is on the 1-Wire device.  It is recommends    * that the data contain some kind of checking (CRC) like in the    * readPagePacket() method or have the 1-Wire device provide the    * CRC as in readPageCRC().  readPageCRC() however is not    * supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPage() continious where the last one    *                       led off and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPage (int page, boolean readContinue, byte[] readBuf,                         int offset)      throws OneWireIOException, OneWireException   {      read(page * pageLength, readContinue, readBuf, offset, pageLength);   }   /**    * Read  page with extra information in the current bank with no    * CRC checking (device or data). The resulting data from this API    * may or may not be what is on the 1-Wire device.  It is recommends    * that the data contain some kind of checking (CRC) like in the    * readPagePacket() method or have the 1-Wire device provide the    * CRC as in readPageCRC().  readPageCRC() however is not    * supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    * See the method 'hasExtraInfo()' for a description of the optional    * extra information some devices have.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPage() continious where the last one    *                       led off and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    * @param  extraInfo     byte array to put extra info read into    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPage (int page, boolean readContinue, byte[] readBuf,                         int offset, byte[] extraInfo)      throws OneWireIOException, OneWireException   {      throw new OneWireException(            "Read extra information not supported on this memory bank");   }   /**    * Read a Universal Data Packet and extra information.  See the    * method 'readPagePacket()' for a description of the packet structure.    * See the method 'hasExtraInfo()' for a description of the optional    * extra information some devices have.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPagePacket() continious where the last one

⌨️ 快捷键说明

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