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

📄 onewirecontainer41.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      return ((state[register&0x3F] & bitMask) != 0);   }   /**    * <p>Sets the status of the specified flag in the specified register.    * If a mission is in progress a <code>OneWireIOException</code> will be thrown    * (one cannot write to the registers while a mission is commencing).  This method    * actually communicates with the DS1922.  To improve    * performance if you intend to make multiple calls to this method,    * first call <code>readDevice()</code> and use the    * <code>setFlag(int,byte,boolean,byte[])</code> method instead.</p>    *    * <p>For more information on valid values for the <code>bitMask</code>    * parameter, see the {@link #getFlag(int,byte) getFlag(int,byte)} method.</p>    *    * @param register address of register containing the flag (see    * {@link #getFlag(int,byte) getFlag(int,byte)} for available options)    * @param bitMask the flag to read (see {@link #getFlag(int,byte) getFlag(int,byte)}    * for available options)    * @param flagValue new value for the flag (<code>true</code> is logic "1")    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  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'.    *         In the case of the DS1922, this could also be due to a    *         currently running mission.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #getFlag(int,byte)    * @see #getFlag(int,byte,byte[])    * @see #setFlag(int,byte,boolean,byte[])    * @see #readDevice()    */   public void setFlag (int register, byte bitMask, boolean flagValue)      throws OneWireIOException, OneWireException   {      byte[] state = readDevice();      setFlag(register, bitMask, flagValue, state);      writeDevice(state);   }   /**    * <p>Sets the status of the specified flag in the specified register.    * If a mission is in progress a <code>OneWireIOException</code> will be thrown    * (one cannot write to the registers while a mission is commencing).  This method    * is the preferred manner of setting the DS1922 status and control flags.    * The method <code>writeDevice()</code> must be called to finalize    * changes to the device.  Note that multiple 'set' methods can    * be called before one call to <code>writeDevice()</code>.</p>    *    * <p>For more information on valid values for the <code>bitMask</code>    * parameter, see the {@link #getFlag(int,byte) getFlag(int,byte)} method.</p>    *    * @param register address of register containing the flag (see    * {@link #getFlag(int,byte) getFlag(int,byte)} for available options)    * @param bitMask the flag to read (see {@link #getFlag(int,byte) getFlag(int,byte)}    * for available options)    * @param flagValue new value for the flag (<code>true</code> is logic "1")    * @param state current state of the device returned from <code>readDevice()</code>    *    * @see #getFlag(int,byte)    * @see #getFlag(int,byte,byte[])    * @see #setFlag(int,byte,boolean)    * @see #readDevice()    * @see #writeDevice(byte[])    */   public void setFlag (int register, byte bitMask, boolean flagValue,                        byte[] state)   {      register = register&0x3F;      byte flags = state [register];      if (flagValue)         flags = (byte)(flags | bitMask);      else         flags = (byte)(flags & ~(bitMask));      // write the regs back      state [register] = flags;   }// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Container Functions//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *****************************************************************************   /**    * Gets 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 v = new Vector(4);      v.addElement(scratch);      v.addElement(userDataMemory);      v.addElement(register);      v.addElement(log);      return v.elements();   }   /**    * Returns instance of the memory bank representing this device's    * scratchpad.    *    * @return scratchpad memory bank    */   public MemoryBankScratchCRCPW getScratchpadMemoryBank()   {      return this.scratch;   }   /**    * Returns instance of the memory bank representing this device's    * general-purpose user data memory.    *    * @return user data memory bank    */   public MemoryBankNVCRCPW getUserDataMemoryBank()   {      return this.userDataMemory;   }   /**    * Returns instance of the memory bank representing this device's    * data log.    *    * @return data log memory bank    */   public MemoryBankNVCRCPW getDataLogMemoryBank()   {      return this.log;   }   /**    * Returns instance of the memory bank representing this device's    * special function registers.    *    * @return register memory bank    */   public MemoryBankNVCRCPW getRegisterMemoryBank()   {      return this.register;   }   /**    * Returns the maximum speed this iButton device can    * communicate at.    *    * @return maximum speed    * @see DSPortAdapter#setSpeed    */   public int getMaxSpeed ()   {      return DSPortAdapter.SPEED_OVERDRIVE;   }   /**    * Gets the Dallas Semiconductor part number of the iButton    * or 1-Wire Device as a <code>java.lang.String</code>.    * For example "DS1992".    *    * @return iButton or 1-Wire device name    */   public String getName ()   {      return partNumber;   }   /**    * Retrieves the alternate Dallas Semiconductor part numbers or names.    * A 'family' of MicroLAN devices may have more than one part number    * depending on packaging.  There can also be nicknames such as    * "Crypto iButton".    *    * @return  the alternate names for this iButton or 1-Wire device    */   public String getAlternateNames ()   {      return "Hygrochron";   }   /**    * Gets a short description of the function of this iButton    * or 1-Wire Device type.    *    * @return device description    */   public String getDescription ()   {      return descriptionString;   }   /**    * Directs the container to avoid the calls to doSpeed() in methods that communicate    * with the DS1922/DS2422. To ensure that all parts can talk to the 1-Wire bus    * at their desired speed, each method contains a call    * to <code>doSpeed()</code>.  However, this is an expensive operation.    * If a user manages the bus speed in an    * application,  call this method with <code>doSpeedCheck</code>    * as <code>false</code>.  The default behavior is    * to call <code>doSpeed()</code>.    *    * @param doSpeedCheck <code>true</code> for <code>doSpeed()</code> to be called before every    * 1-Wire bus access, <code>false</code> to skip this expensive call    *    * @see OneWireContainer#doSpeed()    */   public synchronized void setSpeedCheck (boolean doSpeedCheck)   {      doSpeedEnable = doSpeedCheck;   }// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// DS1922 Device Specific Functions//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// *****************************************************************************   /**    * Stops the currently running mission.    *    */   public void stopMission()      throws OneWireException, OneWireIOException   {      /* read a user specified amount of memory and verify its validity */      if(doSpeedEnable)         doSpeed();      if(!adapter.select(address))         throw new OneWireException("OneWireContainer41-Device not present.");      byte[] buffer = new byte [10];      buffer [0] = STOP_MISSION_PW_COMMAND;      getContainerReadWritePassword(buffer, 1);      buffer[9] = (byte)0xFF;      adapter.dataBlock(buffer, 0, 10);      if (getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MISSION_IN_PROGRESS))         throw new OneWireException(            "OneWireContainer41-Stop mission failed.  Check read/write password.");   }   /**    * Starts a new mission.  Assumes all parameters have been set by either    * writing directly to the device registers, or by calling other setup    * methods.    */   public void startMission()      throws OneWireException, OneWireIOException   {      if (getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MISSION_IN_PROGRESS))         throw new OneWireException(            "OneWireContainer41-Cannot start a mission while a mission is in progress.");      if(!getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MEMORY_CLEARED))         throw new OneWireException(            "OneWireContainer41-Must clear memory before calling start mission.");      if(doSpeedEnable)         doSpeed();      if(!adapter.select(address))         throw new OneWireException("OneWireContainer41-Device not present.");      byte[] buffer = new byte [10];      buffer [0] = START_MISSION_PW_COMMAND;      getContainerReadWritePassword(buffer, 1);      buffer[9] = (byte)0xFF;      adapter.dataBlock(buffer, 0, 10);   }   /**    * Erases the log memory from this missioning device.    */   public void clearMemory()      throws OneWireException, OneWireIOException   {      if (getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MISSION_IN_PROGRESS))         throw new OneWireException(            "OneWireContainer41-Cannot clear memory while mission is in progress.");      if(doSpeedEnable)         doSpeed();      if(!adapter.select(address))         throw new OneWireException("OneWireContainer41-Device not present.");      byte[] buffer = new byte [10];      buffer [0] = CLEAR_MEMORY_PW_COMMAND;      getContainerReadWritePassword(buffer, 1);      buffer [9] = (byte) 0xFF;      adapter.dataBlock(buffer, 0, 10);      // wait 2 ms for Clear Memory to comlete      msWait(2);      if(!getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MEMORY_CLEARED))         throw new OneWireException(            "OneWireContainer41-Clear Memory failed.  Check read/write password.");   }// *****************************************************************************//  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Read/Write Password Functions

⌨️ 快捷键说明

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