Package com.dalsemi.onewire.adapter
Class PDKAdapterUSB
- java.lang.Object
-
- com.dalsemi.onewire.adapter.DSPortAdapter
-
- com.dalsemi.onewire.adapter.PDKAdapterUSB
-
public class PDKAdapterUSB extends DSPortAdapter
-
-
Field Summary
-
Fields inherited from class com.dalsemi.onewire.adapter.DSPortAdapter
CONDITION_AFTER_BIT, CONDITION_AFTER_BYTE, CONDITION_NOW, DELIVERY_CURRENT_DETECT, DELIVERY_EPROM, DELIVERY_FOUR_SECONDS, DELIVERY_HALF_SECOND, DELIVERY_INFINITE, DELIVERY_ONE_SECOND, DELIVERY_SMART_DONE, DELIVERY_TWO_SECONDS, LEVEL_BREAK, LEVEL_NORMAL, LEVEL_POWER_DELIVERY, LEVEL_PROGRAM, RESET_ALARM, RESET_NOPRESENCE, RESET_PRESENCE, RESET_SHORT, SPEED_FLEX, SPEED_HYPERDRIVE, SPEED_OVERDRIVE, SPEED_REGULAR
-
-
Constructor Summary
Constructors Constructor Description PDKAdapterUSB()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
adapterDetected()
Detects adapter presence on the selected port.boolean
beginExclusive(boolean blocking)
Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device.boolean
canBreak()
Returns whether adapter can physically support 0 volt 'break' mode.boolean
canDeliverPower()
Returns whether the adapter can physically support strong 5 volt power mode.boolean
canDeliverSmartPower()
Returns whether the adapter can physically support "smart" strong 5 volt power mode.boolean
canFlex()
Returns whether the adapter can physically support flex speed mode.boolean
canHyperdrive()
Returns whether the adapter can physically support hyperdrive mode.boolean
canOverdrive()
Returns whether adapter can physically support overdrive mode.boolean
canProgram()
Returns whether adapter can physically support 12 volt power mode.void
dataBlock(byte[] buff, int off, int len)
Sends a block of data and returns the data received in the same array.void
endExclusive()
Relinquishes exclusive control of the 1-Wire Network.boolean
findFirstDevice()
Returnstrue
if the first iButton or 1-Wire device is found on the 1-Wire Network.boolean
findNextDevice()
Returnstrue
if the next iButton or 1-Wire device is found.void
freePort()
Frees ownership of the selected port, if it is currently owned, back to the system.java.lang.String
getAdapterName()
Retrieves the name of the port adapter as a string.void
getAddress(byte[] address)
Copies the 'current' 1-Wire device address being used by the adapter into the array.boolean
getBit()
Gets a bit from the 1-Wire Network.void
getBlock(byte[] buff, int len)
Gets a block of data from the 1-Wire Network and write it into the provided array.void
getBlock(byte[] buff, int off, int len)
Gets a block of data from the 1-Wire Network and write it into the provided array.byte[]
getBlock(int len)
Gets a block of data from the 1-Wire Network.int
getByte()
Gets a byte from the 1-Wire Network.java.lang.String
getClassVersion()
Retrieves a version string for this class.java.lang.String
getPortName()
Retrieves the name of the selected port as aString
.java.util.Enumeration<java.lang.String>
getPortNames()
Retrieves a list of the platform appropriate port names for this adapter.java.lang.String
getPortTypeDescription()
Retrieves a description of the port required by this port adapter.int
PowerLevel(int portHandle, int newLevel)
void
putBit(boolean dataBit)
Sends a bit to the 1-Wire Network.void
putByte(int dataByte)
Sends a byte to the 1-Wire Network.int
reset()
Sends a Reset to the 1-Wire Network.boolean
selectPort(java.lang.String portName)
Specifies a platform appropriate port name for this adapter.void
setNoResetSearch()
Sets the 1-Wire Network search to not perform a 1-Wire reset before a search.void
setPowerDuration(int timeFactor)
Sets the duration to supply power to the 1-Wire Network.void
setPowerNormal()
Sets the 1-Wire Network voltage to normal level.void
setSearchAllDevices()
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.void
setSearchOnlyAlarmingDevices()
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.boolean
startPowerDelivery(int changeCondition)
Sets the 1-Wire Network voltage to supply power to an iButton device.-
Methods inherited from class com.dalsemi.onewire.adapter.DSPortAdapter
assertSelect, assertSelect, assertSelect, equals, excludeFamily, excludeFamily, getAdapterAddress, getAdapterVersion, getAddressAsLong, getAddressAsString, getAllDeviceContainers, getDeviceContainer, getDeviceContainer, getDeviceContainer, getDeviceContainer, getFirstDeviceContainer, getNextDeviceContainer, getSpeed, isAlarming, isAlarming, isAlarming, isPresent, isPresent, isPresent, isValidFamily, registerOneWireContainerClass, select, select, select, setProgramPulseDuration, setSpeed, startBreak, startProgramPulse, targetAllFamilies, targetFamily, targetFamily, toString
-
-
-
-
Method Detail
-
selectPort
public boolean selectPort(java.lang.String portName) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Specifies a platform appropriate port name for this adapter. Note that even though the port has been selected, it's ownership may be relinquished if it is not currently held in a 'exclusive' block. This class will then try to re-acquire the port when needed. If the port cannot be re-acquired when the exceptionPortInUseException
will be thrown.- Specified by:
selectPort
in classDSPortAdapter
- Parameters:
portName
- name of the target port, retrieved from getPortNames()- Returns:
true
if the port was acquired,false
if the port is not available.- Throws:
OneWireIOException
- If port does not exist, or unable to communicate with port.OneWireException
- If port does not exist
-
freePort
public void freePort() throws OneWireException
Description copied from class:DSPortAdapter
Frees ownership of the selected port, if it is currently owned, back to the system. This should only be called if the recently selected port does not have an adapter, or at the end of your application's use of the port.- Specified by:
freePort
in classDSPortAdapter
- Throws:
OneWireException
- If port does not exist
-
getAdapterName
public java.lang.String getAdapterName()
Description copied from class:DSPortAdapter
Retrieves the name of the port adapter as a string. The 'Adapter' is a device that connects to a 'port' that allows one to communicate with an iButton or other 1-Wire device. As example of this is 'DS9097U'.- Specified by:
getAdapterName
in classDSPortAdapter
- Returns:
String
representation of the port adapter.
-
getPortTypeDescription
public java.lang.String getPortTypeDescription()
Description copied from class:DSPortAdapter
Retrieves a description of the port required by this port adapter. An example of a 'Port' would 'serial communication port'.- Specified by:
getPortTypeDescription
in classDSPortAdapter
- Returns:
String
description of the port type required.
-
getClassVersion
public java.lang.String getClassVersion()
Description copied from class:DSPortAdapter
Retrieves a version string for this class.- Specified by:
getClassVersion
in classDSPortAdapter
- Returns:
- version string
-
getPortNames
public java.util.Enumeration<java.lang.String> getPortNames()
Description copied from class:DSPortAdapter
Retrieves a list of the platform appropriate port names for this adapter. A port must be selected with the method 'selectPort' before any other communication methods can be used. Using a communication method before 'selectPort' will result in aOneWireException
exception.- Specified by:
getPortNames
in classDSPortAdapter
- Returns:
Enumeration
of typeString
that contains the port names
-
getPortName
public java.lang.String getPortName() throws OneWireException
Description copied from class:DSPortAdapter
Retrieves the name of the selected port as aString
.- Specified by:
getPortName
in classDSPortAdapter
- Returns:
String
of selected port- Throws:
OneWireException
- if valid port not yet selected
-
adapterDetected
public boolean adapterDetected() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Detects adapter presence on the selected port.- Specified by:
adapterDetected
in classDSPortAdapter
- Returns:
true
if the adapter is confirmed to be connected to the selected port,false
if the adapter is not connected.- Throws:
OneWireIOException
OneWireException
-
getAddress
public void getAddress(byte[] address)
Description copied from class:DSPortAdapter
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.- Specified by:
getAddress
in classDSPortAdapter
- Parameters:
address
- An array to be filled with the current iButton address.- See Also:
Address
-
findFirstDevice
public boolean findFirstDevice() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Returnstrue
if the first iButton or 1-Wire device is found on the 1-Wire Network. If no devices are found, thenfalse
will be returned.- Specified by:
findFirstDevice
in classDSPortAdapter
- Returns:
true
if an iButton or 1-Wire device is found.- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
findNextDevice
public boolean findNextDevice() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Returnstrue
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 thenfalse
will be returned.- Specified by:
findNextDevice
in classDSPortAdapter
- Returns:
true
if an iButton or 1-Wire device is found.- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
setSearchOnlyAlarmingDevices
public void setSearchOnlyAlarmingDevices()
Description copied from class:DSPortAdapter
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.- Specified by:
setSearchOnlyAlarmingDevices
in classDSPortAdapter
- See Also:
DSPortAdapter.setNoResetSearch()
-
setNoResetSearch
public void setNoResetSearch()
Description copied from class:DSPortAdapter
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.- Specified by:
setNoResetSearch
in classDSPortAdapter
-
setSearchAllDevices
public void setSearchAllDevices()
Description copied from class:DSPortAdapter
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).- Specified by:
setSearchAllDevices
in classDSPortAdapter
- See Also:
DSPortAdapter.setNoResetSearch()
-
beginExclusive
public boolean beginExclusive(boolean blocking) throws OneWireException
Description copied from class:DSPortAdapter
Gets exclusive use of the 1-Wire to communicate with an iButton or 1-Wire Device. This method should be used for critical sections of code where a sequence of commands must not be interrupted by communication of threads with other iButtons, and it is permissible to sustain a delay in the special case that another thread has already been granted exclusive access and this access has not yet been relinquished.It can be called through the OneWireContainer class by the end application if they want to ensure exclusive use. If it is not called around several methods then it will be called inside each method.
- Specified by:
beginExclusive
in classDSPortAdapter
- Parameters:
blocking
-true
if want to block waiting for exclusive access to the adapter- Returns:
true
if blocking was false and a exclusive session with the adapter was acquired- Throws:
OneWireException
- on a setup error with the 1-Wire adapter
-
endExclusive
public void endExclusive()
Description copied from class:DSPortAdapter
Relinquishes exclusive control of the 1-Wire Network. This command dynamically marks the end of a critical section and should be used when exclusive control is no longer needed.- Specified by:
endExclusive
in classDSPortAdapter
-
putBit
public void putBit(boolean dataBit) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Sends a bit to the 1-Wire Network.- Specified by:
putBit
in classDSPortAdapter
- Parameters:
dataBit
- the bit value to send to the 1-Wire Network.- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
getBit
public boolean getBit() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Gets a bit from the 1-Wire Network.- Specified by:
getBit
in classDSPortAdapter
- Returns:
- the bit value received from the the 1-Wire Network.
- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
putByte
public void putByte(int dataByte) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Sends a byte to the 1-Wire Network.- Specified by:
putByte
in classDSPortAdapter
- Parameters:
dataByte
- the byte value to send to the 1-Wire Network.- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
getByte
public int getByte() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Gets a byte from the 1-Wire Network.- Specified by:
getByte
in classDSPortAdapter
- Returns:
- the byte value received from the the 1-Wire Network.
- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
getBlock
public byte[] getBlock(int len) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Gets a block of data from the 1-Wire Network.- Specified by:
getBlock
in classDSPortAdapter
- Parameters:
len
- length of data bytes to receive- Returns:
- the data received from the 1-Wire Network.
- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
getBlock
public void getBlock(byte[] buff, int len) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Gets a block of data from the 1-Wire Network and write it into the provided array.- Specified by:
getBlock
in classDSPortAdapter
- Parameters:
buff
- array in which to write the received byteslen
- length of data bytes to receive- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
getBlock
public void getBlock(byte[] buff, int off, int len) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Gets a block of data from the 1-Wire Network and write it into the provided array.- Specified by:
getBlock
in classDSPortAdapter
- Parameters:
buff
- array in which to write the received bytesoff
- offset into the array to startlen
- length of data bytes to receive- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
dataBlock
public void dataBlock(byte[] buff, int off, int len) throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Sends a block of data and returns the data received in the same array. This method is used when sending a block that contains reads and writes. The 'read' portions of the data block need to be pre-loaded with 0xFF's. It starts sending data from the index at offset 'off' for length 'len'.- Specified by:
dataBlock
in classDSPortAdapter
- Parameters:
buff
- array of data to transfer to and from the 1-Wire Network.off
- offset into the array of data to startlen
- length of data to send / receive starting at 'off'- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
reset
public int reset() throws OneWireIOException, OneWireException
Description copied from class:DSPortAdapter
Sends a Reset to the 1-Wire Network.- Specified by:
reset
in classDSPortAdapter
- Returns:
- the result of the reset. Potential results are:
- 0 (RESET_NOPRESENCE) no devices present on the 1-Wire Network.
- 1 (RESET_PRESENCE) normal presence pulse detected on the 1-Wire Network indicating there is a device present.
- 2 (RESET_ALARM) alarming presence pulse detected on the 1-Wire Network indicating there is a device present and it is in the alarm condition. This is only provided by the DS1994/DS2404 devices.
- 3 (RESET_SHORT) indicates 1-Wire appears shorted. This can be transient conditions in a 1-Wire Network. Not all adapter types can detect this condition.
- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
canOverdrive
public boolean canOverdrive() throws OneWireIOException, OneWireException
Returns whether adapter can physically support overdrive mode.- Overrides:
canOverdrive
in classDSPortAdapter
- Returns:
true
if this port adapter can do OverDrive,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canHyperdrive
public boolean canHyperdrive() throws OneWireIOException, OneWireException
Returns whether the adapter can physically support hyperdrive mode.- Overrides:
canHyperdrive
in classDSPortAdapter
- Returns:
true
if this port adapter can do HyperDrive,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canFlex
public boolean canFlex() throws OneWireIOException, OneWireException
Returns whether the adapter can physically support flex speed mode.- Overrides:
canFlex
in classDSPortAdapter
- Returns:
true
if this port adapter can do flex speed,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canProgram
public boolean canProgram() throws OneWireIOException, OneWireException
Returns whether adapter can physically support 12 volt power mode.- Overrides:
canProgram
in classDSPortAdapter
- Returns:
true
if this port adapter can do Program voltage,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canDeliverPower
public boolean canDeliverPower() throws OneWireIOException, OneWireException
Returns whether the adapter can physically support strong 5 volt power mode.- Overrides:
canDeliverPower
in classDSPortAdapter
- Returns:
true
if this port adapter can do strong 5 volt mode,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canDeliverSmartPower
public boolean canDeliverSmartPower() throws OneWireIOException, OneWireException
Returns whether the adapter can physically support "smart" strong 5 volt power mode. "smart" power delivery is the ability to deliver power until it is no longer needed. The current drop it detected and power delivery is stopped.- Overrides:
canDeliverSmartPower
in classDSPortAdapter
- Returns:
true
if this port adapter can do "smart" strong 5 volt mode,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
canBreak
public boolean canBreak() throws OneWireIOException, OneWireException
Returns whether adapter can physically support 0 volt 'break' mode.- Overrides:
canBreak
in classDSPortAdapter
- Returns:
true
if this port adapter can do break,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication error with the adapterOneWireException
- on a setup error with the 1-Wire adapter
-
setPowerDuration
public void setPowerDuration(int timeFactor) throws OneWireIOException, OneWireException
Sets the duration to supply power to the 1-Wire Network. This method takes a time parameter that indicates the program pulse length when the method startPowerDelivery().Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.
- Overrides:
setPowerDuration
in classDSPortAdapter
- Parameters:
timeFactor
-- 0 (DELIVERY_HALF_SECOND) provide power for 1/2 second.
- 1 (DELIVERY_ONE_SECOND) provide power for 1 second.
- 2 (DELIVERY_TWO_SECONDS) provide power for 2 seconds.
- 3 (DELIVERY_FOUR_SECONDS) provide power for 4 seconds.
- 4 (DELIVERY_SMART_DONE) provide power until the the device is no longer drawing significant power.
- 5 (DELIVERY_INFINITE) provide power until the setBusNormal() method is called.
- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
startPowerDelivery
public boolean startPowerDelivery(int changeCondition) throws OneWireIOException, OneWireException
Sets the 1-Wire Network voltage to supply power to an iButton device. This method takes a time parameter that indicates whether the power delivery should be done immediately, or after certain conditions have been met.Note: to avoid getting an exception, use the canDeliverPower() and canDeliverSmartPower() method to check it's availability.
- Overrides:
startPowerDelivery
in classDSPortAdapter
- Parameters:
changeCondition
-- 0 (CONDITION_NOW) operation should occur immediately.
- 1 (CONDITION_AFTER_BIT) operation should be pending execution immediately after the next bit is sent.
- 2 (CONDITION_AFTER_BYTE) operation should be pending execution immediately after next byte is sent.
- Returns:
true
if the voltage change was successful,false
otherwise.- Throws:
OneWireIOException
- on a 1-Wire communication errorOneWireException
- on a setup error with the 1-Wire adapter
-
PowerLevel
public int PowerLevel(int portHandle, int newLevel)
-
setPowerNormal
public void setPowerNormal()
Description copied from class:DSPortAdapter
Sets the 1-Wire Network voltage to normal level. This method is used to disable 1-Wire conditions created by startPowerDelivery and startProgramPulse. This method will automatically be called if a communication method is called while an outstanding power command is taking place.- Overrides:
setPowerNormal
in classDSPortAdapter
-
-