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

📄 tmexadapter.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------- * 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.adapter;// importsimport java.util.Enumeration;import com.dalsemi.onewire.container.OneWireContainer;import com.dalsemi.onewire.*;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.OneWireException;import java.util.Vector;import java.lang.ClassNotFoundException;import java.io.File;/** * The DSPortAdapter class for all TMEX native adapters (Win32). * * Instances of valid DSPortAdapter's are retrieved from methods in * {@link com.dalsemi.onewire.OneWireAccessProvider OneWireAccessProvider}. *  * <P>The TMEXAdapter methods can be organized into the following categories: </P> * <UL> *   <LI> <B> Information </B> *     <UL> *       <LI> {@link #getAdapterName() getAdapterName} *       <LI> {@link #getPortTypeDescription() getPortTypeDescription} *       <LI> {@link #getClassVersion() getClassVersion} *       <LI> {@link #adapterDetected() adapterDetected} *       <LI> {@link #getAdapterVersion() getAdapterVersion} *       <LI> {@link #getAdapterAddress() getAdapterAddress} *     </UL> *   <LI> <B> Port Selection </B> *     <UL> *       <LI> {@link #getPortNames() getPortNames} *       <LI> {@link #selectPort(String) selectPort} *       <LI> {@link #getPortName() getPortName} *       <LI> {@link #freePort() freePort} *     </UL> *   <LI> <B> Adapter Capabilities </B> *     <UL> *       <LI> {@link #canOverdrive() canOverdrive} *       <LI> {@link #canHyperdrive() canHyperdrive} *       <LI> {@link #canFlex() canFlex} *       <LI> {@link #canProgram() canProgram} *       <LI> {@link #canDeliverPower() canDeliverPower} *       <LI> {@link #canDeliverSmartPower() canDeliverSmartPower} *       <LI> {@link #canBreak() canBreak} *     </UL> *   <LI> <B> 1-Wire Network Semaphore </B> *     <UL> *       <LI> {@link #beginExclusive(boolean) beginExclusive} *       <LI> {@link #endExclusive() endExclusive} *     </UL> *   <LI> <B> 1-Wire Device Discovery </B> *     <UL> *       <LI> Selective Search Options *         <UL> *          <LI> {@link #targetAllFamilies() targetAllFamilies} *          <LI> {@link #targetFamily(int) targetFamily(int)} *          <LI> {@link #targetFamily(byte[]) targetFamily(byte[])} *          <LI> {@link #excludeFamily(int) excludeFamily(int)} *          <LI> {@link #excludeFamily(byte[]) excludeFamily(byte[])} *          <LI> {@link #setSearchOnlyAlarmingDevices() setSearchOnlyAlarmingDevices} *          <LI> {@link #setNoResetSearch() setNoResetSearch} *          <LI> {@link #setSearchAllDevices() setSearchAllDevices} *         </UL> *       <LI> Search With Automatic 1-Wire Container creation *         <UL> *          <LI> {@link #getAllDeviceContainers() getAllDeviceContainers} *          <LI> {@link #getFirstDeviceContainer() getFirstDeviceContainer} *          <LI> {@link #getNextDeviceContainer() getNextDeviceContainer} *         </UL> *       <LI> Search With NO 1-Wire Container creation *         <UL> *          <LI> {@link #findFirstDevice() findFirstDevice} *          <LI> {@link #findNextDevice() findNextDevice} *          <LI> {@link #getAddress(byte[]) getAddress(byte[])} *          <LI> {@link #getAddressAsLong() getAddressAsLong} *          <LI> {@link #getAddressAsString() getAddressAsString} *         </UL> *       <LI> Manual 1-Wire Container creation *         <UL> *          <LI> {@link #getDeviceContainer(byte[]) getDeviceContainer(byte[])} *          <LI> {@link #getDeviceContainer(long) getDeviceContainer(long)} *          <LI> {@link #getDeviceContainer(String) getDeviceContainer(String)} *          <LI> {@link #getDeviceContainer() getDeviceContainer()} *         </UL> *     </UL> *   <LI> <B> 1-Wire Network low level access (usually not called directly) </B> *     <UL> *       <LI> Device Selection and Presence Detect *         <UL> *          <LI> {@link #isPresent(byte[]) isPresent(byte[])} *          <LI> {@link #isPresent(long) isPresent(long)} *          <LI> {@link #isPresent(String) isPresent(String)} *          <LI> {@link #isAlarming(byte[]) isAlarming(byte[])} *          <LI> {@link #isAlarming(long) isAlarming(long)} *          <LI> {@link #isAlarming(String) isAlarming(String)} *          <LI> {@link #select(byte[]) select(byte[])} *          <LI> {@link #select(long) select(long)} *          <LI> {@link #select(String) select(String)} *         </UL> *       <LI> Raw 1-Wire IO *         <UL> *          <LI> {@link #reset() reset} *          <LI> {@link #putBit(boolean) putBit} *          <LI> {@link #getBit() getBit} *          <LI> {@link #putByte(int) putByte} *          <LI> {@link #getByte() getByte} *          <LI> {@link #getBlock(int) getBlock(int)} *          <LI> {@link #getBlock(byte[], int) getBlock(byte[], int)} *          <LI> {@link #getBlock(byte[], int, int) getBlock(byte[], int, int)} *          <LI> {@link #dataBlock(byte[], int, int) dataBlock(byte[], int, int)} *         </UL> *       <LI> 1-Wire Speed and Power Selection *         <UL> *          <LI> {@link #setPowerDuration(int) setPowerDuration} *          <LI> {@link #startPowerDelivery(int) startPowerDelivery} *          <LI> {@link #setProgramPulseDuration(int) setProgramPulseDuration} *          <LI> {@link #startProgramPulse(int) startProgramPulse} *          <LI> {@link #startBreak() startBreak} *          <LI> {@link #setPowerNormal() setPowerNormal} *          <LI> {@link #setSpeed(int) setSpeed} *          <LI> {@link #getSpeed() getSpeed} *         </UL> *     </UL> *   <LI> <B> Advanced </B> *     <UL> *        <LI> {@link #registerOneWireContainerClass(int, Class) registerOneWireContainerClass} *     </UL> *  </UL> * * @see com.dalsemi.onewire.OneWireAccessProvider * @see com.dalsemi.onewire.container.OneWireContainer * * @version    0.01, 20 March 2001 * @author     DS */public class TMEXAdapter   extends DSPortAdapter{   //--------   //-------- Variables   //--------   /** flag to intidate if native driver got loaded */   private static boolean driverLoaded = false;   /** TMEX port type number (0-15) */   protected int portType;   /** Current 1-Wire Network Address */   protected byte[] RomDta = new byte [8];   /** Flag to indicate next search will look only for alarming devices */   private boolean doAlarmSearch = false;   /** Flag to indicate next search will be a 'first' */   private boolean resetSearch = true;   /** Flag to indicate next search will not be preceeded by a 1-Wire reset */   private boolean skipResetOnSearch = false;   //--------   //-------- Constructors/Destructor   //--------   /**    * Constructs a default adapter    *    * @throws ClassNotFoundException    */   public TMEXAdapter ()      throws ClassNotFoundException   {      // check if native driver got loaded      if (!driverLoaded)         throw new ClassNotFoundException(            "native driver 'ibtmjava.dll' not loaded");      // set default port type      portType = getDefaultTypeNumber();      // attempt to set the portType, will throw exception if does not exist      if (!setPortType_Native(portType))         throw new ClassNotFoundException("TMEX adapter type does not exist");   }   /**    * Constructs with a specified port type    *    *    * @param newPortType    * @throws ClassNotFoundException    */   public TMEXAdapter (int newPortType)      throws ClassNotFoundException   {      // set default port type      portType = newPortType;      // check if native driver got loaded      if (!driverLoaded)         throw new ClassNotFoundException(            "native driver 'ibtmjava.dll' not loaded");      // attempt to set the portType, will throw exception if does not exist      if (!setPortType_Native(portType))         throw new ClassNotFoundException("TMEX adapter type does not exist");   }   /**    * Finalize to Cleanup native    */   protected void finalize ()   {      cleanup_Native();   }   //--------   //-------- Methods   //--------   /**    * Retrieve the name of the port adapter as a string.  The 'Adapter'    * is a device that connects to a 'port' that allows one to    * communicate with an iButton or other 1-Wire device.  As example    * of this is 'DS9097U'.    *    * @return  <code>String</code> representation of the port adapter.    */   public native String getAdapterName ();   /**    * Retrieve a description of the port required by this port adapter.    * An example of a 'Port' would 'serial communication port'.    *    * @return  <code>String</code> description of the port type required.    */   public native String getPortTypeDescription ();   /**    * Retrieve a version string for this class.    *    * @return  version string    */   public String getClassVersion ()   {      return new String("0.01, native: " + getVersion_Native());   }   //--------   //-------- Port Selection   //--------   /**    * Retrieve a list of the platform appropriate port names for this    * adapter.  A port must be selected with the method 'selectPort'    * before any other communication methods can be used.  Using    * a communcation method before 'selectPort' will result in    * a <code>OneWireException</code> exception.    *    * @return  enumeration of type <code>String</code> that contains the port    * names    */   public Enumeration getPortNames ()   {      Vector portVector = new Vector();      String header     = getPortNameHeader_Native();      for (int i = 0; i < 16; i++)         portVector.addElement(new String(header + Integer.toString(i)));      return (portVector.elements());   }   /**    * Specify a platform appropriate port name for this adapter.  Note that    * even though the port has been selected, it's ownership may be relinquished    * if it is not currently held in a 'exclusive' block.  This class will then    * try to re-aquire the port when needed.  If the port cannot be re-aquired    * ehen the exception <code>PortInUseException</code> will be thrown.    *    * @param  portName  name of the target port, retrieved from    * getPortNames()    *    * @return <code>true</code> if the port was aquired, <code>false</code>    * if the port is not available.    *    * @throws OneWireIOException If port does not exist, or unable to communicate with port.    * @throws OneWireException If port does not exist    */   public native boolean selectPort (String portName)      throws OneWireIOException, OneWireException;   /**    * Free ownership of the selected port if it is currently owned back    * to the system.  This should only be called if the recently    * selected port does not have an adapter or at the end of    * your application's use of the port.    *    * @throws OneWireException If port does not exist    */   public native void freePort ()      throws OneWireException;   /**    * Retrieve the name of the selected port as a <code>String</code>.    *    * @return  <code>String</code> of selected port    *    * @throws OneWireException if valid port not yet selected    */   public native String getPortName ()      throws OneWireException;   //--------   //-------- Adapter detection    //--------   /**    * Detect adapter presence on the selected port.    *    * @return  <code>true</code> if the adapter is confirmed to be connected to    * the selected port, <code>false</code> if the adapter is not connected.    *    * @throws OneWireIOException    * @throws OneWireException    */   public native boolean adapterDetected ()      throws OneWireIOException, OneWireException;   /**    * Retrieve the version of the adapter.    *    * @return  <code>String</code> of the adapter version.  It will return    * "<na>" if the adapter version is not or cannot be known.    *    * @throws OneWireIOException on a 1-Wire communication error such as     *         no device present.  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 native String getAdapterVersion ()      throws OneWireIOException, OneWireException;   /**    * Retrieve the address of the adapter if it has one.    *    * @return  <code>String</code> of the adapter address.  It will return "<na>" if    * the adapter does not have an address.  The address is a string representation of an    * 1-Wire address.    *    * @throws OneWireIOException on a 1-Wire communication error such as     *         no device present.  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    * @see    Address    */   public String getAdapterAddress ()      throws OneWireIOException, OneWireException   {      return "<na>";   //??? implement later   }   //--------   //-------- Adapter features    //--------   /* The following interogative methods are provided so that client code    * can react selectively to underlying states without generating an    * exception.    */   /**    * Returns whether adapter can physically support overdrive mode.    *    * @return  <code>true</code> if this port adapter can do OverDrive,    * <code>false</code> otherwise.    *    * @throws OneWireIOException on a 1-Wire communication error with the adapter    * @throws OneWireException on a setup error with the 1-Wire     *         adapter    */   public native boolean canOverdrive ()      throws OneWireIOException, OneWireException;   /**    * Returns whether the adapter can physically support hyperdrive mode.    *    * @return  <code>true</code> if this port adapter can do HyperDrive,    * <code>false</code> otherwise.    *    * @throws OneWireIOException on a 1-Wire communication error with the adapter    * @throws OneWireException on a setup error with the 1-Wire 

⌨️ 快捷键说明

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