📄 onewirecontainer29.java
字号:
* * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>true</code> if activity was detected and <code>false</code> if no activity was detected * * @throws OneWireException if this device does not have activity sensing * * @see #hasActivitySensing() * @see #clearActivity() */ public boolean getSensedActivity (int channel, byte[] state) throws OneWireException { byte activity = (byte) (0x01 << channel); return ((state[2] & activity) == activity); } /** * Clears the activity latches the next time possible. For * example, on a DS2406/07, this happens the next time the * status is read with <code>readDevice()</code>. * * @throws OneWireException if this device does not support activity sensing * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #getSensedActivity(int,byte[]) */ public void clearActivity () throws OneWireException { adapter.select(address); byte[] buffer = new byte[9]; buffer[0] = RESET_ACTIVITY_LATCHES; System.arraycopy(FF,0,buffer,1,8); adapter.dataBlock(buffer, 0, 9); if((buffer[1] != (byte) 0xAA) && (buffer[1] != (byte) 0x55)) throw new OneWireException("Sense Activity was not cleared."); } //-------- //-------- Switch 'set' Methods //-------- /** * Sets the latch state of the indicated channel. * The method <code>writeDevice()</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice()</code>. * * @param channel channel to execute this operation, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param latchState <code>true</code> to set the channel latch 'on' * (conducting) and <code>false</code> to set the channel latch 'off' (not * conducting). Note that the actual output when the latch is 'on' * is returned from the <code>isHighSideSwitch()</code> method. * @param doSmart If latchState is 'on'/<code>true</code> then doSmart indicates * if a 'smart on' is to be done. To avoid an exception * check the capabilities of this device using the * <code>hasSmartOn()</code> method. * @param state current state of the device returned from <code>readDevice()</code> * * @see #hasSmartOn() * @see #getLatchState(int,byte[]) * @see com.dalsemi.onewire.container.OneWireSensor#writeDevice(byte[]) */ public void setLatchState (int channel, boolean latchState, boolean doSmart, byte[] state) { byte latch = (byte) (0x01 << channel); if (latchState) state[1] = (byte) (state[1] | latch); else state[1] = (byte) (state[1] & ~latch); } /** * Sets the latch state for all of the channels. * The method <code>writeDevice()</code> must be called to finalize * changes to the device. Note that multiple 'set' methods can * be called before one call to <code>writeDevice()</code>. * * @param set the state to set all of the channels, in the range [0 to (<code>getNumberChannels(byte[])</code> - 1)] * @param state current state of the device returned from <code>readDevice()</code> * * @see #getLatchState(int,byte[]) * @see com.dalsemi.onewire.container.OneWireSensor#writeDevice(byte[]) */ public void setLatchState (byte set, byte[] state) { state[1] = (byte) set; } /** * Retrieves the 1-Wire device sensor state. This state is * returned as a byte array. Pass this byte array to the 'get' * and 'set' methods. If the device state needs to be changed then call * the 'writeDevice' to finalize the changes. * * @return 1-Wire device sensor state * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 byte[] readDevice () throws OneWireIOException, OneWireException { byte[] state = new byte [3]; System.arraycopy(FF,0,state,0,3); map.read(0,false,state,0,3); return state; } /** * Retrieves the 1-Wire device register mask. This register is * returned as a byte array. Pass this byte array to the 'get' * and 'set' methods. If the device register mask needs to be changed then call * the 'writeRegister' to finalize the changes. * * @return 1-Wire device register mask * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 byte[] readRegister () throws OneWireIOException, OneWireException { byte[] register = new byte[3]; search.read(0,false,register,0,3); return register; } /** * Writes the 1-Wire device sensor state that * have been changed by 'set' methods. Only the state registers that * changed are updated. This is done by referencing a field information * appended to the state data. * * @param state 1-Wire device sensor state * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 void writeDevice (byte[] state) throws OneWireIOException, OneWireException { map.write(1,state,1,1); } /** * Writes the 1-Wire device register mask that * have been changed by 'set' methods. * * @param register 1-Wire device sensor state * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 void writeRegister (byte[] register) throws OneWireIOException, OneWireException { search.write(0,register,0,3); } /** * Turns the Reset mode on/off. * * @param set if 'TRUE' the reset mode will be set or 'FALSE' to turn it off. * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 void setResetMode(byte[] register, boolean set) throws OneWireIOException, OneWireException { if(set && ((register[2] & 0x04) == 0x04)) { register[2] = (byte) (register[2] & (byte) 0xFB); } else if((!set) && ((register[2] & (byte) 0x04) == (byte) 0x00)) { register[2] = (byte) (register[2] | (byte) 0x04); } } /** * Retrieves the state of the VCC pin. If the pin is powered 'TRUE' is * returned else 'FALSE' is returned if the pin is grounded. * * @return <code>true</code> if VCC is powered and <code>false</code> if it is * grounded. * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. 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 boolean getVCC(byte[] register) throws OneWireIOException, OneWireException { if((register[2] & (byte) 0x80) == (byte) 0x80) return true; return false; } /** * Checks if the Power On Reset if on and if so clears it. * * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void clearPowerOnReset(byte[] register) { if((register[2] & (byte) 0x08) == (byte) 0x08) { register[2] = (byte) ((byte) register[2] & (byte) 0xF7); } } /** * Checks if the 'or' Condition Search is set and if not sets it. * * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void orConditionalSearch(byte[] register) { if((register[2] & (byte) 0x02) == (byte) 0x02) { register[2] = (byte) ((byte) register[2] & (byte) 0xFD); } } /** * Checks if the 'and' Conditional Search is set and if not sets it. * * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void andConditionalSearch(byte[] register) { if((register[2] & (byte) 0x02) != (byte) 0x02) { register[2] = (byte) ((byte) register[2] | (byte) 0x02); } } /** * Checks if the 'PIO' Conditional Search is set for input and if not sets it. * * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void pioConditionalSearch(byte[] register) { if((register[2] & (byte) 0x01) == (byte) 0x01) { register[2] = (byte) ((byte) register[2] & (byte) 0xFE); } } /** * Checks if the activity latches are set for Conditional Search and if not sets it. * * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void activityConditionalSearch(byte[] register) { if((register[2] & (byte) 0x01) != (byte) 0x01) { register[2] = (byte) ((byte) register[2] | (byte) 0x01); } } /** * Sets the channel passed to the proper state depending on the set parameter for * responding to the Conditional Search. * * @param channel current channel to set * @param set whether to turn the channel on/off for Conditional Search * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void setChannelMask(int channel, boolean set, byte[] register) { byte mask = (byte) (0x01 << channel); if(set) register[0] = (byte) ((byte) register[0] | (byte) mask); else register[0] = (byte) ((byte) register[0] & (byte) ~mask); } /** * Sets the channel passed to the proper state depending on the set parameter for * the correct polarity in the Conditional Search. * * @param channel current channel to set * @param set whether to turn the channel on/off for polarity * Conditional Search * @param register current register for conditional search, which * if returned from <code>readRegister()</code> */ public void setChannelPolarity(int channel, boolean set, byte[] register) { byte polarity = (byte) (0x01 << channel); if(set) register[1] = (byte) ((byte) register[1] | (byte) polarity); else register[1] = (byte) ((byte) register[1] & (byte) ~polarity); } /** * Retrieves the information if the channel is masked for the Conditional Search. * * @param channel current channel to set * @param register current register for conditional search, which * if returned from <code>readRegister()</code> * * @return <code>true</code> if the channel is masked and <code>false</code> other wise. */ public boolean getChannelMask(int channel, byte[] register) { byte mask = (byte) (0x01 << channel); return ((register[0] & mask) == mask); } /** * Retrieves the polarity of the channel for the Conditional Search. * * @param channel current channel to set * @param register current register for conditional search, which * if returned from <code>readRegister()</code> * * @return <code>true</code> if the channel is masked and <code>false</code> other wise. */ public boolean getChannelPolarity(int channel, byte[] register) { byte polarity = (byte) (0x01 << channel); return ((register[1] & polarity) == polarity); } /** * Initialize the memory banks and data associated with each. */ private void initmem() { // Memory map registers map = new MemoryBankEEPROMstatus(this); map.bankDescription = "Memory mapped register of pin logic state, port output " + "latch logic state and activity latch logic state."; map.startPhysicalAddress = 136; map.size = 3; map.readOnly = true; // Conditional Search search = new MemoryBankEEPROMstatus(this); search.bankDescription = "Conditional search bit mask, polarity bit mask and " + "control register."; search.startPhysicalAddress = 139; search.size = 3; search.readWrite = true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -