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

📄 onewirecontainer12.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.container;// importsimport com.dalsemi.onewire.utils.CRC16;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.OneWireException;import java.util.Vector;import java.util.Enumeration;/** * <P> 1-Wire&#174 container for a Dual Addressable Switch, DS2406 or DS2407. * This container encapsulates the functionality of the 1-Wire family type <B>12</B> (hex). * The DS2406 replaces the DS2407, but does not have hidden mode or user programmable * power-on settings.</P> * * <H3> Features </H3> * <UL> *   <LI> Open drain PIO pin controlled through 1-Wire communication *   <li> 1024-bits of user programmable OTP EPROM *   <LI> Operating temperature range from -40&#176C to +85&#176C *   <li> On-chip CRC16 generator allows detection of data transfer errors *   <li> One or two channels with level sensing abilities *   <li> Supports activity sensing *   <li> Does not support 'Smart On' capabilities *   <li> TO-92 (1 channel) or TSOC (2 channel) packaging *   <li> Supports Conditional Search with user-selectable search options * </UL> * * <H3> Memory </H3> * * <P> The memory can be accessed through the objects that are returned * from the {@link #getMemoryBanks() getMemoryBanks} method. </P> * * The following is a list of the MemoryBank instances that are returned: * * <UL> *   <LI> <B> Main Memory </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank}, *                  {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank} *         <LI> <I> Size </I> 128 starting at physical address 0 *         <LI> <I> Features</I> Write-once general-purpose non-volatile needs-program-pulse *         <LI> <I> Pages</I> 4 pages of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC pages-redirectable pages-lockable *         <li> <i> Extra information for each page</i>  Inverted redirection page, length 1 *      </UL> *   <LI> <B> Write protect pages and Page redirection </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank}, *                  {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank} *         <LI> <I> Size </I> 8 starting at physical address 0 (in STATUS memory area) *         <LI> <I> Features</I> Write-once not-general-purpose non-volatile needs-program-pulse *         <LI> <I> Pages</I> 1 pages of length 8 bytes *         <LI> <I> Page Features </I> page-device-CRC *      </UL> * </UL> * * <H3> Usage </H3> * * <p>The DS2406 supports level sensing and activity sensing.  The code below * reports the flip-flop state, PIO level, and sensed activity while toggling * every switch each time through the loop.  It toggles every switch it finds, * regardless if the device has one or two switches.</p> * * <code><pre> *      // "ID" is a byte array of size 8 with an address of a part we *      // have already found with family code 12 hex *      // "access" is a DSPortAdapter * *      OneWireContainer12 ds2406 = (OneWireContainer12) access.getDeviceContainer(ID); *      ds2406.setupContainer(access,ID); * *      byte[] state = ds2406.readDevice(); *      int numchannels = ds2406.getNumberChannels(state); *      System.out.println("Number of Channels: "+numchannels); *      boolean[] switches = new boolean[numchannels]; * *      ds2406.clearActivity(); * *      for (int j=0;j<10;j++) *      { *          //clear the activity latches halfway through the test *          if (j==5) *              ds2406.clearActivity(); *          state = ds2406.readDevice(); * *          //first let's print out the status of all the latches *          for (int i=0;i &lt; numchannels;i++) *          { *              System.out.println("---------------------------------------------------------\r\n"); *              System.out.println("                       CHANNEL "+i); *              System.out.println("---------------------------------------------------------\r\n"); * *              System.out.println("           Latch state: "+ds2406.getLatchState(i,state)); *              System.out.println("           Level      : "+ds2406.getLevel(i,state)); *              System.out.println("           Activity   : "+ds2406.getSensedActivity(i, state)); *              switches[i] = ds2406.getLatchState(i,state); *          } * *          //now lets toggle the switch flip-flop *          for (int i=0;i &lt; numchannels;i++) *          { *              ds2406.setLatchState(i,!switches[i],false,state); *          } *          ds2406.writeDevice(state); * *          Thread.sleep(500); *      } * * </pre></code> * * <p>Also see the usage example in the {@link com.dalsemi.onewire.container.SwitchContainer SwithContainer} * interface.</p> * * For examples regarding memory operations, * <uL> * <li> See the usage example in * {@link com.dalsemi.onewire.container.OneWireContainer OneWireContainer} * to enumerate the MemoryBanks. * <li> See the usage examples in * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank} and * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} * for bank specific operations. * </uL> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2406.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2406.pdf for the DS2406</A> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2407.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2407.pdf for the DS2407</A> * </DL> * * Also see the {@link com.dalsemi.onewire.container.OneWireContainer05 DS2405}, a single addressable switch (OneWireContainer05). * * @see com.dalsemi.onewire.container.OneWireSensor * @see com.dalsemi.onewire.container.SwitchContainer * @see com.dalsemi.onewire.container.OneWireContainer05 * *  @version    0.00, 28 Aug 2000 *  @author     KLA,DSS */public class OneWireContainer12   extends OneWireContainer   implements SwitchContainer{   //--------   //-------- Static Final Variables   //--------   /**    * Used to set the <code>source</code> to the activity latch for    * conditional searches in the <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte SOURCE_ACTIVITY_LATCH = (byte) 0x02;   /**    * Used to set the <code>source</code> to the flip-flop state for    * conditional searches in the <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte SOURCE_FLIP_FLOP      = (byte) 0x04;   /**    * Used to set the <code>source</code> to the PIO status for    * conditional searches in the <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte SOURCE_PIO            = (byte) 0x06;   /**    * Used to set the <code>polarity</code> to logical '0' for conditional search    * checking in the <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte POLARITY_ZERO = 0x00;   /**    * Used to set the <code>polarity</code> to logical '1' for conditional search    * checking in the <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte POLARITY_ONE  = 0x01;   /**    * Used to select neither channel as the source for alarm conditions in the    * <code>setSearchConditions()</code> method.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte CHANNEL_NONE = 0x00;   /**    * Used for options in the <code>setSearchConditions()</code> to    * make sure the specified option is not changes from its current    * value.    *    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte DONT_CHANGE = (byte)0x0ff;   /**    * <code>channelMode</code> for the <code>channelAccess</code> method.    * Selects Channel A (channel 0) for communication.  Also used to    * select Channel A as the source for alarm conditions in the    * <code>setSearchConditions()</code> method.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte CHANNEL_A_ONLY = 0x04;   /**    * <code>channelMode</code> for the <code>channelAccess</code> method.    * Selects Channel B (channel 1) for communication.  Also used to    * select Channel B as the source for alarm conditions in the    * <code>setSearchConditions()</code> method.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte CHANNEL_B_ONLY = 0x08;   /**    * <code>channelMode</code> for the <code>channelAccess</code> method.    * Selects both Channel A and B (channel 0 and 1) for communication.  Also used to    * select both channels as the source for alarm conditions in the    * <code>setSearchConditions()</code> method.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    * @see #setSearchConditions(byte,byte,byte,byte[])    */   public static final byte CHANNEL_BOTH = 0x0c;   /**    * <code>CRCMode</code> for the <code>channelAccess</code> method.    * Requests no CRC generation by the DS2406/2407.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    */   public static final byte CRC_DISABLE = 0x00;   /**    * <code>CRCMode</code> for the <code>channelAccess</code> method.    * Requests CRC generation after every byte transmitted.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    */   public static final byte CRC_EVERY_BYTE = 0x01;   /**    * <code>CRCMode</code> for the <code>channelAccess</code> method.    * Requests CRC generation after every 8 bytes transmitted.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    */   public static final byte CRC_EVERY_8_BYTES = 0x02;   /**    * <code>CRCMode</code> for the <code>channelAccess</code> method.    * Requests CRC generation after every 32 bytes transmitted.    *    * @see #channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)    */   public static final byte CRC_EVERY_32_BYTES = 0x03;   // privates !   /* DS2406 Write status command                                */   private static final byte WRITE_STATUS_COMMAND = 0x55;   /* DS2406 channel access command                              */   private static final byte CHANNEL_ACCESS_COMMAND = ( byte ) 0xF5;   /* internal buffer  */   private byte[]  buffer        = new byte [7];   private boolean clearactivity = false;   private boolean    doSpeedEnable = true;   //--------   //-------- Variables   //--------   //--------   //-------- Constructor   //--------   /**    * Creates a new <code>OneWireContainer</code> for communication with a DS2406/2407.    * Note that the method <code>setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[])</code>    * must be called to set the correct <code>DSPortAdapter</code> device address.    *    * @see com.dalsemi.onewire.container.OneWireContainer#setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) setupContainer(DSPortAdapter,byte[])    * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[])    * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer12(DSPortAdapter,long)    * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer12(DSPortAdapter,String)    */   public OneWireContainer12 ()   {      super();   }   /**

⌨️ 快捷键说明

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