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

📄 memorybankeepromblock.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    *                       stopped and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to put data read. Must have at least    *                       'getMaxPacketDataLength()' elements.    * @param  offset        offset into readBuf to place data    * @param  extraInfo     byte array to put extra info read into    *    * @return  number of data bytes written to readBuf at the offset.    *    * @throws OneWireIOException    * @throws OneWireException    */   public int readPagePacket (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    *                       stopped and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to put data read. Must have at least    *                       'getMaxPacketDataLength()' elements.    * @param  offset        offset into readBuf to place data    *    * @return  number of data bytes written to readBuf at the offset.    *    * @throws OneWireIOException    * @throws OneWireException    */   public int readPagePacket (int page, boolean readContinue, byte[] readBuf,                              int offset)      throws OneWireIOException, OneWireException   {      byte[] raw_buf = new byte [pageLength];      // read entire page with read page CRC      read((page*pageLength), readContinue, raw_buf, 0, pageLength);      // check if length is realistic      if ((raw_buf [0] & 0x00FF) > maxPacketDataLength)      {         forceVerify();         throw new OneWireIOException("Invalid length in packet");      }      // verify the CRC is correct      if (CRC16.compute(raw_buf, 0, raw_buf [0] + 3, page) == 0x0000B001)      {         // extract the data out of the packet         System.arraycopy(raw_buf, 1, readBuf, offset, raw_buf [0]);         // return the length         return raw_buf [0];      }      else      {         forceVerify();         throw new OneWireIOException("Invalid CRC16 in packet read");      }   }   /**    * Write a Universal Data Packet.  See the method 'readPagePacket()'    * for a description of the packet structure.    *    * @param  page          page number to write packet to    * @param  writeBuf      data byte array to write    * @param  offset        offset into writeBuf where data to write is    * @param  len           number of bytes to write    *    * @throws OneWireIOException    * @throws OneWireException    */   public void writePagePacket (int page, byte[] writeBuf, int offset,                                int len)      throws OneWireIOException, OneWireException   {      // make sure length does not exceed max      if (len > maxPacketDataLength)         throw new OneWireIOException(            "Length of packet requested exceeds page size");      // construct the packet to write      byte[] raw_buf = new byte [len + 3];      raw_buf [0] = ( byte ) len;      System.arraycopy(writeBuf, offset, raw_buf, 1, len);      int crc = CRC16.compute(raw_buf, 0, len + 1, page);      raw_buf [len + 1] = ( byte ) (~crc & 0xFF);      raw_buf [len + 2] = ( byte ) (((~crc & 0xFFFF) >>> 8) & 0xFF);      // write the packet, return result      write(page * pageLength, raw_buf, 0, len + 3);   }   /**    * Read a complete memory page with CRC verification provided by the    * device.  Not supported by all devices.  See the method    * 'hasPageAutoCRC()'.    *    * @param  page          page number to read    * @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    *                       stopped and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to put data read. Must have at least    *                       'getMaxPacketDataLength()' elements.    * @param  offset        offset into readBuf to place data    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPageCRC (int page, boolean readContinue, byte[] readBuf,                            int offset)      throws OneWireIOException, OneWireException   {      throw new OneWireException(            "Read page with CRC not supported in this memory bank");   }   /**    * Read a complete memory page with CRC verification provided by the    * device with extra information.  Not supported by all devices.    * See the method 'hasPageAutoCRC()'.    * See the method 'hasExtraInfo()' for a description of the optional    * extra information.    *    * @param  page          page number to read    * @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    *                       stopped and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to put data read. Must have at least    *                       'getMaxPacketDataLength()' elements.    * @param  offset        offset into readBuf to place data    * @param  extraInfo     byte array to put extra info read into    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPageCRC (int page, boolean readContinue, byte[] readBuf,                            int offset, byte[] extraInfo)      throws OneWireIOException, OneWireException   {      throw new OneWireException(            "Read page with CRC not supported in this memory bank");   }   //--------   //-------- OTPMemoryBank I/O methods   //--------   /**    * Lock the specifed page in the current memory bank.  Not supported    * by all devices.  See the method 'canLockPage()'.    *    * @param  page   number of page to lock    *    * @throws OneWireIOException    * @throws OneWireException    */   public void lockPage (int page)      throws OneWireIOException, OneWireException   {      if(page > 1)         throw new OneWireException("Page does not exist to lock");      ib.setFlag(OneWireContainer30.EEPROM_REGISTER,                 OneWireContainer30.EEPROM_LOCK_ENABLE_FLAG,true);      if(page == 0)      {         ib.setFlag(OneWireContainer30.EEPROM_REGISTER,                    OneWireContainer30.EEPROM_BLOCK_0_LOCK_FLAG,true);      }      else if(page == 1)      {         ib.setFlag(OneWireContainer30.EEPROM_REGISTER,                    OneWireContainer30.EEPROM_BLOCK_1_LOCK_FLAG,true);      }      // read back to verify      if (!isPageLocked(page))      {         forceVerify();         throw new OneWireIOException(            "Read back from write incorrect, could not lock page");      }      else      {         if(page == 0)         {            lockPage0 = true;         }         else if(page == 1)         {            lockPage1 = true;         }      }   }   /**    * Query to see if the specified page is locked.    * See the method 'canLockPage()'.    *    * @param  page  number of page to see if locked    *    * @return  'true' if page locked.    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isPageLocked (int page)      throws OneWireIOException, OneWireException   {      boolean flag = false;      if(page > 1)         throw new OneWireException("Page does not exist to be locked");      if(page == 0)      {         flag = ib.getFlag(OneWireContainer30.EEPROM_REGISTER,                           OneWireContainer30.EEPROM_BLOCK_0_LOCK_FLAG);      }      else if(page == 1)      {         flag = ib.getFlag(OneWireContainer30.EEPROM_REGISTER,                           OneWireContainer30.EEPROM_BLOCK_1_LOCK_FLAG);      }      return flag;   }   /**    * Redirect the specifed page in the current memory bank to a new page.    * Not supported by all devices.  See the method 'canRedirectPage()'.    *    * @param  page      number of page to redirect    * @param  newPage   new page number to redirect to    *    * @throws OneWireIOException    * @throws OneWireException    */   public void redirectPage (int page, int newPage)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This memory bank does not support redirection.");   }   /**    * Query to see if the specified page is redirected.    * Not supported by all devices.  See the method 'canRedirectPage()'.    *    * @param  page      number of page check for redirection    *    * @return  return the new page number or 0 if not redirected    *    * @throws OneWireIOException    * @throws OneWireException    *    * @deprecated  As of 1-Wire API 0.01, replaced by {@link #getRedirectedPage(int)}    */   public int isPageRedirected (int page)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This memory bank does not support redirection.");   }   /**    * Gets the page redirection of the specified page.    * Not supported by all devices.    *    * @param  page  page to check for redirection    *    * @return  the new page number or 0 if not redirected    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         no device present or a CRC read from the device is incorrect.  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 #canRedirectPage() canRedirectPage    * @see #redirectPage(int,int) redirectPage    * @since 1-Wire API 0.01    */   public int getRedirectedPage (int page)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This memory bank does not support redirection.");   }   /**    * Lock the redirection option for the specifed page in the current    * memory bank. Not supported by all devices.  See the method    * 'canLockRedirectPage()'.    *    * @param  page      number of page to redirect    *    * @throws OneWireIOException    * @throws OneWireException    */   public void lockRedirectPage (int page)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This memory bank does not support redirection.");   }   /**    * Query to see if the specified page has redirection locked.    * Not supported by all devices.  See the method 'canRedirectPage()'.    *    * @param  page      number of page check for locked redirection    *    * @return  return 'true' if redirection is locked for this page    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isRedirectPageLocked (int page)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This memory bank does not support redirection.");   }   //--------   //-------- checkSpeed methods   //--------   /**    * Check the device speed if has not been done before or if    * an error was detected.    *    * @throws OneWireIOException    * @throws OneWireException    */   public void checkSpeed ()      throws OneWireIOException, OneWireException   {      synchronized (this)      {         // only check the speed         if (doSetSpeed)         {            // attempt to set the correct speed and verify device present            ib.doSpeed();            // no execptions so clear flag            doSetSpeed = false;         }      }   }   /**    * Set the flag to indicate the next 'checkSpeed()' will force    * a speed set and verify 'doSpeed()'.    */   public void forceVerify ()   {      synchronized (this)      {         doSetSpeed = true;      }   }}

⌨️ 快捷键说明

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