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

📄 onewirecontainer30.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      else      {         // if internal resistor is used         if(internalResistor)            // 0.625 mV units            return 0.000625d;         else            // external resistor is used            // 15.625 uV units            return .000015625d;      }   }   /**    * Extracts the A/D 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 device    *                  returned from <CODE>readDevice()</CODE>    *    * @return A/D input voltage range    */   public double getADRange (int channel, byte[] state)   {      return 5.0;   //so is this one!   }   //--------   //-------- A/D 'set' Methods   //--------   /**    * Sets the A/D 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 A/D 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 AD alarms");   }   /**    * Sets the A/D 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 A/D 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");   }   /**    * Sets the A/D 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 A/D resolution in volts    * @param state current state of the    *               device returned from <CODE>readDevice()</CODE>    */   public void setADResolution (int channel, double resolution, byte[] state)   {      //airball! no resolutions to set!   }   /**    * Sets the A/D 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 max A/D 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)   {      //yet another airball--YAAB...only one range on this part   }   //--------   //-------- Temperature Feature methods   //--------   /**    * Queries to see if this temperature measuring device has high/low    * trip alarms.    *    * @return <CODE>true</CODE> if has high/low temperature trip alarms    */   public boolean hasTemperatureAlarms ()   {      return false;   }   /**    * Queries to see if this device has selectable temperature resolution.    *    * @return <CODE>true</CODE> if has selectable temperature resolution    */   public boolean hasSelectableTemperatureResolution ()   {      return false;   }   /**    * Queries to get an array of available temperature resolutions in    * degrees C.    *    * @return available temperature resolutions in degrees C    */   public double[] getTemperatureResolutions ()   {      double[] result = new double [1];      result [0] = 0.125;      return result;   }   /**    * Queries to get the high/low temperature alarm resolution in degrees C.    *    * @return high/low temperature alarm resolution in degrees C    *    * @throws OneWireException Device does not support temperature alarms    */   public double getTemperatureAlarmResolution ()      throws OneWireException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * Queries to get the maximum temperature in degrees C.    *    * @return maximum temperature in degrees C    */   public double getMaxTemperature ()   {      return 85.0;   }   /**    * Queries to get the minimum temperature in degrees C.    *    * @return minimum temperature in degrees C    */   public double getMinTemperature ()   {      return -40.0;   }   //--------   //-------- Temperature I/O Methods   //--------   /**    * Performs a temperature conversion.    *    * @param state device state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Could not find device    */   public void doTemperatureConvert (byte[] state)      throws OneWireIOException, OneWireException   {      //for the same reason we don't have to do an AD conversion,      //we don't have to do a temperature conversion--its done      //continuously   }   //--------   //-------- Temperature 'get' Methods   //--------   /**    * 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>doTemperatureConvert()</CODE>    */   public double getTemperature (byte[] state)   {      double temperature;      int    data;      // the MSB is at 24, the LSB at 25 and the format is so that when      // attached, the whole thing must be shifted right 5 (Signed)      data = (state [24] << 8) | (state [25] & 0x00ff);      data = data >> 5;      // that raw measurement is in .125 degree units      temperature = data / 8.0;      return temperature;   }   /**    * Extracts the specified temperature alarm value in degrees C from the    * state data retrieved from the <CODE>readDevice()</CODE> method.    *    * @param alarmType 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 support temerature alarms    */   public double getTemperatureAlarm (int alarmType, byte[] state)      throws OneWireException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * Extracts the current temperature 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.125;   }   //--------   //-------- Temperature 'set' Methods   //--------   /**    * Sets the temperature 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 trip type <CODE>ALARM_HIGH (1)    *               or ALARM_LOW (0)</CODE>    * @param alarmValue high/low temperature trip value in degrees C    * @param state device state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Device does not support temperature alarms    */   public void setTemperatureAlarm (int alarmType, double alarmValue,                                    byte[] state)      throws OneWireException, OneWireIOException   {      throw new OneWireException(         "This device does not have temperature alarms");   }   /**    * Sets the current temperature 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 device    */   public void setTemperatureResolution (double resolution, byte[] state)      throws OneWireException, OneWireIOException   {      //airball, there can be only ONE resolution!   }   //--------   //-------- 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 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.  With the    * DS2760, there are no CRC checks on data.  To ensure the integrity    * of this data, call twice and make sure only fields expected to change    * have changed.  This method returns bytes 0 to 31 of the memory.    * Many applications will not need to worry about the lack of CRC checks.    *    * @return 1-Wire device state    *    * @throws OneWireIOException Error reading data    * @throws OneWireException Could not find device    */   public byte[] readDevice ()      throws OneWireIOException, OneWireException   {      byte[] result = new byte [32];      /* perform the read twice to ensure a good transmission */      doSpeed();      adapter.reset();      if (adapter.select(address))      {         /* do the first read */         adapter.putByte(READ_DATA_COMMAND);         adapter.putByte(0);         adapter.getBlock(result, 0, 32);      }      else         throw new OneWireException("OneWireContainer30-Device not found.");      return result;   }   /**    * Writes 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 state    *    * @throws OneWireIOException Error writting data    * @throws OneWireException Could not find device    */   public void writeDevice (byte[] state)      throws OneWireIOException, OneWireException   {      /* need to write the following bytes:       *   0 Protection register       *   1 Status register       *   7 EEPROM register       *   8 Special feature register       *   16 Accumulated current register MSB       *   17 Accumulated current register LSB       */      //drain this....let's just make everything happen in real time   }}

⌨️ 快捷键说明

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