Digital I/O

The DigitalIO functionality provides low-speed monitoring and control of the same digital I/O pins that can also be controlled by the more powerful DigitalIn and DigitalOut instruments. The API provided here is much simpler to use, but it can only accommodate use-cases that do not require triggering, precise timing, or very fast operation.

Using the digital I/O functionality

To use the DigitalIO functionality you first need to initialize a DwfLibrary instance. Next, you open a specific device. The device’s DigitalIO functionality can now be accessed via its digitalIO attribute, which is an instance of the DigitalIO class:

from pydwf import DwfLibrary
from pydwf.utilities import openDwfDevice

dwf = DwfLibrary()

with openDwfDevice(dwf) as device:

    # Get a reference to the device's DigitalIO functionality.
    digitalIO = device.digitalIO

    # Use the DigitalIO functionality.
    digitalIO.reset()

Important

Both the DigitalIO and DigitalOut instruments provide an API to drive the same digital outputs. The former provides a very simple API that can be used in cases where precise timing or realtime behavior is not relevant, while the latter provides a more powerful, but also more complicated API that provides far greater control over timing.

The rule for which device gets precedence is explained in a topic on the Digilent forum. In summary:

  • For DIO channels where the DigitalIO instrument sets outputEnable to 1, the behavior of the channel is determined by the DigitalIO instrument.

  • For DIO channels where the DigitalIO instrument sets outputEnable to 0, and the output is set to 1, the channel is in high-impedance (‘Z’) state.

  • For DIO channels where the DigitalIO instrument sets outputEnable to 0, and the output is set to 0, the behavior of the channel is determined by the DigitalOut instrument.

Thus, in order to use the DigitalOut instrument for a specific channel, the user must ensure that the DigitalIO instrument sets both the outputEnable and output configuration bits to 0. In most circumstances it is not necessary to do this explicitly, since this is the default setting of the DigitalIO instrument for each channel.

DigitalIO reference

class DigitalIO

The DigitalIO class provides access to the static digital I/O functionality of a DwfDevice.

Attention

Users of pydwf should not create instances of this class directly.

It is instantiated during initialization of a DwfDevice and subsequently assigned to its public digitalIO attribute for access by the user.

The class implements 3 generic methods: reset(), configure(), and status(), and 8 methods that come in both 32- and 64-bits variants, where 32 and 64 refer to the maximum number of digital pins that the methods can handle.

reset() None

Reset all DigitalIO settings to default values.

It sets the digital pins to tri-state (high impedance, not enabled) and output value to zero.

If autoconfiguration is enabled, the values are immediately applied.

Raises:

DwfLibraryError – An error occurred while executing the reset operation.

configure() None

Configure the DigitalIO functionality.

This method transfers the settings to the Digilent Waveforms device. It is not needed if autoconfiguration is enabled.

Raises:

DwfLibraryError – An error occurred while executing the configure operation.

status() None

Read the DigitalIO status and input values from the device to the PC.

The status inquiry methods that follow will return the information that was read from the device when this method was last called.

Note that the DigitalIO functionality is not managed by a state machine, so this method does not return a value.

Raises:

DwfLibraryError – An error occurred while executing the status operation.

outputEnableInfo() int

Get the digital pins that can be enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 32-bits version of this method. For the 64-bits version, see outputEnableInfo64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputEnableSet(output_enable: int) None

Set the digital pins that are enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 32-bits version of this method. For the 64-bits version, see outputEnableSet64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Parameters:

output_enable (int) – A bitmask of pins that will be used as outputs.

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputEnableGet() int

Get the digital pins that are enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 32-bits version of this method. For the 64-bits version, see outputEnableGet64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently configured as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputInfo() int

Get the digital pins that can be used as outputs, i.e., driven high or low, as a bitmask.

This is the 32-bits version of this method. For the 64-bits version, see outputInfo64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputSet(output: int) None

