跳轉到

GPIO

GPIO 回讀、靜態驅動、定時脈衝與脈衝寬度觸發設定位於 AqProtocolExerciser。從 aqpxlib.gpioaqpxlib 匯入列舉與 payload 型別——不要從 aqpxlib.message 匯入。

公開匯出

名稱 種類 用途
PxIoState enum set_gpio_state、脈衝邊緣與回報接腳狀態的準位
PxGpioWidthTriggerMode enum set_gpio_trigger(..., mode=...)
PxGpioPinState message get_gpio_state 的回傳型別
PxGpioTriggerEvent message 處理 gpio_trigger 時的 event_msg.global_event.gpio_trigger

PxIoState

Logical I/O state for a single GPIO line.

單一 GPIO 線路的邏輯準位。

成員 意義
LOW 驅動或取樣為低
HIGH 驅動或取樣為高
HIGH_Z 高阻抗(未主動驅動)

PxGpioWidthTriggerMode

set_gpio_trigger 的寬度條件選擇器。

成員 意義
TRIGGER_PULSE_WIDTH_IN_RANGE 寬度落在 [min_duration_ns, max_duration_ns] 內時觸發(搭配 low_pulse / high_pulse)
TRIGGER_PULSE_WIDTH_OUT_OF_RANGE 寬度落在該視窗外時觸發

PxGpioPinState

PxGpioPinState(
    pin_idx: int = uint32_field(1),
    output_state: Optional[PxIoState] = enum_field(2, optional=True),
    input_state: Optional[PxIoState] = enum_field(3, optional=True),
)

get_gpio_state(gpio_idx=…) 回傳的單一接腳快照。

欄位 意義
pin_idx 接腳索引
output_state 驅動準位(未驅動/未知時為 None)
input_state 取樣輸入(無法取得時為 None)

PxGpioTriggerEvent

PxGpioTriggerEvent(
    pin_idx: int = uint32_field(1),
    pulse_duration: int = uint64_field(2),
    pulse_polarity: bool = bool_field(3),
)

gpio_trigger 處理函式的 payload(PxEventMsg.global_event.gpio_trigger)。

欄位 意義
pin_idx 符合條件的接腳
pulse_duration 寬度,單位為奈秒
pulse_polarity 偵測到的極性

Exerciser 方法

AqProtocolExerciser

AqProtocolExerciser(
    generation: str = "PX2K", host: str = "localhost", port: int = 60600
)

AqProtocolExerciser class.

METHOD DESCRIPTION
get_gpio_state

Read electrical state for one GPIO pin.

set_gpio_state

Drive a static logic level on one GPIO pin.

send_gpio_pulse

Emit one pulse: idle → active_state for active_time_nsidle_state.

set_gpio_trigger

Configure GPIO pulse-width triggering (fires gpio_trigger global events).

get_gpio_state

get_gpio_state(gpio_idx: int) -> PxGpioPinState

Read electrical state for one GPIO pin.

The instrument returns status for all pins; this method selects gpio_idx.

PARAMETER DESCRIPTION

gpio_idx

Index of the pin to read.

TYPE: int

RETURNS DESCRIPTION
PxGpioPinState

pin_idx plus optional output_state (driven level)

TYPE: PxGpioPinState

PxGpioPinState

and input_state (sampled level).

RAISES DESCRIPTION
ValueError

If gpio_idx is negative or not present in the reply.

set_gpio_state

set_gpio_state(gpio_idx: int, state: PxIoState) -> None

Drive a static logic level on one GPIO pin.

PARAMETER DESCRIPTION

gpio_idx

Pin index to drive.

TYPE: int

state

Target level (see PxIoState: LOW, HIGH, HIGH_Z).

TYPE: PxIoState

Note

The server may reject the operation if the pin is owned by another protocol.

send_gpio_pulse

Emit one pulse: idle → active_state for active_time_nsidle_state.

Supported only on GPIO indices 8 and 9. Pulse width must be greater than 5 ns and less than 1 second.

PARAMETER DESCRIPTION

gpio_idx

Pin index; must be 8 or 9.

TYPE: int

active_state

Level during the active portion of the pulse.

TYPE: PxIoState

idle_state

Level after the pulse completes.

TYPE: PxIoState

active_time_ns

Width of the active portion in nanoseconds.

TYPE: int

RAISES DESCRIPTION
ValueError

If gpio_idx is not 8 or 9, or active_time_ns is outside (5, 1_000_000_000).

set_gpio_trigger

set_gpio_trigger(
    gpio_idx: int,
    min_duration_ns: int,
    max_duration_ns: int,
    low_pulse: bool = False,
    high_pulse: bool = False,
    mode: PxGpioWidthTriggerMode = TRIGGER_PULSE_WIDTH_IN_RANGE,
) -> None

Configure GPIO pulse-width triggering (fires gpio_trigger global events).

Supported only on GPIO indices 8 and 9. Both duration bounds must be greater than 5 ns and less than 1 second.

PARAMETER DESCRIPTION

gpio_idx

Pin index; must be 8 or 9.

TYPE: int

min_duration_ns

Minimum pulse width for the condition (nanoseconds).

TYPE: int

max_duration_ns

Maximum pulse width for the condition (nanoseconds).

TYPE: int

low_pulse

Include low-going pulses when True.

TYPE: bool DEFAULT: False

high_pulse

Include high-going pulses when True.

TYPE: bool DEFAULT: False

mode

TRIGGER_PULSE_WIDTH_IN_RANGE or TRIGGER_PULSE_WIDTH_OUT_OF_RANGE.

TYPE: PxGpioWidthTriggerMode DEFAULT: TRIGGER_PULSE_WIDTH_IN_RANGE

RAISES DESCRIPTION
ValueError

If gpio_idx is invalid or durations are out of range.