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

📄 onewirecontainer12.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   }   /**    * <p>Clears the activity latches the next time possible.  For    * example, on a DS2406/07, this happens the next time the    * status is read with <code>readDevice()</code>.</p>    *    * <p>The activity latches will only be cleared once.  With the    * DS2406/07, this means that only the first call to     * <code>readDevice()</code> will clear the activity latches.      * Subsequent calls to <code>readDevice()</code> will leave the    * activity latch states intact, unless this method has been     * invoked since the last call to <code>readDevice()</code>.</p>    *    * @see com.dalsemi.onewire.container.OneWireSensor#readDevice()    * @see #getSensedActivity(int,byte[])    */   public void clearActivity ()   {      synchronized (this)      {         clearactivity = true;      }   }   //--------   //-------- Switch 'set' Methods   //--------   /**    * Sets the latch state of the indicated channel.    * 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>.    *    * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)]    * @param latchState <code>true</code> to set the channel latch 'on'    *     (conducting) and <code>false</code> to set the channel latch 'off' (not    *     conducting).  Note that the actual output when the latch is 'on'    *     is returned from the <code>isHighSideSwitch()</code> method.    * @param doSmart If latchState is 'on'/<code>true</code> then doSmart indicates    *                  if a 'smart on' is to be done.  To avoid an exception    *                  check the capabilities of this device using the    *                  <code>hasSmartOn()</code> method.    * @param state current state of the device returned from <code>readDevice()</code>    *    * @see #hasSmartOn()    * @see #getLatchState(int,byte[])    * @see com.dalsemi.onewire.container.OneWireSensor#writeDevice(byte[])    */   public void setLatchState (int channel, boolean latchState,                              boolean doSmart, byte[] state)   {      if (channel == 0)      {         state[1] &= (byte)0xdf;         if (!latchState)            state [1] = ( byte ) (state [1] | 0x20);      }      else      {         state[1] &= (byte)0xbf;         if (!latchState)            state [1] = ( byte ) (state [1] | 0x40);      }   }   /**    * Retrieves the 1-Wire device sensor state.  This state is    * returned as a byte array.  Pass this byte array to the 'get'    * and 'set' methods.  If the device state needs to be changed then call    * the 'writeDevice' to finalize the changes.    *    * @return 1-Wire device sensor state    *    * @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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public byte[] readDevice ()      throws OneWireIOException, OneWireException   {      byte[] state = new byte [2];      //the first byte is the raw status      //the second byte is for writing      //this is a strange solution because      //the status we are interested in reading does not      //look the same as the status we are interested in writing      synchronized (this)      {         if (doSpeedEnable)            doSpeed();         // select the device         if (adapter.select(address))         {            // channel access command            buffer [0] = CHANNEL_ACCESS_COMMAND;            // send the control bytes            if (clearactivity)            {               buffer [1] = ( byte ) 0xD5;               clearactivity = false;            }            else            {               buffer [1] = ( byte ) 0x55;            }            buffer [2] = ( byte ) 0xFF;            // read the info, dummy and CRC16            for (int i = 3; i < 7; i++)               buffer [i] = ( byte ) 0xFF;            // send the block            adapter.dataBlock(buffer, 0, 7);            // calculate the CRC16 on the result and check if correct            if (CRC16.compute(buffer, 0, 7, 0) == 0xB001)            {               state [0] = buffer [3];               //let's read the status byte 7 and get the data there               buffer[0] = (byte)0x0aa; //READ_STATUS               buffer[1] = 7;  //address to read               buffer[2] = 0;               for (int i=3;i<6;i++)  //plus room for the CRC                   buffer[i] = (byte)0x0ff;               adapter.reset();               adapter.select(address);               adapter.dataBlock(buffer,0,6);               if (CRC16.compute(buffer, 0, 6, 0) == 0xB001)               {                   state[1] = buffer[3];                   return state;               }            }         }      }     //end synch block      // device must not have been present      throw new OneWireIOException(address, "OneWireContainer12-device not present");   }   /**    * Writes the 1-Wire device sensor state that    * have been changed by 'set' methods.  Only the state registers that    * changed are updated.  This is done by referencing a field information    * appended to the state data.    *    * @param  state 1-Wire device sensor state    *    * @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'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public void writeDevice (byte[] state)      throws OneWireIOException, OneWireException   {      if (doSpeedEnable)         doSpeed();      if (adapter.select(address))      {         synchronized (this)         {            // create a block to set the switch state            // read memory and counter command            // write status command            buffer [0] = WRITE_STATUS_COMMAND;            // address of switch state in status            buffer [1] = 0x07;            buffer [2] = 0x00;            // write state            buffer [3] = ( byte ) state [1];            // read CRC16            buffer [4] = ( byte ) 0xFF;            buffer [5] = ( byte ) 0xFF;            // send the block            adapter.dataBlock(buffer, 0, 6);            // calculate the CRC16 on the result and check if correct            if (CRC16.compute(buffer, 0, 6, 0) == 0xB001)               return;         }      }      // device must not have been present      throw new OneWireException(address, "OneWireContainer12-device not present");   }   /**    * Directs the container to avoid the calls to doSpeed() in methods that communicate    * with the Thermocron. 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;   }    /**     * <p>Programs the Conditional Search options for the DS2406/2407.</p>     *     * <p>The DS2406/2407 supports Conditional Searches with     * user programmable search conditions.  This means that     * the part can alarm on several kinds of conditions,     * programmable by the user.</p>     *     * <p>The user can select a channel and a source to compare to     * a polarity.  If the source's logical value is equal to the     * polarity, the device alarms (responds to a Conditional Search).     * For instance, if <code>channel</code> is <code>CHANNEL_A</code>,     * <code>source</code> is <code>SOURCE_ACTIVITY_LATCH</code>,     * and <code>polarity</code> is <code>POLARITY_ONE</code>, then the     * device will respond to a Conditional Search when the activity     * latch on channel A is 1 (when activity has been detected on     * channel A).  When <code>channel</code> is <code>CHANNEL_BOTH</code>,     * the selected source signals are ORed for comparison with the polarity.     * When <code>channel</code> is <code>CHANNEL_NONE</code>,  the selected     * source signal is considered a logical '0'.  In other words, if     * <code>channel</code> is <code>CHANNEL_NONE</code>, if <code>polarity</code>     * is <code>POLARITY_ZERO</code>, the device always responds to a     * Conditional Search.  If <code>polarity</code> is <code>POLARITY_ONE</code>,     * the device never responds to a Conditional Search.</p>     *     * <p>Note that for any of these options, the value <code>DONT_CHANGE</code>     * will insure that the value previously used by the DS2406/2407 will     * not be altered.</p>     *     * <p>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>Also note that the Hidden Mode of the DS2407 is not supported in this     * implementation as an option for source selection.  Hidden Mode was     * phased out for the newer DS2406.  See the datasheet for the DS2407     * for more information on Hidden Mode.</p>     *     * @param channel the channel of interest for the source of the conditional check     * (valid values are <code>CHANNEL_NONE</code>, <code>CHANNEL_A_ONLY</code>, <code>CHANNEL_B_ONLY</code>, <code>CHANNEL_BOTH</code>, and <code>DONT_CHANGE</code>)     * @param source the source selection for the conditional check     * (valid values are <code>SOURCE_ACTIVITY_LATCH</code>, <code>SOURCE_FLIP_FLOP</code>, <code>SOURCE_PIO</code>, and <code>DONT_CHANGE</code>)     * @param polarity the polarity selection for the conditional check     * (valid values are <code>POLARITY_ZERO</code>, <code>POLARITY_ONE</code>, and <code>DONT_CHANGE</code>)     * @param state current state of the device returned from <code>readDevice()</code>     *     * @see com.dalsemi.onewire.container.OneWireSensor#readDevice()     * @see com.dalsemi.onewire.container.OneWireSensor#writeDevice(byte[])     * @see #CHANNEL_NONE     * @see #CHANNEL_A_ONLY     * @see #CHANNEL_B_ONLY     * @see #CHANNEL_BOTH     * @see #SOURCE_ACTIVITY_LATCH     * @see #SOURCE_PIO     * @see #SOURCE_FLIP_FLOP     * @see #POLARITY_ONE     * @see #POLARITY_ZERO     * @see #DONT_CHANGE     */    public void setSearchConditions(byte channel, byte source, byte polarity, byte[] state)    {        //state[1] bitmap        // SUP PIOB PIOA CSS4 CSS3 CSS2 CSS1  CSS0        //               [channel] [source ][polarity]        //so channel needs to be shifted left once, other's can be or-ed in        byte newstate = 0;        if (channel!=DONT_CHANGE)        {            newstate = (byte)(channel << 1);        }        if (source!=DONT_CHANGE)        {            newstate |= source;        }        if (polarity!=DONT_CHANGE)        {            newstate |= polarity;        }        state[1] = (byte) (state[1] & 0xe0);        state[1] |= newstate;    }   /**    * <p>Accesses the PIO channels to sense the logical status of    * the output node.  This method supports all the modes of    * communication with the part as described in the datasheet for    * the DS2406/2407.</p>    *    * @param inbuffer The input buffer.  Depending on the other options chosen    * to this method, this will contain data to be written to    * the channels or it will hold space for data that will be read.    *    * @param toggleRW By selecting <code>toggleRW</code> to be    * <code>true</code>, the part will alternately    * read and write bytes from and to this channel.  Setting    * <code>toggleRW</code> to <code>false</code> means    * that only one operation will occur, whichever operation    * is selected by <code>readInitially</code>. <br> <i> <b> NOTE: </b>     * When toggleRW is <code>true</code> the 'read' bytes are    * automatically provided and only the results of the read    * bytes are returned. </i>    *    * @param readInitially If <code>readInitially</code> is    * <code>true</code>, the first operation to occur will    * be a read, else it will be a write.  If <code>toggleRW</code>    * is <code>false</code>, the operation chosen by this flag    * is the only operation that will occur.  If <code>toggleRW</code>    * is <code>true</code>, this operation is the one    * that will occur first, then the other will occur.  For example,    * if <code>toggleRW</code> is <code>true</code> and

⌨️ 快捷键说明

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