Set the digital pins that are currently driven high as a bitmask.

This is the 32-bits version of this method. For the 64-bits version, see outputSet64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Parameters:

output (int) – A bitmask of pins that will be driven high.

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputGet() int

Get the digital pins that are currently driven high as a bitmask.

This is the 32-bits version of this method. For the 64-bits version, see outputGet64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently set to high.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

pullInfo() Tuple[int, int]

Get pull info.

Raises:

DwfLibraryError – An error occurred while executing the operation.

pullSet(pull_up_mask: int, pull_down_mask: int) None

Set pull-up and pull-down channels.

Raises:

DwfLibraryError – An error occurred while executing the operation.

pullGet() Tuple[int, int]

Get pull up/down configuration.

Raises:

DwfLibraryError – An error occurred while executing the operation.

driveInfo() Tuple[float, float, int, int]

Get drive info.

Raises:

DwfLibraryError – An error occurred while executing the operation.

driveSet(channel: int, amp: float, slew: int) None

Set channel drive.

Raises:

DwfLibraryError – An error occurred while executing the operation.

driveGet(channel: int) Tuple[float, int]

Get channel drive settings.

Raises:

DwfLibraryError – An error occurred while executing the operation.

inputInfo() int

Return the digital pins that can be used for input on the device as a bitmask.

This is the 32-bits version of this method. For the 64-bits version, see inputInfo64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as inputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

inputStatus() int

Return the current state of the digital input pins on the device as a bitmask.

Before calling this method, call the status() method to read the current digital input status from the device.

This is the 32-bits version of this method. For the 64-bits version, see inputStatus64(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently read as high.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputEnableInfo64() int

Get the digital pins that can be enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 64-bits version of this method. For the 32-bits version, see outputEnableInfo(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputEnableSet64(output_enable: int) None

Set the digital pins that are enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 64-bits version of this method. For the 32-bits version, see outputEnableSet(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Parameters:

output_enable (int) – A bitmask of pins that will be used as outputs.

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputEnableGet64() int

Get the digital pins that are enabled for output as a bitmask.

The output enable state of a pin determines if it is driven as an output. If not, it is in high impedance (also known as high Z) mode.

Only digital pins that are used as outputs should be enabled; digital pins that are used as inputs should remain disabled (the default state after reset).

This is the 64-bits version of this method. For the 32-bits version, see outputEnableGet(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently configured as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputInfo64() int

Get the digital pins that can be used as outputs, i.e., driven high or low, as a bitmask.

This is the 64-bits version of this method. For the 32-bits version, see outputInfo(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as outputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputSet64(output: int) None

Set the digital pins that are currently driven high as a bitmask.

This is the 64-bits version of this method. For the 32-bits version, see outputSet(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Parameters:

output (int) – A bitmask of pins that will be driven high.

Raises:

DwfLibraryError – An error occurred while executing the operation.

outputGet64() int

Get the digital pins that are currently driven high as a bitmask.

This is the 64-bits version of this method. For the 32-bits version, see outputGet(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently set to high.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

inputInfo64() int

Return the digital pins that can be used for input on the device as a bitmask.

This is the 64-bits version of this method. For the 32-bits version, see inputInfo(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that can be used as inputs.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

inputStatus64() int

Return the current state of the digital input pins on the device as a bitmask.

Before calling this method, call the status() method to read the current digital input status from the device.

This is the 64-bits version of this method. For the 32-bits version, see inputStatus(). The 32 and 64 bits refer here to the maximum number of digital pins that the methods can handle.

Returns:

A bitmask of pins that are currently read as high.

Return type:

int

Raises:

DwfLibraryError – An error occurred while executing the operation.

property device

Return the DwfDevice instance of which we are an attribute.

This is useful if we have a variable that contains a reference to a DwfDevice attribute, but we need the DwfDevice itself.

Returns:

The DwfDevice instance that this attribute belongs to.

Return type:

DwfDevice