📄 onewirecontainer12.java
字号:
* Creates a new <code>OneWireContainer</code> for communication with a DS2406/2407. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2406/2407 * * @see #OneWireContainer12() * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer12(DSPortAdapter,long) * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer12(DSPortAdapter,String) */ public OneWireContainer12 (DSPortAdapter sourceAdapter, byte[] newAddress) { super(sourceAdapter, newAddress); } /** * Creates a new <code>OneWireContainer</code> for communication with a DS2406/2407. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2406/2407 * * @see #OneWireContainer12() * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[]) * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer12(DSPortAdapter,String) */ public OneWireContainer12 (DSPortAdapter sourceAdapter, long newAddress) { super(sourceAdapter, newAddress); } /** * Creates a new <code>OneWireContainer</code> for communication with a DS2406/2407. * * @param sourceAdapter adapter object required to communicate with * this 1-Wire device * @param newAddress address of this DS2406/2407 * * @see #OneWireContainer12() * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[]) * @see #OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer12(DSPortAdapter,long) */ public OneWireContainer12 (DSPortAdapter sourceAdapter, String newAddress) { super(sourceAdapter, newAddress); } //-------- //-------- Information Methods //-------- /** * Gets the Dallas Semiconductor part number of the iButton * or 1-Wire Device as a <code>java.lang.String</code>. * For example "DS1992". * * @return iButton or 1-Wire device name */ public String getName () { return "DS2406"; } /** * Retrieves the alternate Dallas Semiconductor part numbers or names. * A 'family' of MicroLAN devices may have more than one part number * depending on packaging. There can also be nicknames such as * "Crypto iButton". * * @return the alternate names for this iButton or 1-Wire device */ public String getAlternateNames () { return "Dual Addressable Switch, DS2407"; } /** * Gets a short description of the function of this iButton * or 1-Wire Device type. * * @return device description */ public String getDescription () { return "1-Wire Dual Addressable Switch. PIO pin channel " + "A sink capability of typical 50mA at 0.4V with " + "soft turn-on; optional channel B typical 10 mA at " + "0.4V. 1024 bits of Electrically Programmable " + "Read Only Memory (EPROM) partitioned into four 256 " + "bit pages. 7 bytes of user-programmable status " + "memory to control the device."; } /** * Gets an enumeration of memory bank instances that implement one or more * of the following interfaces: * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank}, * and {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank}. * @return <CODE>Enumeration</CODE> of memory banks */ public Enumeration getMemoryBanks () { Vector bank_vector = new Vector(2); // EPROM main bank MemoryBankEPROM mn = new MemoryBankEPROM(this); mn.numberPages = 4; mn.size = 128; bank_vector.addElement(mn); // EPROM status write protect pages bank MemoryBankEPROM st = new MemoryBankEPROM(this); st.bankDescription = "Write protect pages, Page redirection, Switch control"; st.numberPages = 1; st.size = 8; st.pageLength = 8; st.generalPurposeMemory = false; st.extraInfo = false; st.extraInfoLength = 0; st.extraInfoDescription = null; st.crcAfterAddress = false; st.READ_PAGE_WITH_CRC = MemoryBankEPROM.STATUS_READ_PAGE_COMMAND; st.WRITE_MEMORY_COMMAND = MemoryBankEPROM.STATUS_WRITE_COMMAND; bank_vector.addElement(st); // setup OTP features in main memory mn.mbLock = st; mn.lockPage = true; mn.mbRedirect = st; mn.redirectOffset = 1; mn.redirectPage = true; return bank_vector.elements(); } //-------- //-------- Custom Methods for this 1-Wire Device Type //-------- /** * Checks to see how the DS2406 is being supplied with power. * The 6-pin (2 channel) package of the DS2406 can be powered * by an outside source, but will still function on * parasite power only. * * @param state current state of the device returned from <code>readDevice()</code> * * @return <code>true</code> if the device is getting supplied with * power and <code>false</code> if the device is parasite powered * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() */ public boolean isPowerSupplied (byte[] state) { return ((state [0] & 0x80) == 0x80); } /** * Gets the number of channels supported by this switch. * Channel specific methods will use a channel number specified * by an integer from [0 to (<code>getNumberChannels(byte[])</code> - 1)]. Note that * all devices of the same family will not necessarily have the * same number of channels. * * @param state current state of the device returned from <code>readDevice()</code> * * @return the number of channels for this device * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() */ public int getNumberChannels (byte[] state) { return ((state [0] & 0x40) == 0x40) ? 2 : 1; } /** * Checks if the channels of this switch are 'high side' * switches. This indicates that when 'on' or <code>true</code>, the switch output is * connect to the 1-Wire data. If this method returns <code>false</code> * then when the switch is 'on' or <code>true</code>, the switch is connected * to ground. * * @return <code>true</code> if the switch is a 'high side' switch, * <code>false</code> if the switch is a 'low side' switch * * @see #getLatchState(int,byte[]) */ public boolean isHighSideSwitch () { return false; } /** * Checks if the channels of this switch support * activity sensing. If this method returns <code>true</code> then the * method <code>getSensedActivity(int,byte[])</code> can be used. * * @return <code>true</code> if channels support activity sensing * * @see #getSensedActivity(int,byte[]) * @see #clearActivity() */ public boolean hasActivitySensing () { return true; } /** * Checks if the channels of this switch support * level sensing. If this method returns <code>true</code> then the * method <code>getLevel(int,byte[])</code> can be used. * * @return <code>true</code> if channels support level sensing * * @see #getLevel(int,byte[]) */ public boolean hasLevelSensing () { return true; } /** * Checks if the channels of this switch support * 'smart on'. Smart on is the ability to turn on a channel * such that only 1-Wire device on this channel are awake * and ready to do an operation. This greatly reduces * the time to discover the device down a branch. * If this method returns <code>true</code> then the * method <code>setLatchState(int,boolean,boolean,byte[])</code> * can be used with the <code>doSmart</code> parameter <code>true</code>. * * @return <code>true</code> if channels support 'smart on' * * @see #setLatchState(int,boolean,boolean,byte[]) */ public boolean hasSmartOn () { return false; } /** * Checks if the channels of this switch require that only one * channel is on at any one time. If this method returns <code>true</code> then the * method <code>setLatchState(int,boolean,boolean,byte[])</code> * will not only affect the state of the given * channel but may affect the state of the other channels as well * to insure that only one channel is on at a time. * * @return <code>true</code> if only one channel can be on at a time. * * @see #setLatchState(int,boolean,boolean,byte[]) */ public boolean onlySingleChannelOn () { return false; } //-------- //-------- Switch 'get' Methods //-------- /** * Checks the sensed level on the indicated channel. * To avoid an exception, verify that this switch * has level sensing with the <code>hasLevelSensing()</code>. * Level sensing means that the device can sense the logic * level on its PIO pin. * * @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 level sensed is 'high' and <code>false</code> if level sensed is 'low' * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #hasLevelSensing() */ public boolean getLevel (int channel, byte[] state) { if (channel == 0) return ((state [0] & 0x04) == 0x04); else return ((state [0] & 0x08) == 0x08); } /** * Checks the latch state of the indicated channel. * * @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 channel latch is 'on' * or conducting and <code>false</code> if channel latch is 'off' and not * conducting. Note that the actual output when the latch is 'on' * is returned from the <code>isHighSideSwitch()</code> method. * * @see com.dalsemi.onewire.container.OneWireSensor#readDevice() * @see #isHighSideSwitch() * @see #setLatchState(int,boolean,boolean,byte[]) */ public boolean getLatchState (int channel, byte[] state) { if (channel == 0) { return ((state [1] & 0x20) != 0x20); } else { return ((state [1] & 0x40) != 0x40); } } /** * Checks if the indicated channel has experienced activity. * This occurs when the level on the PIO pins changes. To clear * the activity that is reported, call <code>clearActivity()</code>. * To avoid an exception, verify that this device supports activity * sensing by calling the method <code>hasActivitySensing()</code>. * * @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 * * @see #hasActivitySensing() * @see #clearActivity() */ public boolean getSensedActivity (int channel, byte[] state) { if (channel == 0) return ((state [0] & 0x10) == 0x10); else return ((state [0] & 0x20) == 0x20);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -