com.acces.aiousb
Class DigitalIOSubsystem

java.lang.Object
  extended by com.acces.aiousb.DigitalIOSubsystem

public class DigitalIOSubsystem
extends java.lang.Object

Class DigitalIOSubsystem represents the digital I/O subsystem of a device. One accesses this analog output subsystem through its parent object, typically through a method such as dio() (see USB_AI16_Family.dio()).


Field Summary
static int BITS_PER_BYTE
          Number of bits in one byte.
 
Method Summary
 DigitalIOSubsystem configure(boolean[] tristates, boolean[] outputs, boolean[] values)
          Configures the digital I/O ports.
 DigitalIOSubsystem configure(boolean tristate, boolean[] outputs, boolean[] values)
          Configures the digital I/O ports.
 DigitalIOSubsystem getConfiguration(boolean[] tristates, boolean[] outputs)
          Gets the current configuration of the digital I/O ports.
 int getNumChannels()
          Gets the number of digital I/O channels (bits).
 int getNumPorts()
          Gets the number of digital I/O ports (bytes).
 int getNumTristateChannels()
          Gets the number of tristate channels (bits).
 int getNumTristateGroups()
          Gets the number of tristate groups (bytes).
 USBDevice getParent()
          Gets the parent device that this subsystem is part of.
 java.io.PrintStream print(java.io.PrintStream stream)
          Prints the properties of this subsystem.
 boolean read(int channel)
          Reads a single digital input channel.
 boolean[] read(int startChannel, int numChannels)
          Reads multiple digital input channels.
 DigitalIOSubsystem write(int channel, boolean value)
          Writes a single digital output channel.
 DigitalIOSubsystem write(int startChannel, boolean[] values)
          Writes multiple digital output channels.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BITS_PER_BYTE

public static final int BITS_PER_BYTE
Number of bits in one byte. A handy number.

See Also:
Constant Field Values
Method Detail

print

public java.io.PrintStream print(java.io.PrintStream stream)
Prints the properties of this subsystem. Mainly useful for diagnostic purposes.

Parameters:
stream - the print stream where properties will be printed.
Returns:
The print stream.

getNumPorts

public int getNumPorts()
Gets the number of digital I/O ports (bytes).

Returns:
Number of ports, numbered 0 to n-1.

getNumChannels

public int getNumChannels()
Gets the number of digital I/O channels (bits). The number of "channels" is simply equal to the number of ports times the number of channels per port, which is eight.

Returns:
Number of channels, numbered 0 to n-1.

getNumTristateGroups

public int getNumTristateGroups()
Gets the number of tristate groups (bytes).

Returns:
Number of tristate groups, numbered 0 to n-1.

getNumTristateChannels

public int getNumTristateChannels()
Gets the number of tristate channels (bits). The number of "channels" is simply equal to the number of tristate groups times the number of channels per group, which is eight.

Returns:
Number of tristate channels, numbered 0 to n-1.

configure

public DigitalIOSubsystem configure(boolean tristate,
                                    boolean[] outputs,
                                    boolean[] values)
Configures the digital I/O ports.

Parameters:
tristate - true causes all bits on the device to enter tristate (high-impedance) mode; false removes tristate mode. All devices with this feature power up in tristate mode, and tristate mode is changed after the remainder of the configuration has occurred.
outputs - an array of boolean values, one per digital I/O port. Each true value in the array configures the entire corresponding I/O port as an output port; each false value configures the entire corresponding I/O port as an input port.
values - an array of boolean values, one per digital I/O bit, starting with bit 0 of the device (that is, the least significant bit on the lowest numbered port). Each true value in the array sets the corresponding output bit to a "1"; each false value sets the corresponding output bit to a "0." The values are written to the digital output ports before the ports are taken out of tristate mode.
Returns:
This subsystem, useful for chaining together multiple operations.
Throws:
java.lang.IllegalArgumentException
OperationFailedException

configure

public DigitalIOSubsystem configure(boolean[] tristates,
                                    boolean[] outputs,
                                    boolean[] values)
Configures the digital I/O ports. If the device does not support the per-port tristate feature, then configure( boolean tristate, ...) should be used instead, otherwise an exception will be thrown.

Parameters:
tristates - an array of boolean values, one per tristate group. Each true value in the array puts the entire corresponding I/O port into tristate (high-impedance) mode; each false value takes the entire corresponding I/O port out of tristate mode. All devices with this feature power up in tristate mode, and tristate mode is changed after the remainder of the configuration has occurred.
outputs - an array of boolean values, one per digital I/O port. Each true value in the array configures the entire corresponding I/O port as an output port; each false value configures the entire corresponding I/O port as an input port.
values - an array of boolean values, one per digital I/O bit, starting with bit 0 of the device (that is, the least significant bit on the lowest numbered port). Each true value in the array sets the corresponding output bit to a "1"; each false value sets the corresponding output bit to a "0." The values are written to the digital output ports before the ports are taken out of tristate mode.
Returns:
This subsystem, useful for chaining together multiple operations.
Throws:
java.lang.IllegalArgumentException
OperationFailedException

getConfiguration

public DigitalIOSubsystem getConfiguration(boolean[] tristates,
                                           boolean[] outputs)
Gets the current configuration of the digital I/O ports. If the device does not support the per-port tristate feature, then this method should not be used, otherwise an exception will be thrown.

Parameters:
tristates - an array of boolean values, one per tristate group, which will receive the current tristate mode of each tristate group. Each true value returned in the array indicates that the entire corresponding I/O port is in tristate (high-impedance) mode; each false value indicates that the entire corresponding I/O port is not in tristate mode. If this parameter is null, then the tristate configuration is not returned.
outputs - an array of boolean values, one per digital I/O port, which will receive the current output mode of each I/O port. Each true value returned in the array indicates that the entire corresponding I/O port is configured as an output port; each false value indicates that the entire corresponding I/O port is configured as an input port. If this parameter is null, then the output configuration is not returned.
Returns:
This subsystem, useful for chaining together multiple operations.
Throws:
java.lang.IllegalArgumentException
OperationFailedException

read

public boolean read(int channel)
Reads a single digital input channel.

Parameters:
channel - the channel to read.
Returns:
True indicates that the bit is set ("1"); false indicates that the bit is clear ("0").
Throws:
java.lang.IllegalArgumentException
OperationFailedException

read

public boolean[] read(int startChannel,
                      int numChannels)
Reads multiple digital input channels.

Parameters:
startChannel - the first channel to read.
numChannels - the number of channels to read.
Returns:
An array containing the values read from the specified channels. For each channel, true indicates that the bit is set ("1"); false indicates that the bit is clear ("0").
Throws:
java.lang.IllegalArgumentException
OperationFailedException

write

public DigitalIOSubsystem write(int channel,
                                boolean value)
Writes a single digital output channel.

Parameters:
channel - the channel to write.
value - the value to write to the specified channel. True sets the output bit to a "1" and false clears the output bit to a "0".
Returns:
This subsystem, useful for chaining together multiple operations.

write

public DigitalIOSubsystem write(int startChannel,
                                boolean[] values)
Writes multiple digital output channels.

Parameters:
startChannel - the first channel to write.
values - an array containing the values to write to the specified channels. For each channel, true sets the output bit to a "1" and false clears the output bit to a "0".
Returns:
This subsystem, useful for chaining together multiple operations.
Throws:
java.lang.IllegalArgumentException
OperationFailedException

getParent

public USBDevice getParent()
Gets the parent device that this subsystem is part of.

Returns:
The parent device that this subsystem is part of.