onewirecontainer05.java
来自「这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统」· Java 代码 · 共 543 行 · 第 1/2 页
JAVA
543 行
/*--------------------------------------------------------------------------- * 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.adapter.DSPortAdapter;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.OneWireException;/** * <P> 1-Wire® container for a Single Addressable Switch, DS2405. This container * encapsulates the functionality of the 1-Wire family type <B>05</B> (hex)</P> * * <H3> Features </H3> * <UL> * <LI> Open drain PIO pin controlled through 1-Wire communication * <LI> Logic level sensing of the PIO pin can be sensed * <LI> Operating temperature range from -40°C to * +85°C * <li> One channel with level sensing abilities * <li> Does not support activity sensing or 'Smart On' capabilities * </UL> * * <H3> Memory </H3> * * <P> The DS2405 has no memory beyond its 64-bit registration number. </P> * * * <H3> Usage </H3> * * <p>The DS2405 supports level sensing, but not activity sensing. The code below * reads the state of the DS2405, extracting the latch state and the sensed level * of the PIO pin, then in the loop it toggles the latch state.</p> * * <code><pre> * // "ID" is a byte array of size 8 with an address of a part we * // have already found with family code 05 hex * // "access" is a DSPortAdapter * * int i=0; * OneWireContainer05 ds2405 = (OneWireContainer05) access.getDeviceContainer(ID); * ds2405.setupContainer(access,ID); * * byte[] state = ds2405.readDevice(); * * // I know that the 2405 only has one channel (one switch) * // and it doesn't support 'Smart On' * * boolean latch_state = ds2405.getLatchState(0,state); * System.out.println("Current state of switch: "+latch_state); * System.out.println("Current output level: "+ds2405.getLevel(0,state)); * while (++i < 100) * { * System.out.println("Toggling switch"); * ds2405.setLatchState(0,!latch_state,false,state); * ds2405.writeDevice(state); * state = ds2405.readDevice(); * latch_state = ds2405.getLatchState(0,state); * System.out.println("Current state of switch: "+latch_state); * System.out.println("Current output level: "+ds2405.getLevel(0,state)); * Thread.sleep(500); * } * * </pre></code> * * <p>Also see the usage example in the {@link com.dalsemi.onewire.container.SwitchContainer SwithContainer} * interface.</p> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2405.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2405.pdf</A> * </DL> * * Also see the {@link com.dalsemi.onewire.container.OneWireContainer12 DS2406}, a dual addressable switch (OneWireContainer12). * * @see com.dalsemi.onewire.container.OneWireSensor * @see com.dalsemi.onewire.container.SwitchContainer * @see com.dalsemi.onewire.container.OneWireContainer12 * * @version 0.00, 28 Aug 2000 * @author KLA,DSS */public class OneWireContainer05 extends OneWireContainer implements SwitchContainer{ //-------- //-------- Constructors //-------- /** * Creates a new <code>OneWireContainer</code> for communication with a DS2405. * 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 #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer05(DSPortAdapter,byte[]) * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer05(DSPortAdapter,long) * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer05(DSPortAdapter,String) */ public OneWireContainer05 () { super(); } /** * Creates a new <code>OneWireContainer</code> for communication with a DS2405. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2405 * * @see #OneWireContainer05() * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer05(DSPortAdapter,long) * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer05(DSPortAdapter,String) */ public OneWireContainer05 (DSPortAdapter sourceAdapter, byte[] newAddress) { super(sourceAdapter, newAddress); } /** * Creates a new <code>OneWireContainer</code> for communication with a DS2405. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2405 * * @see #OneWireContainer05() * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer05(DSPortAdapter,byte[]) * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer05(DSPortAdapter,String) */ public OneWireContainer05 (DSPortAdapter sourceAdapter, long newAddress) { super(sourceAdapter, newAddress); } /** * Creates a new <code>OneWireContainer</code> for communication with a DS2405. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2405 * * @see #OneWireContainer05() * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer05(DSPortAdapter,byte[]) * @see #OneWireContainer05(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer05(DSPortAdapter,long) */ public OneWireContainer05 (DSPortAdapter sourceAdapter, String newAddress) { super(sourceAdapter, newAddress); } //-------- //-------- Methods //-------- /** * 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 "DS2405"; } /** * 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 "Addressable Switch"; } /** * Gets a short description of the function of this iButton * or 1-Wire Device type. * * @return device description */ public String getDescription () { return "Addressable Switch with controlled open drain PIO " + "pin. PIO pin sink capability is greater than 4mA " + "at 0.4V."; } //-------- //-------- Switch Feature methods //-------- /** * Gets the number of channels supported by this switch. * Channel specific methods will use a channel number specified * by an integer from [0 to (<code>getNumberChannels(byte[])</code> - 1)]. Note that * all devices of the same family will not necessarily have the * same number of channels. * * @param state current state of the device returned from <code>readDevice()</code> * * @return the number of channels for this device * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() */ public int getNumberChannels (byte[] state) { //we ignore the state, DS2405 can only have one channel return 1; } /** * Checks if the channels of this switch are 'high side' * switches. This indicates that when 'on' or <code>true</code>, the switch output is * connect to the 1-Wire data. If this method returns <code>false</code> * then when the switch is 'on' or <code>true</code>, the switch is connected * to ground. * * @return <code>true</code> if the switch is a 'high side' switch, * <code>false</code> if the switch is a 'low side' switch * * @see #getLatchState(int,byte[]) */ public boolean isHighSideSwitch () { return false; } /** * Checks if the channels of this switch support * activity sensing. If this method returns <code>true</code> then the * method <code>getSensedActivity(int,byte[])</code> can be used. * * @return <code>true</code> if channels support activity sensing * * @see #getSensedActivity(int,byte[]) * @see #clearActivity()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?