netadapter.java

来自「这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统」· Java 代码 · 共 2,064 行 · 第 1/5 页

JAVA
2,064
字号
    * <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 boolean canProgram ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send beginExclusive command            conn.output.writeByte(CMD_CANPROGRAM);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // next parameter should be the return from beginExclusive            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   /**    * Returns whether the adapter can physically support strong 5 volt power    * mode.    *    * @return  <code>true</code> if this port adapter can do strong 5 volt    * mode, <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 boolean canDeliverPower ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send beginExclusive command            conn.output.writeByte(CMD_CANDELIVERPOWER);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // next parameter should be the return from beginExclusive            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   /**    * Returns whether the adapter can physically support "smart" strong 5    * volt power mode.  "smart" power delivery is the ability to deliver    * power until it is no longer needed.  The current drop it detected    * and power delivery is stopped.    *    * @return  <code>true</code> if this port adapter can do "smart" strong    * 5 volt mode, <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 boolean canDeliverSmartPower ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send beginExclusive command            conn.output.writeByte(CMD_CANDELIVERSMARTPOWER);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // next parameter should be the return from beginExclusive            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   /**    * Returns whether adapter can physically support 0 volt 'break' mode.    *    * @return  <code>true</code> if this port adapter can do break,    * <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 boolean canBreak ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send beginExclusive command            conn.output.writeByte(CMD_CANBREAK);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // next parameter should be the return from beginExclusive            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   //--------   //-------- Finding iButton/1-Wire device options   //--------   /**    * Returns <code>true</code> if the first iButton or 1-Wire device    * is found on the 1-Wire Network.    * If no devices are found, then <code>false</code> will be returned.    *    * @return  <code>true</code> if an iButton or 1-Wire device is found.    *    * @throws OneWireIOException on a 1-Wire communication error    * @throws OneWireException on a setup error with the 1-Wire adapter    */   public boolean findFirstDevice ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send findFirstDevice command            conn.output.writeByte(CMD_FINDFIRSTDEVICE);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // return boolean from findFirstDevice            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   /**    * Returns <code>true</code> if the next iButton or 1-Wire device    * is found. The previous 1-Wire device found is used    * as a starting point in the search.  If no more devices are found    * then <code>false</code> will be returned.    *    * @return  <code>true</code> if an iButton or 1-Wire device is found.    *    * @throws OneWireIOException on a 1-Wire communication error    * @throws OneWireException on a setup error with the 1-Wire adapter    */   public boolean findNextDevice ()      throws OneWireIOException, OneWireException   {      try      {         synchronized(conn)         {            // send findNextDevice command            conn.output.writeByte(CMD_FINDNEXTDEVICE);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // return boolean from findNextDevice            return conn.input.readBoolean();         }      }      catch(IOException ioe)      {         throw new OneWireException(COMM_FAILED + ioe.getMessage());      }   }   /**    * Copies the 'current' 1-Wire device address being used by the adapter into    * the array.  This address is the last iButton or 1-Wire device found    * in a search (findNextDevice()...).    * This method copies into a user generated array to allow the    * reuse of the buffer.  When searching many iButtons on the one    * wire network, this will reduce the memory burn rate.    *    * @param  address An array to be filled with the current iButton address.    * @see    Address    */   public void getAddress (byte[] address)   {      try      {         synchronized(conn)         {            // send getAddress command            conn.output.writeByte(CMD_GETADDRESS);            conn.output.flush();            // check return value for success            checkReturnValue(conn);            // get the address            conn.input.read(address, 0, 8);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Sets the 1-Wire Network search to find only iButtons and 1-Wire    * devices that are in an 'Alarm' state that signals a need for    * attention.  Not all iButton types    * have this feature.  Some that do: DS1994, DS1920, DS2407.    * This selective searching can be canceled with the    * 'setSearchAllDevices()' method.    *    * @see #setNoResetSearch    */   public void setSearchOnlyAlarmingDevices ()   {      try      {         synchronized(conn)         {            // send setSearchOnlyAlarmingDevices command            conn.output.writeByte(CMD_SETSEARCHONLYALARMINGDEVICES);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Sets the 1-Wire Network search to not perform a 1-Wire    * reset before a search.  This feature is chiefly used with    * the DS2409 1-Wire coupler.    * The normal reset before each search can be restored with the    * 'setSearchAllDevices()' method.    */   public void setNoResetSearch ()   {      try      {         synchronized(conn)         {            // send setNoResetSearch command            conn.output.writeByte(CMD_SETNORESETSEARCH);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Sets the 1-Wire Network search to find all iButtons and 1-Wire    * devices whether they are in an 'Alarm' state or not and    * restores the default setting of providing a 1-Wire reset    * command before each search. (see setNoResetSearch() method).    *    * @see #setNoResetSearch    */   public void setSearchAllDevices ()   {      try      {         synchronized(conn)         {            // send setSearchAllDevices command            conn.output.writeByte(CMD_SETSEARCHALLDEVICES);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Removes any selectivity during a search for iButtons or 1-Wire devices    * by family type.  The unique address for each iButton and 1-Wire device    * contains a family descriptor that indicates the capabilities of the    * device.    * @see    #targetFamily    * @see    #targetFamily(byte[])    * @see    #excludeFamily    * @see    #excludeFamily(byte[])    */   public void targetAllFamilies ()   {      try      {         synchronized(conn)         {            // send targetAllFamilies command            conn.output.writeByte(CMD_TARGETALLFAMILIES);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Takes an integer to selectively search for this desired family type.    * If this method is used, then no devices of other families will be    * found by any of the search methods.    *    * @param  family   the code of the family type to target for searches    * @see    Address    * @see    #targetAllFamilies    */   public void targetFamily (int family)   {      try      {         synchronized(conn)         {            // send targetFamily command            conn.output.writeByte(CMD_TARGETFAMILY);            conn.output.writeInt(1);            conn.output.writeByte((byte)family);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**    * Takes an array of bytes to use for selectively searching for acceptable    * family codes.  If used, only devices with family codes in this array    * will be found by any of the search methods.    *    * @param  family  array of the family types to target for searches    * @see    Address    * @see    #targetAllFamilies    */   public void targetFamily (byte family [])   {      try      {         synchronized(conn)         {            // send targetFamily command            conn.output.writeByte(CMD_TARGETFAMILY);            conn.output.writeInt(family.length);            conn.output.write(family, 0, family.length);            conn.output.flush();            // check return value for success            checkReturnValue(conn);         }      }      catch(Exception e)      { /* drain */ }   }   /**

⌨️ 快捷键说明

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