📄 dsportadapter.java
字号:
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>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isPresent (byte[] address) throws OneWireIOException, OneWireException { reset(); putByte(0xF0); // Search ROM command return strongAccess(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>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isPresent (long address) throws OneWireIOException, OneWireException { return isPresent(Address.toByteArray(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>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isPresent (String address) throws OneWireIOException, OneWireException { 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 does not * affect the 'current' device state information used in searches * (findNextDevice...). * * @param address device address to verify is present and alarming * * @return <code>true</code> if device is present and alarming, else * <code>false</code>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isAlarming (byte[] address) throws OneWireIOException, OneWireException { reset(); putByte(0xEC); // Conditional search commands return strongAccess(address); } /** * Verifies that the iButton or 1-Wire device specified is present * on the 1-Wire Network and in an alarm state. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * @param address device address to verify is present and alarming * * @return <code>true</code> if device is present and alarming, else * <code>false</code>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isAlarming (long address) throws OneWireIOException, OneWireException { 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 does not * affect the 'current' device state information used in searches * (findNextDevice...). * * @param address device address to verify is present and alarming * * @return <code>true</code> if device is present and alarming, else * <code>false</code>. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see Address */ public boolean isAlarming (String address) throws OneWireIOException, OneWireException { return isAlarming(Address.toByteArray(address)); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * 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. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#isPresent(byte[]) * @see Address */ public boolean select (byte[] address) throws OneWireIOException, OneWireException { // send 1-Wire Reset int rslt = reset(); // broadcast the MATCH ROM command and address byte[] send_packet = new byte [9]; send_packet [0] = 0x55; // MATCH ROM command System.arraycopy(address, 0, send_packet, 1, 8); dataBlock(send_packet, 0, 9); // success if any device present on 1-Wire Network return ((rslt == RESET_PRESENCE) || (rslt == RESET_ALARM)); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * 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. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#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. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * 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. * * @throws OneWireIOException on a 1-Wire communication error * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#isPresent(byte[]) * @see Address */ public boolean select (String address) throws OneWireIOException, OneWireException { return select(Address.toByteArray(address)); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * In addition, this method asserts that the select did find some * devices on the 1-Wire net. If no devices were found, a OneWireException * is thrown. * * 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 * * @throws OneWireIOException on a 1-Wire communication error, or if their * are no devices on the 1-Wire net. * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#isPresent(byte[]) * @see Address */ public void assertSelect(byte[] address) throws OneWireIOException, OneWireException { if(!select(address)) throw new OneWireIOException("Device " + Address.toString(address) + " not present."); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * In addition, this method asserts that the select did find some * devices on the 1-Wire net. If no devices were found, a OneWireException * is thrown. * * 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. * * @throws OneWireIOException on a 1-Wire communication error, or if their * are no devices on the 1-Wire net. * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#isPresent(byte[]) * @see Address */ public void assertSelect(long address) throws OneWireIOException, OneWireException { if(!select(Address.toByteArray(address))) throw new OneWireIOException("Device " + Address.toString(address) + " not present."); } /** * Selects the specified iButton or 1-Wire device by broadcasting its * address. This operation is refered to a 'MATCH ROM' operation * in the iButton and 1-Wire device data sheets. This does not * affect the 'current' device state information used in searches * (findNextDevice...). * * In addition, this method asserts that the select did find some * devices on the 1-Wire net. If no devices were found, a OneWireException * is thrown. * * 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 * * @throws OneWireIOException on a 1-Wire communication error, or if their * are no devices on the 1-Wire net. * @throws OneWireException on a setup error with the 1-Wire adapter * * @see com.dalsemi.onewire.adapter.DSPortAdapter#isPresent(byte[]) * @see Address */ public void assertSelect(String address) throws OneWireIOException, OneWireException { if(!select(Address.toByteArray(address))) throw new OneWireIOException("Device " + address + " not present."); } //-------- //-------- Finding iButton/1-Wire device options //-------- /** * Sets the 1-Wire Network search to find only iButtons and 1-Wire * devices that are in an 'Alarm' state that signals a need for * attention. Not all iButton types * have this feature. Some that do: DS1994, DS1920, DS2407. * This selective searching can be canceled with the * 'setSearchAllDevices()' method. * * @see #setNoResetSearch */ public abstract void setSearchOnlyAlarmingDevices (); /** * Sets the 1-Wire Network search to not perform a 1-Wire * reset before a search. This feature is chiefly used with * the DS2409 1-Wire coupler. * The normal reset before each search can be restored with the * 'setSearchAllDevices()' method. */ public abstract void setNoResetSearch (); /** * Sets the 1-Wire Network search to find all iButtons and 1-Wire * devices whether they are in an 'Alarm' state or not and * restores the default setting of providing a 1-Wire reset * command before each search. (see setNoResetSearch() method). * * @see #setNoResetSearch */ public abstract void setSearchAllDevices (); /** * Removes any selectivity during a search for iButtons or 1-Wire devices * by family type. The unique address for each iButton and 1-Wire device * contains a family descriptor that indicates the capabilities of the * device. * @see #targetFamily * @see #targetFamily(byte[]) * @see #excludeFamily * @see #excludeFamily(byte[]) */ public void targetAllFamilies () {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -