Skip to content

GPIO: read, drive, and pulse

GPIO helpers live on AqProtocolExerciser: they talk directly to the instrument’s GPIO layer (not to a bus device). Import enums and value types from aqpxlib.gpio—you do not need aqpxlib.message for typical scripts.

from aqpxlib import AqProtocolExerciser
from aqpxlib.gpio import GpioState

with AqProtocolExerciser.connect(host="localhost", port=60600) as px:
    ...

Typed reference: GPIO (API).

Logical levels (GpioState)

Use GpioState when driving or interpreting states (PxIoState is a backward-compatible alias):

Member Meaning
GpioState.LOW Driven or sampled low
GpioState.HIGH Driven or sampled high
GpioState.HIGH_Z High impedance (not actively driven)

Read pin state (get_gpio_state)

pin = px.get_gpio_state(gpio_idx=3)

The exerciser returns status for all pins; the library selects gpio_idx and returns a single GpioPinState with:

Field Meaning
pin_idx Pin index (echo of hardware indexing)
output_state Level the instrument is driving (None / unset if not driving)
input_state Last sampled input level (None / unset if unavailable)

If gpio_idx is negative or past the last pin in the response, the library raises ValueError.

Drive a static level (set_gpio_state)

px.set_gpio_state(gpio_idx=3, state=GpioState.HIGH)

This sends a set state operation for one pin. If that GPIO is already assigned to another protocol on the instrument, the server may reject the request.

There is no Python-side restriction on gpio_idx here (unlike pulse); valid indices depend on hardware and firmware.

Send a pulse (send_gpio_pulse)

Emit one pulse: idle → active foractive_time_ns→ idle.

px.send_gpio_pulse(
    gpio_idx=8,
    active_state=GpioState.HIGH,
    idle_state=GpioState.LOW,
    active_time_ns=5000,
)
Constraint Detail
Pins Only gpio_idx 8 or 9 (same as width-trigger tooling).
Width active_time_ns must be greater than 5 ns and less than 1 second (1_000_000_000 ns).

See also: GPIO width trigger for set_gpio_trigger and the gpio_trigger global event.

Related GPIO (API).