📄 onewirecontainer1f.java
字号:
/*--------------------------------------------------------------------------- * 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.*;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.adapter.*;import java.io.*;import com.dalsemi.onewire.adapter.OneWireIOException;/** * <P> 1-Wire® container for 1-Wire(MicroLAN) Coupler, DS2409. * This container encapsulates the functionality of the 1-Wire family type <B>1F</B> (hex). * </P> * * <H3> Features </H3> * <UL> * <li> Low impedance coupler to create large * common-ground, multi-level MicroLAN * networks * <li> Keeps inactive branches pulled high to 5V * <li> Simplifies network topology analysis by * logically decoupling devices on active * network segments * <li> Conditional search for fast event signaling * <li> Auxiliary 1-Wire TM line to connect a memory * chip or to be used as digital input * <li> Programmable, general purpose open drain * control output * <li> Operating temperature range from -40°C to * +85°C * <li> Compact, low cost 6-pin TSOC surface mount * package * </UL> * * <P> Setting the latch on the DS2409 to 'on' * (see {@link #setLatchState(int,boolean,boolean,byte[]) seLatchState}) * connects the channel [Main(0) or Auxillary(1)] to the 1-Wire data line. Note * that this is the opposite of the * {@link com.dalsemi.onewire.container.OneWireContainer12 DS2406} and * {@link com.dalsemi.onewire.container.OneWireContainer05 DS2405} * which connect thier I/O lines to ground. * <H3> Usage </H3> * * <DL> * <DD> See the usage example in * {@link com.dalsemi.onewire.container.SwitchContainer SwitchContainer} * for basic switch operations. * </DL> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2409.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2409.pdf</A> * </DL> * * @see com.dalsemi.onewire.container.OneWireSensor * @see com.dalsemi.onewire.container.SwitchContainer * @see com.dalsemi.onewire.container.OneWireContainer05 * @see com.dalsemi.onewire.container.OneWireContainer12 * * @version 0.00, 13 Sept 2000 * @author DSS */public class OneWireContainer1F extends OneWireContainer implements SwitchContainer{ //-------- //-------- Static Final Variables //-------- /** Offset of BITMAP in array returned from read state. */ protected static final int BITMAP_OFFSET = 3; /** Offset of Status in array returned from read state. */ protected static final int STATUS_OFFSET = 0; /** Offset of Main channel flag in array returned from read state. */ protected static final int MAIN_OFFSET = 1; /** Offset of Main channel flag in array returned from read state. */ protected static final int AUX_OFFSET = 2; /** Channel flag to indicate turn off. */ protected static final int SWITCH_OFF = 0; /** Channel flag to indicate turn on. */ protected static final int SWITCH_ON = 1; /** Channel flag to indicate smart on. */ protected static final int SWITCH_SMART = 2; /** Read Write Status register commmand. */ protected static final byte READ_WRITE_STATUS_COMMAND = ( byte ) 0x5A; /** All lines off command. */ protected static final byte ALL_LINES_OFF_COMMAND = ( byte ) 0x66; /** Discharge command. */ protected static final byte DISCHARGE_COMMAND = ( byte ) 0x99; /** Direct on main command. */ protected static final byte DIRECT_ON_MAIN_COMMAND = ( byte ) 0xA5; /** Smart on main command. */ protected static final byte SMART_ON_MAIN_COMMAND = ( byte ) 0xCC; /** Smart on aux command. */ protected static final byte SMART_ON_AUX_COMMAND = ( byte ) 0x33; /** Main Channel number. */ public static final int CHANNEL_MAIN = 0; /** Aux Channel number. */ public static final int CHANNEL_AUX = 1; //-------- //-------- Variables //-------- /** Flag to clear the activity on a write operation */ private boolean clearActivityOnWrite; /** Flag to do speed checking */ private boolean doSpeedEnable = true; /** Flag to indicated devices detected on branch during smart-on */ private boolean devicesOnBranch = false; //-------- //-------- Constructors //-------- /** * Create an empty container that is not complete until after a call * to <code>setupContainer</code>. <p> * * This is one of the methods to construct a container. The others are * through creating a OneWireContainer with parameters. * * @see #setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) super.setupContainer() */ public OneWireContainer1F () { super(); clearActivityOnWrite = false; } /** * Create a container with the provided adapter instance * and the address of the iButton or 1-Wire device.<p> * * This is one of the methods to construct a container. The other is * through creating a OneWireContainer with NO parameters. * * @param sourceAdapter adapter instance used to communicate with * this iButton * @param newAddress {@link com.dalsemi.onewire.utils.Address Address} * of this 1-Wire device * * @see #OneWireContainer1F() OneWireContainer1F * @see com.dalsemi.onewire.utils.Address utils.Address */ public OneWireContainer1F (DSPortAdapter sourceAdapter, byte[] newAddress) { super(sourceAdapter, newAddress); clearActivityOnWrite = false; } /** * Create a container with the provided adapter instance * and the address of the iButton or 1-Wire device.<p> * * This is one of the methods to construct a container. The other is * through creating a OneWireContainer with NO parameters. * * @param sourceAdapter adapter instance used to communicate with * this 1-Wire device * @param newAddress {@link com.dalsemi.onewire.utils.Address Address} * of this 1-Wire device * * @see #OneWireContainer1F() OneWireContainer1F * @see com.dalsemi.onewire.utils.Address utils.Address */ public OneWireContainer1F (DSPortAdapter sourceAdapter, long newAddress) { super(sourceAdapter, newAddress); clearActivityOnWrite = false; } /** * Create a container with the provided adapter instance * and the address of the iButton or 1-Wire device.<p> * * This is one of the methods to construct a container. The other is * through creating a OneWireContainer with NO parameters. * * @param sourceAdapter adapter instance used to communicate with * this 1-Wire device * @param newAddress {@link com.dalsemi.onewire.utils.Address Address} * of this 1-Wire device * * @see #OneWireContainer1F() OneWireContainer1F * @see com.dalsemi.onewire.utils.Address utils.Address */ public OneWireContainer1F (DSPortAdapter sourceAdapter, String newAddress) { super(sourceAdapter, newAddress); clearActivityOnWrite = false; } //-------- //-------- Methods //-------- /** * Gets the Dallas Semiconductor part number of the iButton * or 1-Wire Device as a string. For example 'DS1992'. * * @return iButton or 1-Wire device name */ public String getName () { return "DS2409"; } /** * Gets the alternate Dallas Semiconductor part numbers or names. * A 'family' of 1-Wire Network devices may have more than one part number * depending on packaging. There can also be nicknames such as * 'Crypto iButton'. * * @return 1-Wire device alternate names */ public String getAlternateNames () { return "Coupler"; } /** * Gets a short description of the function of this iButton * or 1-Wire Device type. * * @return device description */ public String getDescription () { return "1-Wire Network Coupler with dual addressable " + "switches and a general purpose open drain control " + "output. Provides a common ground for all connected" + "multi-level MicroLan networks. Keeps inactive branches" + "Pulled to 5V."; } /** * 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; } //-------- //-------- Sensor I/O methods //-------- /** * 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'.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -