Python Library

D88A42 Python Library

Overview

The D88A42 class provides a high-level interface for controlling relays, reading inputs, and setting analog outputs on the D88A42 USB I/O module.

Installation

pip install https://en-z-em.edwardschmitzsoftware.com/Downloads/d88a42-1.0.0-py3-none-any.whl

Basic Usage

from d88a42 import D88A42, Relays

device = D88A42()
if device.connect():
    device.set_digital_output(Relays.R1, True)
    device.disconnect()

Enums

  • DigitalInputs: DI1-DI8
  • Relays: R1-R8
  • AnalogInputs: AI1-AI4
  • AnalogOutputs: AO1, AO2

Digital I/O

  • get_digital_input(channel)
  • get_digital_output(relay)
  • set_digital_output(relay, value)
  • set_relay(channel, value) (alias)

Analog I/O

  • get_analog_input(channel)
  • get_analog_output(channel)
  • set_analog_output(channel, value)

Configuration & Labels

  • save_config(), load_config()
  • set_user_id(channel, name), get_user_id(channel)

Connection

  • connect(): Connect to the device.
  • disconnect(): Stop sampling and close the connection.
  • start(): Load config and begin polling.
  • stop(): Save config and stop polling.
  • reset(): Reset relays and analog outputs to default values.

Sampling

  • start_sampling(interval_ms=250): Start input polling.
  • stop_sampling(): Stop polling.

Function Details

connect()

Attempts to open a connection to the D88A42 device via USB. Returns True if successful.

disconnect()

Stops sampling and closes the connection to the device. Should be called before exiting your application.

start()

Loads configuration from disk, connects to the device, and begins polling input channels.

stop()

Stops polling, saves configuration to disk, and disconnects the device.

reset()

Turns all relays OFF and sets analog outputs to 0.0V.

start_sampling(interval_ms=250)

Begins polling digital and analog input values at a specified interval (milliseconds). Default is 250 ms.

stop_sampling()

Stops the sampling thread. This can reduce CPU usage when inputs do not need monitoring.

get_digital_input(channel)

Returns the boolean state of a digital input channel.

Parameters: channel - one of DigitalInputs enum.

get_digital_output(relay)

Returns the last known state of a relay (True or False).

Parameters: relay - one of Relays enum.

set_digital_output(relay, value)

Sets a relay (digital output) to True (ON) or False (OFF).

Parameters: relay - relay to control. value - boolean.

set_relay(channel, value)

Alias for set_digital_output().

get_analog_input(channel)

Returns the current calibrated analog input value as a float (typically in volts).

Parameters: channel - one of AnalogInputs enum.

get_analog_output(channel)

Returns the last set analog output value.

Parameters: channel - one of AnalogOutputs enum.

set_analog_output(channel, value)

Sets the analog output voltage (0.0-5.0V).

Parameters: channel - analog output to control. value - voltage as float.

save_config()

Saves the current configuration, including user-defined labels, to disk.

load_config()

Loads previously saved configuration from disk and applies it to the instance.

set_user_id(channel, name)

Assigns a friendly name to any channel object (digital, analog, or relay).

Parameters: channel - any channel object. name - string label.

get_user_id(channel)

Retrieves the user-defined name (label) for the specified channel.