The memory can be accessed through the objects that are returned from the getMemoryBanks method.
The following is a list of the MemoryBank instances that are returned:
The DS2406 supports level sensing and activity sensing. The code below reports the flip-flop state, PIO level, and sensed activity while toggling every switch each time through the loop. It toggles every switch it finds, regardless if the device has one or two switches.
// "ID" is a byte array of size 8 with an address of a part we
// have already found with family code 12 hex
// "access" is a DSPortAdapter
OneWireContainer12 ds2406 = (OneWireContainer12) access.getDeviceContainer(ID);
ds2406.setupContainer(access,ID);
byte[] state = ds2406.readDevice();
int numchannels = ds2406.getNumberChannels(state);
System.out.println("Number of Channels: "+numchannels);
boolean[] switches = new boolean[numchannels];
ds2406.clearActivity();
for (int j=0;j<10;j++)
{
//clear the activity latches halfway through the test
if (j==5)
ds2406.clearActivity();
state = ds2406.readDevice();
//first let's print out the status of all the latches
for (int i=0;i < numchannels;i++)
{
System.out.println("---------------------------------------------------------\r\n");
System.out.println(" CHANNEL "+i);
System.out.println("---------------------------------------------------------\r\n");
System.out.println(" Latch state: "+ds2406.getLatchState(i,state));
System.out.println(" Level : "+ds2406.getLevel(i,state));
System.out.println(" Activity : "+ds2406.getSensedActivity(i, state));
switches[i] = ds2406.getLatchState(i,state);
}
//now lets toggle the switch flip-flop
for (int i=0;i < numchannels;i++)
{
ds2406.setLatchState(i,!switches[i],false,state);
}
ds2406.writeDevice(state);
Thread.sleep(500);
}
Also see the usage example in the SwithContainer interface.
For examples regarding memory operations,
Also see the DS2405, a single addressable switch (OneWireContainer05).
Public Member Functions | |
OneWireContainer12 () | |
Creates a new OneWireContainer for communication with a DS2406/2407. | |
OneWireContainer12 (DSPortAdapter sourceAdapter, byte[] newAddress) | |
Creates a new OneWireContainer for communication with a DS2406/2407. | |
OneWireContainer12 (DSPortAdapter sourceAdapter, long newAddress) | |
Creates a new OneWireContainer for communication with a DS2406/2407. | |
OneWireContainer12 (DSPortAdapter sourceAdapter, String newAddress) | |
Creates a new OneWireContainer for communication with a DS2406/2407. | |
String | getName () |
Gets the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String . | |
String | getAlternateNames () |
Retrieves the alternate Maxim Integrated Products part numbers or names. | |
String | getDescription () |
Gets a short description of the function of this iButton or 1-Wire Device type. | |
Enumeration | getMemoryBanks () |
Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank. | |
boolean | isPowerSupplied (byte[] state) |
Checks to see how the DS2406 is being supplied with power. | |
int | getNumberChannels (byte[] state) |
Gets the number of channels supported by this switch. | |
boolean | isHighSideSwitch () |
Checks if the channels of this switch are 'high side' switches. | |
boolean | hasActivitySensing () |
Checks if the channels of this switch support activity sensing. | |
boolean | hasLevelSensing () |
Checks if the channels of this switch support level sensing. | |
boolean | hasSmartOn () |
Checks if the channels of this switch support 'smart on'. | |
boolean | onlySingleChannelOn () |
Checks if the channels of this switch require that only one channel is on at any one time. | |
boolean | getLevel (int channel, byte[] state) |
Checks the sensed level on the indicated channel. | |
boolean | getLatchState (int channel, byte[] state) |
Checks the latch state of the indicated channel. | |
boolean | getSensedActivity (int channel, byte[] state) |
Checks if the indicated channel has experienced activity. | |
void | clearActivity () |
void | setLatchState (int channel, boolean latchState, boolean doSmart, byte[] state) |
Sets the latch state of the indicated channel. | |
byte[] | readDevice () throws OneWireIOException, OneWireException |
Retrieves the 1-Wire device sensor state. | |
void | writeDevice (byte[] state) throws OneWireIOException, OneWireException |
Writes the 1-Wire device sensor state that have been changed by 'set' methods. | |
synchronized void | setSpeedCheck (boolean doSpeedCheck) |
Directs the container to avoid the calls to doSpeed() in methods that communicate with the Thermocron. | |
void | setSearchConditions (byte channel, byte source, byte polarity, byte[] state) |
byte[] | channelAccess (byte[] inbuffer, boolean toggleRW, boolean readInitially, int CRCMode, int channelMode, boolean clearActivity, boolean interleave) throws OneWireException, OneWireIOException |
Static Public Attributes | |
static final byte | SOURCE_ACTIVITY_LATCH = (byte) 0x02 |
Used to set the source to the activity latch for conditional searches in the setSearchConditions() method. | |
static final byte | SOURCE_FLIP_FLOP = (byte) 0x04 |
Used to set the source to the flip-flop state for conditional searches in the setSearchConditions() method. | |
static final byte | SOURCE_PIO = (byte) 0x06 |
Used to set the source to the PIO status for conditional searches in the setSearchConditions() method. | |
static final byte | POLARITY_ZERO = 0x00 |
Used to set the polarity to logical '0' for conditional search checking in the setSearchConditions() method. | |
static final byte | POLARITY_ONE = 0x01 |
Used to set the polarity to logical '1' for conditional search checking in the setSearchConditions() method. | |
static final byte | CHANNEL_NONE = 0x00 |
Used to select neither channel as the source for alarm conditions in the setSearchConditions() method. | |
static final byte | DONT_CHANGE = (byte)0x0ff |
Used for options in the setSearchConditions() to make sure the specified option is not changes from its current value. | |
static final byte | CHANNEL_A_ONLY = 0x04 |
channelMode for the channelAccess method. | |
static final byte | CHANNEL_B_ONLY = 0x08 |
channelMode for the channelAccess method. | |
static final byte | CHANNEL_BOTH = 0x0c |
channelMode for the channelAccess method. | |
static final byte | CRC_DISABLE = 0x00 |
CRCMode for the channelAccess method. | |
static final byte | CRC_EVERY_BYTE = 0x01 |
CRCMode for the channelAccess method. | |
static final byte | CRC_EVERY_8_BYTES = 0x02 |
CRCMode for the channelAccess method. | |
static final byte | CRC_EVERY_32_BYTES = 0x03 |
CRCMode for the channelAccess method. |
Creates a new OneWireContainer
for communication with a DS2406/2407.
Note that the method setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[])
must be called to set the correct DSPortAdapter
device address.
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[])
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer12(DSPortAdapter,long)
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer12(DSPortAdapter,String)
OneWireContainer12 | ( | DSPortAdapter | sourceAdapter, | |
byte[] | newAddress | |||
) |
Creates a new OneWireContainer
for communication with a DS2406/2407.
sourceAdapter | adapter object required to communicate with this 1-Wire device | |
newAddress | address of this DS2406/2407 |
OneWireContainer12 | ( | DSPortAdapter | sourceAdapter, | |
long | newAddress | |||
) |
Creates a new OneWireContainer
for communication with a DS2406/2407.
sourceAdapter | adapter object required to communicate with this 1-Wire device | |
newAddress | address of this DS2406/2407 |
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[])
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer12(DSPortAdapter,String)
OneWireContainer12 | ( | DSPortAdapter | sourceAdapter, | |
String | newAddress | |||
) |
Creates a new OneWireContainer
for communication with a DS2406/2407.
sourceAdapter | adapter object required to communicate with this 1-Wire device | |
newAddress | address of this DS2406/2407 |
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer12(DSPortAdapter,byte[])
OneWireContainer12(com.dalsemi.onewire.adapter.DSPortAdapter,long) OneWireContainer12(DSPortAdapter,long)
String getName | ( | ) |
Gets the Maxim Integrated Products part number of the iButton or 1-Wire Device as a java.lang.String
.
For example "DS1992".
Reimplemented from OneWireContainer.
String getAlternateNames | ( | ) |
Retrieves the alternate Maxim Integrated Products 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".
Reimplemented from OneWireContainer.
String getDescription | ( | ) |
Gets a short description of the function of this iButton or 1-Wire Device type.
Reimplemented from OneWireContainer.
Enumeration getMemoryBanks | ( | ) |
Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank, PagedMemoryBank, and OTPMemoryBank.
Enumeration
of memory banks Reimplemented from OneWireContainer.
boolean isPowerSupplied | ( | byte[] | state | ) |
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.
state | current state of the device returned from readDevice() |
true
if the device is getting supplied with power and false
if the device is parasite poweredint getNumberChannels | ( | byte[] | state | ) |
Gets the number of channels supported by this switch.
Channel specific methods will use a channel number specified by an integer from [0 to (getNumberChannels(byte[])
- 1)]. Note that all devices of the same family will not necessarily have the same number of channels.
state | current state of the device returned from readDevice() |
Implements SwitchContainer.
boolean isHighSideSwitch | ( | ) |
Checks if the channels of this switch are 'high side' switches.
This indicates that when 'on' or true
, the switch output is connect to the 1-Wire data. If this method returns false
then when the switch is 'on' or true
, the switch is connected to ground.
true
if the switch is a 'high side' switch, false
if the switch is a 'low side' switchImplements SwitchContainer.
boolean hasActivitySensing | ( | ) |
Checks if the channels of this switch support activity sensing.
If this method returns true
then the method getSensedActivity(int,byte[])
can be used.
true
if channels support activity sensingImplements SwitchContainer.
boolean hasLevelSensing | ( | ) |
Checks if the channels of this switch support level sensing.
If this method returns true
then the method getLevel(int,byte[])
can be used.
true
if channels support level sensingImplements SwitchContainer.
boolean hasSmartOn | ( | ) |
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 true
then the method setLatchState(int,boolean,boolean,byte[])
can be used with the doSmart
parameter true
.
true
if channels support 'smart on'Implements SwitchContainer.
boolean onlySingleChannelOn | ( | ) |
Checks if the channels of this switch require that only one channel is on at any one time.
If this method returns true
then the method setLatchState(int,boolean,boolean,byte[])
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.
true
if only one channel can be on at a time.Implements SwitchContainer.
boolean getLevel | ( | int | channel, | |
byte[] | state | |||
) |
Checks the sensed level on the indicated channel.
To avoid an exception, verify that this switch has level sensing with the hasLevelSensing()
. Level sensing means that the device can sense the logic level on its PIO pin.
channel | channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)] | |
state | current state of the device returned from readDevice() |
true
if level sensed is 'high' and false
if level sensed is 'low'Implements SwitchContainer.
boolean getLatchState | ( | int | channel, | |
byte[] | state | |||
) |
Checks the latch state of the indicated channel.
channel | channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)] | |
state | current state of the device returned from readDevice() |
true
if channel latch is 'on' or conducting and false
if channel latch is 'off' and not conducting. Note that the actual output when the latch is 'on' is returned from the isHighSideSwitch()
method.setLatchState(int,boolean,boolean,byte[])
Implements SwitchContainer.
boolean getSensedActivity | ( | int | channel, | |
byte[] | state | |||
) |
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 clearActivity()
. To avoid an exception, verify that this device supports activity sensing by calling the method hasActivitySensing()
.
channel | channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)] | |
state | current state of the device returned from readDevice() |
true
if activity was detected and false
if no activity was detectedImplements SwitchContainer.
void clearActivity | ( | ) |
Clears the activity latches the next time possible. For example, on a DS2406/07, this happens the next time the status is read with readDevice()
.
The activity latches will only be cleared once. With the DS2406/07, this means that only the first call to readDevice()
will clear the activity latches. Subsequent calls to readDevice()
will leave the activity latch states intact, unless this method has been invoked since the last call to readDevice()
.
getSensedActivity(int,byte[])
Implements SwitchContainer.
void setLatchState | ( | int | channel, | |
boolean | latchState, | |||
boolean | doSmart, | |||
byte[] | state | |||
) |
Sets the latch state of the indicated channel.
The method writeDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call to writeDevice()
.
channel | channel to execute this operation, in the range [0 to (getNumberChannels(byte[]) - 1)] | |
latchState | true to set the channel latch 'on' (conducting) and false to set the channel latch 'off' (not conducting). Note that the actual output when the latch is 'on' is returned from the isHighSideSwitch() method. | |
doSmart | If latchState is 'on'/true then doSmart indicates if a 'smart on' is to be done. To avoid an exception check the capabilities of this device using the hasSmartOn() method. | |
state | current state of the device returned from readDevice() |
getLatchState(int,byte[])
com.dalsemi.onewire.container.OneWireSensor.writeDevice(byte[])
Implements SwitchContainer.
byte [] readDevice | ( | ) | throws OneWireIOException, OneWireException |
Retrieves the 1-Wire device sensor state.
This state is returned as a byte array. Pass this byte array to the 'get' and 'set' methods. If the device state needs to be changed then call the 'writeDevice' to finalize the changes.
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. 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 |
Implements OneWireSensor.
void writeDevice | ( | byte[] | state | ) | throws OneWireIOException, OneWireException |
Writes the 1-Wire device sensor state that have been changed by 'set' methods.
Only the state registers that changed are updated. This is done by referencing a field information appended to the state data.
state | 1-Wire device sensor state |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. 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 |
Implements OneWireSensor.
synchronized void setSpeedCheck | ( | boolean | doSpeedCheck | ) |
Directs the container to avoid the calls to doSpeed() in methods that communicate with the Thermocron.
To ensure that all parts can talk to the 1-Wire bus at their desired speed, each method contains a call to doSpeed()
. However, this is an expensive operation. If a user manages the bus speed in an application, call this method with doSpeedCheck
as false
. The default behavior is to call doSpeed()
.
doSpeedCheck | true for doSpeed() to be called before every 1-Wire bus access, false to skip this expensive call |
void setSearchConditions | ( | byte | channel, | |
byte | source, | |||
byte | polarity, | |||
byte[] | state | |||
) |
Programs the Conditional Search options for the DS2406/2407.
The DS2406/2407 supports Conditional Searches with user programmable search conditions. This means that the part can alarm on several kinds of conditions, programmable by the user.
The user can select a channel and a source to compare to a polarity. If the source's logical value is equal to the polarity, the device alarms (responds to a Conditional Search). For instance, if channel
is CHANNEL_A
, source
is SOURCE_ACTIVITY_LATCH
, and polarity
is POLARITY_ONE
, then the device will respond to a Conditional Search when the activity latch on channel A is 1 (when activity has been detected on channel A). When channel
is CHANNEL_BOTH
, the selected source signals are ORed for comparison with the polarity. When channel
is CHANNEL_NONE
, the selected source signal is considered a logical '0'. In other words, if channel
is CHANNEL_NONE
, if polarity
is POLARITY_ZERO
, the device always responds to a Conditional Search. If polarity
is POLARITY_ONE
, the device never responds to a Conditional Search.
Note that for any of these options, the value DONT_CHANGE
will insure that the value previously used by the DS2406/2407 will not be altered.
The method writeDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call to writeDevice()
.
Also note that the Hidden Mode of the DS2407 is not supported in this implementation as an option for source selection. Hidden Mode was phased out for the newer DS2406. See the datasheet for the DS2407 for more information on Hidden Mode.
channel | the channel of interest for the source of the conditional check (valid values are CHANNEL_NONE , CHANNEL_A_ONLY , CHANNEL_B_ONLY , CHANNEL_BOTH , and DONT_CHANGE ) | |
source | the source selection for the conditional check (valid values are SOURCE_ACTIVITY_LATCH , SOURCE_FLIP_FLOP , SOURCE_PIO , and DONT_CHANGE ) | |
polarity | the polarity selection for the conditional check (valid values are POLARITY_ZERO , POLARITY_ONE , and DONT_CHANGE ) | |
state | current state of the device returned from readDevice() |
byte [] channelAccess | ( | byte[] | inbuffer, | |
boolean | toggleRW, | |||
boolean | readInitially, | |||
int | CRCMode, | |||
int | channelMode, | |||
boolean | clearActivity, | |||
boolean | interleave | |||
) | throws OneWireException, OneWireIOException |
Accesses the PIO channels to sense the logical status of the output node. This method supports all the modes of communication with the part as described in the datasheet for the DS2406/2407.
inbuffer | The input buffer. Depending on the other options chosen to this method, this will contain data to be written to the channels or it will hold space for data that will be read. | |
toggleRW | By selecting toggleRW to be true , the part will alternately read and write bytes from and to this channel. Setting toggleRW to false means that only one operation will occur, whichever operation is selected by readInitially . NOTE: When toggleRW is true the 'read' bytes are automatically provided and only the results of the read bytes are returned. | |
readInitially | If readInitially is true , the first operation to occur will be a read, else it will be a write. If toggleRW is false , the operation chosen by this flag is the only operation that will occur. If toggleRW is true , this operation is the one that will occur first, then the other will occur. For example, if toggleRW is true and readInitially is false (and you only have one channel communication), 8 bits will be written to channel A and then 8 bits will be read from channel A. | |
CRCMode | The 2406/7 supports 4 CRC generation modes for error detection when performing channel access. This argument should have one of the following values: Invalid values will be masked to valid values. The CRC is 16 bits, and does not get passed back with the output. This method returns null on a CRC failure. | |
channelMode | The 2406/7 supports 3 modes of channel communication. This argument should take one of the following values: If CHANNEL_BOTH is selected, data is written and read from the input buffer to the two channels. See the datasheet for a description of operation in this mode. If communicating with both channels, it is up to the caller to format the data correctly in the input buffer so the correct channel gets the correct data. Similarly, any return data must be parsed by the user. | |
clearActivity | true to reset the activity latch | |
interleave | The value for the Interleave Control bit. If true , operates in synchronous mode. If false , operates in asynchronous mode. See the datasheet for a discussion of asynchronous and synchronous mode. This argument only matters if communicating with both channels. |
OneWireIOException | on a 1-Wire communication error such as reading an incorrect CRC from a 1-Wire device. 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 |
final byte SOURCE_ACTIVITY_LATCH = (byte) 0x02 [static] |
Used to set the source
to the activity latch for conditional searches in the setSearchConditions()
method.
final byte SOURCE_FLIP_FLOP = (byte) 0x04 [static] |
Used to set the source
to the flip-flop state for conditional searches in the setSearchConditions()
method.
final byte SOURCE_PIO = (byte) 0x06 [static] |
Used to set the source
to the PIO status for conditional searches in the setSearchConditions()
method.
final byte POLARITY_ZERO = 0x00 [static] |
Used to set the polarity
to logical '0' for conditional search checking in the setSearchConditions()
method.
final byte POLARITY_ONE = 0x01 [static] |
Used to set the polarity
to logical '1' for conditional search checking in the setSearchConditions()
method.
final byte CHANNEL_NONE = 0x00 [static] |
Used to select neither channel as the source for alarm conditions in the setSearchConditions()
method.
final byte DONT_CHANGE = (byte)0x0ff [static] |
Used for options in the setSearchConditions()
to make sure the specified option is not changes from its current value.
final byte CHANNEL_A_ONLY = 0x04 [static] |
channelMode
for the channelAccess
method.
Selects Channel A (channel 0) for communication. Also used to select Channel A as the source for alarm conditions in the setSearchConditions()
method.
setSearchConditions(byte,byte,byte,byte[])
final byte CHANNEL_B_ONLY = 0x08 [static] |
channelMode
for the channelAccess
method.
Selects Channel B (channel 1) for communication. Also used to select Channel B as the source for alarm conditions in the setSearchConditions()
method.
setSearchConditions(byte,byte,byte,byte[])
final byte CHANNEL_BOTH = 0x0c [static] |
channelMode
for the channelAccess
method.
Selects both Channel A and B (channel 0 and 1) for communication. Also used to select both channels as the source for alarm conditions in the setSearchConditions()
method.
setSearchConditions(byte,byte,byte,byte[])
final byte CRC_DISABLE = 0x00 [static] |
CRCMode
for the channelAccess
method.
Requests no CRC generation by the DS2406/2407.
final byte CRC_EVERY_BYTE = 0x01 [static] |
CRCMode
for the channelAccess
method.
Requests CRC generation after every byte transmitted.
final byte CRC_EVERY_8_BYTES = 0x02 [static] |
CRCMode
for the channelAccess
method.
Requests CRC generation after every 8 bytes transmitted.
final byte CRC_EVERY_32_BYTES = 0x03 [static] |
CRCMode
for the channelAccess
method.
Requests CRC generation after every 32 bytes transmitted.