|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.dalsemi.onewire.container.OneWireContainer | +--com.dalsemi.onewire.container.OneWireContainer12
1-Wire® container for a Dual Addressable Switch, DS2406 or DS2407. This container encapsulates the functionality of the 1-Wire family type 12 (hex). The DS2406 replaces the DS2407, but does not have hidden mode or user programmable power-on settings.
The memory can be accessed through the objects that are returned
from the getMemoryBanks
method.
MemoryBank
,
PagedMemoryBank
,
OTPMemoryBank
MemoryBank
,
PagedMemoryBank
,
OTPMemoryBank
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.
OneWireContainer
to enumerate the MemoryBanks.
MemoryBank
and
PagedMemoryBank
for bank specific operations.
DS2405
, a single addressable switch (OneWireContainer05).
OneWireSensor
,
SwitchContainer
,
OneWireContainer05
Field Summary | |
static byte |
CHANNEL_A_ONLY
channelMode for the channelAccess method. |
static byte |
CHANNEL_B_ONLY
channelMode for the channelAccess method. |
static byte |
CHANNEL_BOTH
channelMode for the channelAccess method. |
static byte |
CHANNEL_NONE
Used to select neither channel as the source for alarm conditions in the setSearchConditions() method. |
static byte |
CRC_DISABLE
CRCMode for the channelAccess method. |
static byte |
CRC_EVERY_32_BYTES
CRCMode for the channelAccess method. |
static byte |
CRC_EVERY_8_BYTES
CRCMode for the channelAccess method. |
static byte |
CRC_EVERY_BYTE
CRCMode for the channelAccess method. |
static byte |
DONT_CHANGE
Used for options in the setSearchConditions() to
make sure the specified option is not changes from its current
value. |
static byte |
POLARITY_ONE
Used to set the polarity to logical '1' for conditional search
checking in the setSearchConditions() method. |
static byte |
POLARITY_ZERO
Used to set the polarity to logical '0' for conditional search
checking in the setSearchConditions() method. |
static byte |
SOURCE_ACTIVITY_LATCH
Used to set the source to the activity latch for
conditional searches in the setSearchConditions() method. |
static byte |
SOURCE_FLIP_FLOP
Used to set the source to the flip-flop state for
conditional searches in the setSearchConditions() method. |
static byte |
SOURCE_PIO
Used to set the source to the PIO status for
conditional searches in the setSearchConditions() method. |
Constructor Summary | |
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. |
Method Summary | |
byte[] |
channelAccess(byte[] inbuffer,
boolean toggleRW,
boolean readInitially,
int CRCMode,
int channelMode,
boolean clearActivity,
boolean interleave)
Accesses the PIO channels to sense the logical status of the output node. |
void |
clearActivity()
Clears the activity latches the next time possible. |
String |
getAlternateNames()
Retrieves the alternate Dallas Semiconductor part numbers or names. |
String |
getDescription()
Gets a short description of the function of this iButton or 1-Wire Device type. |
boolean |
getLatchState(int channel,
byte[] state)
Checks the latch state of the indicated channel. |
boolean |
getLevel(int channel,
byte[] state)
Checks the sensed level on the indicated channel. |
Enumeration |
getMemoryBanks()
Gets an enumeration of memory bank instances that implement one or more of the following interfaces: MemoryBank ,
PagedMemoryBank ,
and OTPMemoryBank . |
String |
getName()
Gets the Dallas Semiconductor part number of the iButton or 1-Wire Device as a java.lang.String . |
int |
getNumberChannels(byte[] state)
Gets the number of channels supported by this switch. |
boolean |
getSensedActivity(int channel,
byte[] state)
Checks if the indicated channel has experienced activity. |
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 |
isHighSideSwitch()
Checks if the channels of this switch are 'high side' switches. |
boolean |
isPowerSupplied(byte[] state)
Checks to see how the DS2406 is being supplied with power. |
boolean |
onlySingleChannelOn()
Checks if the channels of this switch require that only one channel is on at any one time. |
byte[] |
readDevice()
Retrieves the 1-Wire device sensor state. |
void |
setLatchState(int channel,
boolean latchState,
boolean doSmart,
byte[] state)
Sets the latch state of the indicated channel. |
void |
setSearchConditions(byte channel,
byte source,
byte polarity,
byte[] state)
Programs the Conditional Search options for the DS2406/2407. |
void |
setSpeedCheck(boolean doSpeedCheck)
Directs the container to avoid the calls to doSpeed() in methods that communicate with the Thermocron. |
void |
writeDevice(byte[] state)
Writes the 1-Wire device sensor state that have been changed by 'set' methods. |
Methods inherited from class com.dalsemi.onewire.container.OneWireContainer |
doSpeed, equals, getAdapter, getAddress, getAddressAsLong, getAddressAsString, getMaxSpeed, hashCode, isAlarming, isPresent, setSpeed, setupContainer, setupContainer, setupContainer, toString |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final byte SOURCE_ACTIVITY_LATCH
source
to the activity latch for
conditional searches in the setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte SOURCE_FLIP_FLOP
source
to the flip-flop state for
conditional searches in the setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte SOURCE_PIO
source
to the PIO status for
conditional searches in the setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte POLARITY_ZERO
polarity
to logical '0' for conditional search
checking in the setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte POLARITY_ONE
polarity
to logical '1' for conditional search
checking in the setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte CHANNEL_NONE
setSearchConditions()
method.setSearchConditions(byte,byte,byte,byte[])
public static final byte DONT_CHANGE
setSearchConditions()
to
make sure the specified option is not changes from its current
value.setSearchConditions(byte,byte,byte,byte[])
public static final byte CHANNEL_A_ONLY
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.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
,
setSearchConditions(byte,byte,byte,byte[])
public static final byte CHANNEL_B_ONLY
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.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
,
setSearchConditions(byte,byte,byte,byte[])
public static final byte CHANNEL_BOTH
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.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
,
setSearchConditions(byte,byte,byte,byte[])
public static final byte CRC_DISABLE
CRCMode
for the channelAccess
method.
Requests no CRC generation by the DS2406/2407.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
public static final byte CRC_EVERY_BYTE
CRCMode
for the channelAccess
method.
Requests CRC generation after every byte transmitted.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
public static final byte CRC_EVERY_8_BYTES
CRCMode
for the channelAccess
method.
Requests CRC generation after every 8 bytes transmitted.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
public static final byte CRC_EVERY_32_BYTES
CRCMode
for the channelAccess
method.
Requests CRC generation after every 32 bytes transmitted.channelAccess(byte[],boolean,boolean,int,int,boolean,boolean)
Constructor Detail |
public OneWireContainer12()
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.setupContainer(DSPortAdapter,byte[])
,
OneWireContainer12(DSPortAdapter,byte[])
,
OneWireContainer12(DSPortAdapter,long)
,
OneWireContainer12(DSPortAdapter,String)
public OneWireContainer12(DSPortAdapter sourceAdapter, byte[] newAddress)
OneWireContainer
for communication with a DS2406/2407.sourceAdapter
- adapter object required to communicate with
this 1-Wire devicenewAddress
- address of this DS2406/2407OneWireContainer12()
,
OneWireContainer12(DSPortAdapter,long)
,
OneWireContainer12(DSPortAdapter,String)
public OneWireContainer12(DSPortAdapter sourceAdapter, long newAddress)
OneWireContainer
for communication with a DS2406/2407.sourceAdapter
- adapter object required to communicate with
this 1-Wire devicenewAddress
- address of this DS2406/2407OneWireContainer12()
,
OneWireContainer12(DSPortAdapter,byte[])
,
OneWireContainer12(DSPortAdapter,String)
public OneWireContainer12(DSPortAdapter sourceAdapter, String newAddress)
OneWireContainer
for communication with a DS2406/2407.sourceAdapter
- adapter object required to communicate with
this 1-Wire devicenewAddress
- address of this DS2406/2407OneWireContainer12()
,
OneWireContainer12(DSPortAdapter,byte[])
,
OneWireContainer12(DSPortAdapter,long)
Method Detail |
public String getName()
java.lang.String
.
For example "DS1992".getName
in class OneWireContainer
public String getAlternateNames()
getAlternateNames
in class OneWireContainer
public String getDescription()
getDescription
in class OneWireContainer
public Enumeration getMemoryBanks()
MemoryBank
,
PagedMemoryBank
,
and OTPMemoryBank
.getMemoryBanks
in class OneWireContainer
Enumeration
of memory bankspublic boolean isPowerSupplied(byte[] state)
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 poweredOneWireSensor.readDevice()
public int getNumberChannels(byte[] state)
getNumberChannels(byte[])
- 1)]. Note that
all devices of the same family will not necessarily have the
same number of channels.getNumberChannels
in interface SwitchContainer
state
- current state of the device returned from readDevice()
OneWireSensor.readDevice()
public boolean isHighSideSwitch()
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.isHighSideSwitch
in interface SwitchContainer
true
if the switch is a 'high side' switch,
false
if the switch is a 'low side' switchgetLatchState(int,byte[])
public boolean hasActivitySensing()
true
then the
method getSensedActivity(int,byte[])
can be used.hasActivitySensing
in interface SwitchContainer
true
if channels support activity sensinggetSensedActivity(int,byte[])
,
clearActivity()
public boolean hasLevelSensing()
true
then the
method getLevel(int,byte[])
can be used.hasLevelSensing
in interface SwitchContainer
true
if channels support level sensinggetLevel(int,byte[])
public boolean hasSmartOn()
true
then the
method setLatchState(int,boolean,boolean,byte[])
can be used with the doSmart
parameter true
.hasSmartOn
in interface SwitchContainer
true
if channels support 'smart on'setLatchState(int,boolean,boolean,byte[])
public boolean onlySingleChannelOn()
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.onlySingleChannelOn
in interface SwitchContainer
true
if only one channel can be on at a time.setLatchState(int,boolean,boolean,byte[])
public boolean getLevel(int channel, byte[] state)
hasLevelSensing()
.
Level sensing means that the device can sense the logic
level on its PIO pin.getLevel
in interface SwitchContainer
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'OneWireSensor.readDevice()
,
hasLevelSensing()
public boolean getLatchState(int channel, byte[] state)
getLatchState
in interface SwitchContainer
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.OneWireSensor.readDevice()
,
isHighSideSwitch()
,
setLatchState(int,boolean,boolean,byte[])
public boolean getSensedActivity(int channel, byte[] state)
clearActivity()
.
To avoid an exception, verify that this device supports activity
sensing by calling the method hasActivitySensing()
.getSensedActivity
in interface SwitchContainer
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 detectedhasActivitySensing()
,
clearActivity()
public 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()
.
clearActivity
in interface SwitchContainer
OneWireSensor.readDevice()
,
getSensedActivity(int,byte[])
public void setLatchState(int channel, boolean latchState, boolean doSmart, byte[] state)
writeDevice()
must be called to finalize
changes to the device. Note that multiple 'set' methods can
be called before one call to writeDevice()
.setLatchState
in interface SwitchContainer
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()
hasSmartOn()
,
getLatchState(int,byte[])
,
OneWireSensor.writeDevice(byte[])
public byte[] readDevice() throws OneWireIOException, OneWireException
readDevice
in interface OneWireSensor
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
adapterpublic void writeDevice(byte[] state) throws OneWireIOException, OneWireException
writeDevice
in interface OneWireSensor
state
- 1-Wire device sensor stateOneWireIOException
- 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
adapterpublic void setSpeedCheck(boolean doSpeedCheck)
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 callOneWireContainer.doSpeed()
public 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()
OneWireSensor.readDevice()
,
OneWireSensor.writeDevice(byte[])
,
CHANNEL_NONE
,
CHANNEL_A_ONLY
,
CHANNEL_B_ONLY
,
CHANNEL_BOTH
,
SOURCE_ACTIVITY_LATCH
,
SOURCE_PIO
,
SOURCE_FLIP_FLOP
,
POLARITY_ONE
,
POLARITY_ZERO
,
DONT_CHANGE
public 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
. 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:
CRC_DISABLE Never generate a CRC
CRC_EVERY_BYTE Generate a CRC after every byte transmission.
CRC_EVERY_8_BYTES Generate a CRC after every 8 bytes.
CRC_EVERY_32_BYTES Generate a CRC after every 32 bytes.
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:
CHANNEL_A_ONLY Only communicate with PIO A
CHANNEL_B_ONLY Only communicate with PIO B
CHANNEL_BOTH Communicate with both PIO's
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 latchinterleave
- 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
adapterCHANNEL_A_ONLY
,
CHANNEL_B_ONLY
,
CHANNEL_BOTH
,
CRC_DISABLE
,
CRC_EVERY_BYTE
,
CRC_EVERY_8_BYTES
,
CRC_EVERY_32_BYTES
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |