Package com.dalsemi.onewire.adapter
Class LSerialAdapter
java.lang.Object
com.dalsemi.onewire.adapter.DSPortAdapter
com.dalsemi.onewire.adapter.LSerialAdapter
The LSerialAdapter class implements the DSPortAdapter interface for a legacy
1-Wire serial interface adapters such as the DS9097.
Instances of valid LSerialdapter's are retrieved from methods in
OneWireAccessProvider
.
The DSPortAdapter methods can be organized into the following categories:
- Information
- Port Selection
- Adapter Capabilities
- 1-Wire Network Semaphore
- 1-Wire Device Discovery
- Selective Search Options
- Search With Automatic 1-Wire Container creation
- Search With NO 1-Wire Container creation
- Manual 1-Wire Container creation
- 1-Wire Network low level access (usually not called directly)
- Device Selection and Presence Detect
- Raw 1-Wire IO
- 1-Wire Speed and Power Selection
- Advanced
- See Also:
-
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Detect 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.void
dataBlock
(byte[] dataBlock, int off, int len) Sends a block of data and returns the data received in the same array.void
Relinquishes exclusive control of the 1-Wire Network.boolean
Returnstrue
if the first iButton or 1-Wire device is found on the 1-Wire Network.boolean
Returnstrue
if the next iButton or 1-Wire device is found.void
freePort()
Free ownership of the selected port if it is currently owned back to the system.Retrieve the address of the adapter if it has one.Retrieve the name of the port adapter as a string.Retrieve the version of the adapter.void
getAddress
(byte[] address) Copies the 'current' iButton address being used by the adapter into the array.boolean
getBit()
Gets a bit from the 1-Wire Network.void
getBlock
(byte[] arr, int len) Get a block of data from the 1-Wire Network and write it into the provided array.void
getBlock
(byte[] arr, int off, int len) Get a block of data from the 1-Wire Network and write it into the provided array.byte[]
getBlock
(int len) Get a block of data from the 1-Wire Network.int
getByte()
Gets a byte from the 1-Wire Network.Retrieve a version string for this class.Retrieve the name of the selected port as aString
.Retrieve a list of the platform appropriate port names for this adapter.Retrieve a description of the port required by this port adapter.void
putBit
(boolean bitValue) Sends a bit to the 1-Wire Network.void
putByte
(int byteValue) Sends a byte to the 1-Wire Network.int
reset()
Sends a Reset to the 1-Wire Network.boolean
selectPort
(String newPortName) Specify a platform appropriate port name for this adapter.void
setAddress
(byte[] address) Copies the provided 1-Wire device address into the 'current' array.void
Set the 1-Wire Network search to not perform a 1-Wire reset before a search.void
Set 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
Set 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.Methods inherited from class com.dalsemi.onewire.adapter.DSPortAdapter
assertSelect, assertSelect, assertSelect, canBreak, canDeliverPower, canDeliverSmartPower, canFlex, canHyperdrive, canOverdrive, canProgram, equals, excludeFamily, excludeFamily, getAddressAsLong, getAddressAsString, getAllDeviceContainers, getDeviceContainer, getDeviceContainer, getDeviceContainer, getDeviceContainer, getFirstDeviceContainer, getNextDeviceContainer, getSpeed, isAlarming, isAlarming, isAlarming, isPresent, isPresent, isPresent, isValidFamily, registerOneWireContainerClass, select, select, select, setPowerDuration, setPowerNormal, setProgramPulseDuration, setSpeed, startBreak, startPowerDelivery, startProgramPulse, targetAllFamilies, targetFamily, targetFamily, toString
-
Constructor Details
-
LSerialAdapter
public LSerialAdapter()Constructs a legacy serial adapter class
-
-
Method Details
-
getAdapterName
Retrieve 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 'DS9097E'.- Specified by:
getAdapterName
in classDSPortAdapter
- Returns:
String
representation of the port adapter.
-
getPortTypeDescription
Retrieve 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
Retrieve a version string for this class.- Specified by:
getClassVersion
in classDSPortAdapter
- Returns:
- version string
-
getPortNames
Retrieve 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 type
String
that contains the port names
-
selectPort
Specify 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:
newPortName
- 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
-
getPortName
Retrieve 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
-
freePort
Free 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
-
adapterDetected
Detect 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
-
getAdapterVersion
Retrieve the version of the adapter.- Overrides:
getAdapterVersion
in classDSPortAdapter
- Returns:
String
of the adapter version. It will return "" if the adapter version is not or cannot be known. - Throws:
OneWireIOException
- on a 1-Wire communication error such as no device present. 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'.OneWireException
- on a communication or setup error with the 1-Wire adapter
-
getAdapterAddress
Retrieve the address of the adapter if it has one.- Overrides:
getAdapterAddress
in classDSPortAdapter
- Returns:
String
of the adapter address. It will return "" if the adapter does not have an address. The address is a string representation of an 1-Wire address. - Throws:
OneWireIOException
- on a 1-Wire communication error such as no device present. 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'.OneWireException
- on a communication or setup error with the 1-Wire adapter- See Also:
-
findFirstDevice
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
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
-
getAddress
public void getAddress(byte[] address) Copies the 'current' iButton address being used by the adapter into the array. This address is the last iButton or 1-Wire device found in a search (findNextDevice()...).- Specified by:
getAddress
in classDSPortAdapter
- Parameters:
address
- An array to be filled with the current iButton address.- See Also:
-
setAddress
public void setAddress(byte[] address) Copies the provided 1-Wire device address into the 'current' array. This address will then be used in the getDeviceContainer() method. Permits the adapter instance to create containers of devices it did not find in a search.- Parameters:
address
- An array to be copied into the current iButton address.
-
setSearchOnlyAlarmingDevices
public void setSearchOnlyAlarmingDevices()Set 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:
-
setNoResetSearch
public void setNoResetSearch()Set 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()Set 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:
-
beginExclusive
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.- 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()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
Sends a bit to the 1-Wire Network.- Specified by:
putBit
in classDSPortAdapter
- Parameters:
bitValue
- 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
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
Sends a byte to the 1-Wire Network.- Specified by:
putByte
in classDSPortAdapter
- Parameters:
byteValue
- 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
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
Get 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
Get a block of data from the 1-Wire Network and write it into the provided array.- Specified by:
getBlock
in classDSPortAdapter
- Parameters:
arr
- 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
Get a block of data from the 1-Wire Network and write it into the provided array.- Specified by:
getBlock
in classDSPortAdapter
- Parameters:
arr
- 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[] dataBlock, int off, int len) throws OneWireIOException, OneWireException 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:
dataBlock
- 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
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) inticates 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
-