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

📄 onewirecontainer26.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      writePage(7, data, 0);   }   /**    * Set the value of the DCA.    *    * @param dcaValue new DCA value    *    * @throws OneWireIOException Error writing data    * @throws OneWireException Could not find part    * @throws IllegalArgumentException Bad parameters passed    */   public void setDCA (int dcaValue)      throws OneWireIOException, OneWireException, IllegalArgumentException   {      byte[] data = readPage(7);      data [6] = ( byte ) (dcaValue & 0x00ff);      data [7] = ( byte ) ((dcaValue & 0xff00) >>> 8);      writePage(7, data, 0);   }   /**    * This method extracts the Clock Value in milliseconds from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param state device state    *    * @return time in milliseconds that have    * occured since 1970    */   public long getDisconnectTime (byte[] state)   {      return getTime(state, 16) * 1000;   }   /**    * This method extracts the Clock Value in milliseconds from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param state device state    *    * @return time in milliseconds that have    * occured since 1970    */   public long getEndOfChargeTime (byte[] state)   {      return getTime(state, 20) * 1000;   }   //actually could be called byteArrayToLong, only used in time functions   private long getTime (byte[] state, int start)   {      long time = (state [start] & 0x0ff)                  | ((state [start + 1] & 0x0ff) << 8)                  | ((state [start + 2] & 0x0ff) << 16)                  | ((state [start + 3] & 0x0ff) << 24);      return time & 0x0ffffffff;   }   //////////////////////////////////////////////////////////////////////////////   //   //      INTERFACE METHODS!!!!!!!!   //   //////////////////////////////////////////////////////////////////////////////   /**     * Query to get the number of channels supported by this A/D.     * Channel specific methods will use a channel number specified     * by an integer from [0 to (getNumberChannels() - 1)].     *     * @return number of channels     */   public int getNumberADChannels ()   {      return 3;   //has VDD, VAD channel  (battery, gen purpose)                  // and it has a Vsense channel for current sensing   }   /**    * Query to see if this A/D measuring device has high/low    * alarms.    *    * @return true if has high/low trips    */   public boolean hasADAlarms ()   {      return false;   }   /**    * Query to get an array of available ranges for the specified    * A/D channel.    *    * @param channel  channel in the range    *                  [0 to (getNumberChannels() - 1)]    *    * @return available ranges    */   public double[] getADRanges (int channel)   {      double[] result = new double [1];      if(channel==CHANNEL_VSENSE)         result [0] = .250;      else         result [0] = 10.23;      /* for VAD, not entirely true--this should be         2 * VDD.  If you hook up VDD to the         one-wire in series with a diode and then         hang a .1 microF capacitor off the line to ground,         you can get about 9.5 for the high end accurately                       ----------------------------------                       |             *****************  |         One-Wire------- DIODE-------*VDD     ONEWIRE*---                                 |   *               *                                 |   *        GROUND *---                                 C   *               *  |                                 |   *    2438       *  |                                gnd  *               *  |                                 |   *****************  |                                 |----------------------|       */      return result;   }   /**    * Query to get an array of available resolutions based    * on the specified range on the specified A/D channel.    *    * @param channel channel in the range    *                  [0 to (getNumberChannels() - 1)]    * @param range A/D range    *    * @return available resolutions    */   public double[] getADResolutions (int channel, double range)   {      double[] result = new double [1];      if(channel == CHANNEL_VSENSE)         result [0] = 0.2441;      else         result [0] = 0.01;   //10 mV      return result;   }   /**    * Query to see if this A/D supports doing multiple voltage    * conversions at the same time.    *    * @return true if device can do multi-channel voltage reads    */   public boolean canADMultiChannelRead ()   {      return false;   }   //--------   //-------- A/D IO Methods   //--------   /**    * This method is used to perform voltage conversion on all specified    * channels.  The method 'getVoltage()' can be used to read the result    * of the conversion.    *    * @param channel channel in the range    *                 <CODE> [0 to (getNumberChannels() - 1)]</CODE>    * @param state  current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @throws OneWireIOException Error writing data    * @throws OneWireException Could not find part    */   public void doADConvert (int channel, byte[] state)      throws OneWireIOException, OneWireException   {      if(channel == CHANNEL_VSENSE)      {         if((state[0]&IAD_FLAG) == 0)         {            // enable the current sense channel            setFlag(IAD_FLAG, true);            state[0] |= IAD_FLAG;            try            {               // updates once every 27.6 milliseconds               Thread.sleep(30);            }            catch (InterruptedException e){}         }         byte[] data = readPage(0);         // update the state         System.arraycopy(data, 5, state, 5, 2);      }      else      {         setFlag(AD_FLAG, channel == CHANNEL_VDD);         // first perform the conversion         if (doSpeedEnable)            doSpeed();         if (adapter.select(address))         {            adapter.putByte(CONVERT_VOLTAGE_COMMAND);            try            {               Thread.sleep(4);            }            catch (InterruptedException e){}            byte[] data = readPage(0);            //let's update state with this info            System.arraycopy(data, 0, state, 0, 8);            // save off the voltage in our state's holdindg area            state [24 + channel * 2]     = data [4];            state [24 + channel * 2 + 1] = data [3];         }         else            throw new OneWireException("OneWireContainer26-Device not found.");      }   }   /**    * This method is used to perform voltage conversion on all specified    * channels.  The method <CODE>getVoltage()</CODE> can be used to read the result    * of the conversion. This A/D must support multi-channel read    * <CODE>canMultiChannelRead()</CODE> if there are more then 1 channel is specified.    *    * @param doConvert  channels    *                    to perform conversion on    * @param state  current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @throws OneWireIOException Error writing data    * @throws OneWireException Could not find part    */   public void doADConvert (boolean[] doConvert, byte[] state)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This device cannot do multi-channel reads");   }   /**    * This method is used to read the voltage values.  Must    * be used after a <CODE>doADConvert()</CODE> method call.  Also must    * include the last valid state from the <CODE>readDevice()</CODE> method    * and this A/D must support multi-channel read <CODE>canMultiChannelRead()</CODE>    * if there are more then 1 channel.    *    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @return voltage values for all channels    *    * @throws OneWireIOException Error reading data    * @throws OneWireException Could not find part    */   public double[] getADVoltage (byte[] state)      throws OneWireIOException, OneWireException   {      throw new OneWireException("This device cannot do multi-channel reads");   }   /**    * This method is used to read a channels voltage value.  Must    * be used after a <CODE>doADConvert()</CODE> method call.  Also must    * include the last valid state from the <CODE>readDevice()</CODE> method.    * Note, if more then one channel is to be read then it is more    * efficient to use the <CODE>getVoltage()</CODE> method that returns all    * channel values.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @return   voltage value for the specified    *                  channel    *    * @throws OneWireIOException Error reading data    * @throws OneWireException Could not find part    */   public double getADVoltage (int channel, byte[] state)      throws OneWireIOException, OneWireException   {      double result = 0;      if(channel == CHANNEL_VSENSE)         result = ((state [6] << 8) | (state [5] & 0x0ff))/4096d;      else         result = (((state [24 + channel*2] << 8) & 0x00300) |                    (state [24 + channel*2 + 1] & 0x0ff))                   / 100.0d;      return result;   }   //--------   //-------- A/D 'get' Methods   //--------   /**    * This method is used to extract the alarm voltage value of the    * specified channel from the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param alarmType desired alarm, <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @return alarm_value in volts    *    * @throws OneWireException Device does not support A/D alarms    */   public double getADAlarm (int channel, int alarmType, byte[] state)      throws OneWireException   {      throw new OneWireException("This device does not have A/D alarms");   }   /**    * This method is used to extract the alarm enable value of the    * specified channel from the provided state buffer.  The state    * buffer is retrieved from the <CODE>readDevice()</CODE> method.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param alarmType desired alarm, <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param state current state of the state    *               returned from <CODE>readDevice()</CODE>    *    * @return true if specified alarm is enabled    *    * @throws OneWireException Device does not support A/D alarms    */   public boolean getADAlarmEnable (int channel, int alarmType, byte[] state)      throws OneWireException   {      throw new OneWireException("This device does not have A/D alarms");   }   /**    * This method is used to check the alarm event value of the    * specified channel from the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param alarmType desired alarm, <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param state current state of the state                    returned from <CODE>readDevice()</CODE>    *    * @return true if specified alarm occurred    *    * @throws OneWireException Device does not support A/D alarms    */   public boolean hasADAlarmed (int channel, int alarmType, byte[] state)      throws OneWireException   {      throw new OneWireException("This device does not have A/D alarms");   }   /**    * This method is used to extract the conversion resolution of the    * specified channel from the provided state buffer expressed in    * volts.  The state is retrieved from the    * <CODE>readDevice()</CODE> method.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param state current state of the state    *               returned from <CODE>readDevice()</CODE>    *    * @return resolution of channel in volts    */   public double getADResolution (int channel, byte[] state)   {      //this is easy, its always 0.01 V = 10 mV      return 0.01;   }   /**    * This method is used to extract the input voltage range of the    * specified channel from the provided state buffer.  The state    * buffer is retrieved from the <CODE>readDevice()</CODE> method.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param state current state of the state    *                  returned from <CODE>readDevice()</CODE>

⌨️ 快捷键说明

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