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

📄 onewirecontainer26.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    *    * @return input voltage range    */   public double getADRange (int channel, byte[] state)   {      if(channel==CHANNEL_VSENSE)         return .250;      else         return 10.23;   }   //--------   //-------- A/D 'set' Methods   //--------   /**    * This method is used to set the alarm voltage value of the    * specified channel in the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    * The method <CODE>writeDevice()</CODE> must be called to finalize these    * changes to the device.  Note that multiple 'set' methods can    * be called before one call to <CODE>writeDevice()</CODE>.    *    * @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 alarm  alarm value (will be reduced to 8 bit resolution)    * @param state  current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @throws OneWireException Device does not support A/D alarms    */   public void setADAlarm (int channel, int alarmType, double alarm,                           byte[] state)      throws OneWireException   {      throw new OneWireException("This device does not have A/D alarms");   }   /**    * This method is used to set the alarm enable value of the    * specified channel in the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    * The method <CODE>writeDevice()</CODE> must be called to finalize these    * changes to the device.  Note that multiple 'set' methods can    * be called before one call to <CODE>writeDevice()</CODE>.    *    * @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 alarmEnable alarm enable value    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    *    * @throws OneWireException Device does not support A/D alarms    */   public void setADAlarmEnable (int channel, int alarmType,                                 boolean alarmEnable, byte[] state)      throws OneWireException   {      throw new OneWireException("This device does not have AD alarms");   }   /**    * This method is used to set the conversion resolution value for the    * specified channel in the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    * The method <CODE>writeDevice()</CODE> must be called to finalize these    * changes to the device.  Note that multiple 'set' methods can    * be called before one call to <CODE>writeDevice()</CODE>.    *    * @param channel  channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param resolution resolution to use in volts    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    */   public void setADResolution (int channel, double resolution, byte[] state)   {      //but you can't select the resolution for this part!!!!      //just make it an airball   }   /**    * This method is used to set the input range for the    * specified channel in the provided state buffer.  The    * state buffer is retrieved from the <CODE>readDevice()</CODE> method.    * The method <CODE>writeDevice()</CODE> must be called to finalize these    * changes to the device.  Note that multiple 'set' methods can    * be called before one call to <CODE>writeDevice()</CODE>.    *    * @param channel channel in the range    *                  <CODE>[0 to (getNumberChannels() - 1)]</CODE>    * @param range maximum volt range, use    *                <CODE>getRanges()</CODE> method to get available ranges    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    */   public void setADRange (int channel, double range, byte[] state)   {      //you can't change the ranges here without changing VDD!!!      //just make this function call an airball   }   /**    * This method retrieves the 1-Wire device sensor state.  This state is    * returned as a byte array.  Pass this byte array to the static query    * and set methods.  If the device state needs to be changed then call    * the <CODE>writeDevice()</CODE> to finalize the one or more change.    *    * @return 1-Wire device's state    *    * @throws OneWireIOException Error reading data    * @throws OneWireException Could not find part    */   public byte[] readDevice ()      throws OneWireIOException, OneWireException   {      //should return the first three pages      //and then 6 extra bytes, 2 for channel 1 voltage and      //2 for channel 2 voltage      byte[] state = new byte [28];      for (int i = 0; i < 3; i++)      {         byte[] pg = readPage(i);         System.arraycopy(pg, 0, state, i * 8, 8);      }      //the last four bytes are used this way...      //the current voltage reading is kept in page 0,      //but if a new voltage reading is asked for we move it to the      //end so it can be there in case it is asked for again,      //so we kind of weasel around this whole ADcontainer thing      /* here's a little map           byte[24] VDD high byte           byte[25] VDD low byte           byte[26] VAD high byte           byte[27] VAD low byte      */      return state;   }   /**    * This method write the 1-Wire device sensor state that    * have been changed by the 'set' methods.  It knows which registers have    * changed by looking at the bitmap fields appended to the state    * data.    *    * @param  state device's state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Could not find part    */   public void writeDevice (byte[] state)      throws OneWireIOException, OneWireException   {      writePage(0, state, 0);      writePage(1, state, 8);   }   //--------   //-------- Temperature Feature methods   //--------   /**    * Query to see if this temperature measuring device has high/low    * trip alarms.    *    * @return true if has high/low trip alarms    */   public boolean hasTemperatureAlarms ()   {      return false;   }   /**    * Query to see if this device has selectable resolution.    *    * @return true if device has selectable resolution    */   public boolean hasSelectableTemperatureResolution ()   {      return false;   }   /**    * Query to get an array of available resolutions in degrees C.    *    * @return available resolutions in degrees C    */   public double[] getTemperatureResolutions ()   {      double[] result = new double [1];      result [0] = 0.03125;      return result;   }   /**    * Query to get the high/low resolution in degrees C.    *    * @return high/low resolution resolution in degrees C    *    * @throws OneWireException Device does not have temperature alarms    */   public double getTemperatureAlarmResolution ()      throws OneWireException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * Query to get the maximum temperature in degrees C.    *    * @return maximum temperature in degrees C    */   public double getMaxTemperature ()   {      return 125.0;   }   /**    * Query to get the minimum temperature in degrees C.    *    * @return minimum temperature in degrees C    */   public double getMinTemperature ()   {      return -55.0;   }   //--------   //-------- Temperature I/O Methods   //--------   /**    * Perform an temperature conversion.  Use this state information    * to calculate the conversion time.    *    * @param state device state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Could not find part    */   public void doTemperatureConvert (byte[] state)      throws OneWireIOException, OneWireException   {      byte[] data;   // hold page      if (doSpeedEnable)         doSpeed();      if (adapter.select(address))      {         // perform the temperature conversion         adapter.putByte(CONVERT_TEMP_COMMAND);         try         {            Thread.sleep(10);         }         catch (InterruptedException Ie){}         data      = readPage(0);         state [2] = data [2];         state [1] = data [1];      }      else         throw new OneWireException("OneWireContainer26-Device not found.");   }   //--------   //-------- Temperature 'get' Methods   //--------   /**    * This method extracts the Temperature Value in degrees C from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param state device state    *    * @return temperature in degrees C from the last <CODE>doTemperature()</CODE>    */   public double getTemperature (byte[] state)   {      double temp = (( short ) ((state [2] << 8) | (state [1] & 0x0ff)) >> 3)                    * 0.03125;      return temp;   }   /**    * This method extracts the specified Alarm value in degrees C from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param alarmType alarm trip type <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param state device state    *    * @return alarm trip temperature in degrees C    *    * @throws OneWireException Device does not have temperature alarms    */   public double getTemperatureAlarm (int alarmType, byte[] state)      throws OneWireException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * This method extracts the current resolution in degrees C from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param state device state    *    * @return temperature resolution in degrees C    */   public double getTemperatureResolution (byte[] state)   {      return 0.03125;   }   //--------   //-------- Temperature 'set' Methods   //--------   /**    * This method sets the alarm value in degrees C in the    * provided state data.  Use the method <CODE>writeDevice()</CODE> with    * this data to finalize the change to the device.    *    * @param alarmType alarm type <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param alarmValue trip value in degrees C    * @param state device state    *    * @throws OneWireException Device does not have temperature alarms    */   public void setTemperatureAlarm (int alarmType, double alarmValue,                                    byte[] state)      throws OneWireException, OneWireIOException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * This method sets the current resolution in degrees C in the    * provided state data.   Use the method <CODE>writeDevice()</CODE> with    * this data to finalize the change to the device.    *    * @param resolution temperature resolution in degrees C    * @param state device state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Could not find part    */   public void setTemperatureResolution (double resolution, byte[] state)      throws OneWireException, OneWireIOException   {      //airball, only one resolution!!!   }   //--------   //-------- Clock Feature methods   //--------   /**    * Query to see if the clock has an alarm feature.    *    * @return true if real-time-clock has an alarm    */   public boolean hasClockAlarm ()   {      return false;   }   /**    * Query to see if the clock can be disabled.  See    * the methods <CODE>isClockRunning()</CODE> and <CODE>setClockRunEnable()</CODE>.    *    * @return true if the clock can be enabled and    * disabled    */   public boolean canDisableClock ()   {      return false;   }   /**    * Query to get the clock resolution in milliseconds    *    * @return clock resolution in milliseconds.    */   public long getClockResolution ()   {

⌨️ 快捷键说明

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