📄 dumbadapter.java
字号:
public OneWireContainer getNextDeviceContainer () { synchronized(containers) { if (containers.size() > containers_index) { containers_index++; return (OneWireContainer) containers.elementAt(containers_index - 1); } else return null; } } /** * Returns <code>true</code> if the first iButton or 1-Wire device * is found on the 1-Wire Network. * If no devices are found, then <code>false</code> will be returned. * * @return <code>true</code> if an iButton or 1-Wire device is found. */ public boolean findFirstDevice () { synchronized(containers) { if (containers.size() > 0) { containers_index = 1; return true; } else return false; } } /** * Returns <code>true</code> if the next iButton or 1-Wire device * is found. The previous 1-Wire device found is used * as a starting point in the search. If no more devices are found * then <code>false</code> will be returned. * * @return <code>true</code> if an iButton or 1-Wire device is found. */ public boolean findNextDevice () { synchronized(containers) { if (containers.size() > containers_index) { containers_index++; return true; } else return false; } } /** * Copies the 'current' 1-Wire device address being used by the adapter into * the array. This address is the last iButton or 1-Wire device found * in a search (findNextDevice()...). * This method copies into a user generated array to allow the * reuse of the buffer. When searching many iButtons on the one * wire network, this will reduce the memory burn rate. * * @param address An array to be filled with the current iButton address. * @see Address */ public void getAddress (byte[] address) { OneWireContainer temp = (OneWireContainer) containers.elementAt(containers_index - 1); if (temp != null) { System.arraycopy(temp.getAddress(), 0, address, 0, 8); } } /** * Gets the 'current' 1-Wire device address being used by the adapter as a long. * This address is the last iButton or 1-Wire device found * in a search (findNextDevice()...). * * @return <code>long</code> representation of the iButton address * @see Address */ public long getAddressAsLong () { byte[] address = new byte [8]; getAddress(address); return Address.toLong(address); } /** * Gets the 'current' 1-Wire device address being used by the adapter as a String. * This address is the last iButton or 1-Wire device found * in a search (findNextDevice()...). * * @return <code>String</code> representation of the iButton address * @see Address */ public String getAddressAsString () { byte[] address = new byte [8]; getAddress(address); return Address.toString(address); } /** * Verifies that the iButton or 1-Wire device specified is present on * the 1-Wire Network. This does not affect the 'current' device * state information used in searches (findNextDevice...). * * @param address device address to verify is present * * @return <code>true</code> if device is present, else * <code>false</code>. * * @see Address */ public boolean isPresent (byte[] address) { return isPresent(Address.toLong(address)); } /** * Verifies that the iButton or 1-Wire device specified is present on * the 1-Wire Network. This does not affect the 'current' device * state information used in searches (findNextDevice...). * * @param address device address to verify is present * * @return <code>true</code> if device is present, else * <code>false</code>. * * @see Address */ public boolean isPresent (long address) { synchronized (containers) { for (int i=0;i<containers.size();i++) { OneWireContainer temp = (OneWireContainer) containers.elementAt(i); long addr = temp.getAddressAsLong(); if (addr == address) return true; } } return false; } /** * Verifies that the iButton or 1-Wire device specified is present on * the 1-Wire Network. This does not affect the 'current' device * state information used in searches (findNextDevice...). * * @param address device address to verify is present * * @return <code>true</code> if device is present, else * <code>false</code>. * * @see Address */ public boolean isPresent (String address) { return isPresent(Address.toByteArray(address)); } /** * Verifies that the iButton or 1-Wire device specified is present * on the 1-Wire Network and in an alarm state. This method is currently * not implemented in <code>DumbAdapter</code>. * * @param address device address to verify is present and alarming * * @return <code>false</code> * * @see Address */ public boolean isAlarming (byte[] address) { return false; } /** * Verifies that the iButton or 1-Wire device specified is present * on the 1-Wire Network and in an alarm state. This method is currently * not implemented in <code>DumbAdapter</code>. * * @param address device address to verify is present and alarming * * @return <code>false</code> * * @see Address */ public boolean isAlarming (long address) { return isAlarming(Address.toByteArray(address)); } /** * Verifies that the iButton or 1-Wire device specified is present * on the 1-Wire Network and in an alarm state. This method is currently * not implemented in <code>DumbAdapter</code>. * * @param address device address to verify is present and alarming * * @return <code>false</code> * * @see Address */ public boolean isAlarming (String address) { return isAlarming(Address.toByteArray(address)); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. With a <code>DumbAdapter</code>, this method simply * returns true. * * Warning, this does not verify that the device is currently present * on the 1-Wire Network (See isPresent). * * @param address address of iButton or 1-Wire device to select * * @return <code>true</code> if device address was sent, <code>false</code> * otherwise. * * @see #isPresent(byte[]) * @see Address */ public boolean select (byte[] address) { return isPresent(address); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. With a <code>DumbAdapter</code>, this method simply * returns true. * * Warning, this does not verify that the device is currently present * on the 1-Wire Network (See isPresent). * * @param address address of iButton or 1-Wire device to select * * @return <code>true</code> if device address was sent, <code>false</code> * otherwise. * * @see #isPresent(byte[]) * @see Address */ public boolean select (long address) throws OneWireIOException, OneWireException { return select(Address.toByteArray(address)); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. With a <code>DumbAdapter</code>, this method simply * returns true. * * Warning, this does not verify that the device is currently present * on the 1-Wire Network (See isPresent). * * @param address address of iButton or 1-Wire device to select * * @return <code>true</code> if device address was sent, <code>false</code> * otherwise. * * @see #isPresent(byte[]) * @see Address */ public boolean select (String address) throws OneWireIOException, OneWireException { return select(Address.toByteArray(address)); } //-------- //-------- Finding iButton/1-Wire device options //-------- /** * This method does nothing in <code>DumbAdapter</code>. * * @see #setNoResetSearch */ public void setSearchOnlyAlarmingDevices () { } /** * This method does nothing in <code>DumbAdapter</code>. * */ public void setNoResetSearch () { } /** * This method does nothing in <code>DumbAdapter</code>. * * @see #setNoResetSearch */ public void setSearchAllDevices () { } /** * This method does nothing in <code>DumbAdapter</code>. * * @see #targetFamily * @see #targetFamily(byte[]) * @see #excludeFamily * @see #excludeFamily(byte[]) */ public void targetAllFamilies () { include = null; exclude = null; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param family the code of the family type to target for searches * @see Address * @see #targetAllFamilies */ public void targetFamily (int family) { if ((include == null) || (include.length != 1)) include = new byte [1]; include [0] = ( byte ) family; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param family array of the family types to target for searches * @see Address * @see #targetAllFamilies */ public void targetFamily (byte family []) { if ((include == null) || (include.length != family.length)) include = new byte [family.length]; System.arraycopy(family, 0, include, 0, family.length); } /** * This method does nothing in <code>DumbAdapter</code>. * * @param family the code of the family type NOT to target in searches * @see Address * @see #targetAllFamilies */ public void excludeFamily (int family) { if ((exclude == null) || (exclude.length != 1)) exclude = new byte [1]; exclude [0] = ( byte ) family; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param family array of family cods NOT to target for searches * @see Address * @see #targetAllFamilies */ public void excludeFamily (byte family []) { if ((exclude == null) || (exclude.length != family.length)) exclude = new byte [family.length]; System.arraycopy(family, 0, exclude, 0, family.length); } //-------- //-------- 1-Wire Network Semaphore methods
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -