Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for timing APIs #603

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions tests/component/task/test_timing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import pytest

from nidaqmx.constants import (
AcquisitionType,
Edge,
Level,
LineGrouping,
Polarity,
SampleTimingType,
)
from nidaqmx.system import Device
from nidaqmx.task import Task


@pytest.fixture()
def sim_6535_di_single_line_task(task: Task, sim_6535_device: Device) -> Task:
"""Gets DI task."""
task.di_channels.add_di_chan(
sim_6535_device.di_lines[0].name, line_grouping=LineGrouping.CHAN_FOR_ALL_LINES
)
return task


def test___timing___cfg_handshaking___sets_properties(
sim_6535_di_single_line_task: Task,
) -> None:
sim_6535_di_single_line_task.timing.cfg_handshaking_timing(
AcquisitionType.FINITE, samps_per_chan=2000
)
bkeryan marked this conversation as resolved.
Show resolved Hide resolved

assert sim_6535_di_single_line_task.timing.samp_timing_type == SampleTimingType.HANDSHAKE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_mode == AcquisitionType.FINITE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_per_chan == 2000


def test___timing___cfg_change_detection___sets_properties(
sim_6535_di_single_line_task: Task,
) -> None:
sim_6535_di_single_line_task.timing.cfg_change_detection_timing(
"port0/line0:1", "port0/line3:5", AcquisitionType.FINITE, samps_per_chan=2000
)

assert (
sim_6535_di_single_line_task.timing.change_detect_di_rising_edge_physical_chans.name
== "port0/line0, port0/line1"
)
assert (
sim_6535_di_single_line_task.timing.change_detect_di_falling_edge_physical_chans.name
== "port0/line3, port0/line4, port0/line5"
)
assert sim_6535_di_single_line_task.timing.samp_timing_type == SampleTimingType.CHANGE_DETECTION
assert sim_6535_di_single_line_task.timing.samp_quant_samp_mode == AcquisitionType.FINITE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_per_chan == 2000


@pytest.mark.parametrize(
"clk_source, active_edge",
[
("PFI5", Edge.RISING),
("RTSI7", Edge.FALLING),
],
)
def test___timing___cfg_pipelined_samp_clk___sets_properties(
sim_6535_di_single_line_task: Task,
clk_source: str,
active_edge: int,
) -> None:
sim_6535_di_single_line_task.timing.cfg_pipelined_samp_clk_timing(
rate=32000.0,
source=clk_source,
active_edge=active_edge,
sample_mode=AcquisitionType.FINITE,
samps_per_chan=2000,
)

assert sim_6535_di_single_line_task.timing.samp_clk_src == clk_source
assert sim_6535_di_single_line_task.timing.samp_clk_active_edge == active_edge
assert (
sim_6535_di_single_line_task.timing.samp_timing_type
== SampleTimingType.PIPELINED_SAMPLE_CLOCK
)
assert sim_6535_di_single_line_task.timing.samp_quant_samp_mode == AcquisitionType.FINITE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_per_chan == 2000


@pytest.mark.parametrize(
"clk_source, active_edge, pause_when, ready_event_active_level",
[
("PFI5", Edge.RISING, Level.HIGH, Polarity.ACTIVE_HIGH),
("PFI5", Edge.FALLING, Level.HIGH, Polarity.ACTIVE_LOW),
("RTSI7", Edge.FALLING, Level.LOW, Polarity.ACTIVE_LOW),
],
)
def test___timing___cfg_burst_handshaking_import_clock___sets_properties(
sim_6535_di_single_line_task: Task,
clk_source: str,
active_edge: int,
pause_when: int,
ready_event_active_level: int,
) -> None:
sim_6535_di_single_line_task.timing.cfg_burst_handshaking_timing_import_clock(
sample_clk_rate=32000.0,
sample_clk_src=clk_source,
sample_mode=AcquisitionType.FINITE,
samps_per_chan=2000,
sample_clk_active_edge=active_edge,
pause_when=pause_when,
ready_event_active_level=ready_event_active_level,
)

assert sim_6535_di_single_line_task.timing.samp_timing_type == SampleTimingType.BURST_HANDSHAKE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_mode == AcquisitionType.FINITE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_per_chan == 2000
assert sim_6535_di_single_line_task.timing.samp_clk_rate == 32000
assert sim_6535_di_single_line_task.timing.samp_clk_src == clk_source
assert sim_6535_di_single_line_task.timing.samp_clk_active_edge == active_edge
assert sim_6535_di_single_line_task.triggers.pause_trigger.dig_lvl_when == pause_when
assert (
sim_6535_di_single_line_task.export_signals.rdy_for_xfer_event_lvl_active_lvl
== ready_event_active_level
)


@pytest.mark.parametrize(
"clk_outp_term, clk_pulse_polarity, pause_when, ready_event_active_level",
[
("PFI0", Polarity.ACTIVE_HIGH, Level.HIGH, Polarity.ACTIVE_HIGH),
("PFI1", Polarity.ACTIVE_HIGH, Level.HIGH, Polarity.ACTIVE_LOW),
("PFI1", Polarity.ACTIVE_LOW, Level.LOW, Polarity.ACTIVE_LOW),
],
)
def test___timing___cfg_burst_handshaking_export_clock___sets_properties(
sim_6535_di_single_line_task: Task,
clk_outp_term: str,
clk_pulse_polarity: int,
pause_when: int,
ready_event_active_level: int,
) -> None:
sim_6535_di_single_line_task.timing.cfg_burst_handshaking_timing_export_clock(
sample_clk_rate=32000.0,
sample_clk_outp_term=clk_outp_term,
sample_mode=AcquisitionType.FINITE,
samps_per_chan=2000,
sample_clk_pulse_polarity=clk_pulse_polarity,
pause_when=pause_when,
ready_event_active_level=ready_event_active_level,
bkeryan marked this conversation as resolved.
Show resolved Hide resolved
)

assert sim_6535_di_single_line_task.timing.samp_timing_type == SampleTimingType.BURST_HANDSHAKE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_mode == AcquisitionType.FINITE
assert sim_6535_di_single_line_task.timing.samp_quant_samp_per_chan == 2000
assert sim_6535_di_single_line_task.timing.samp_clk_rate == 32000
assert sim_6535_di_single_line_task.export_signals.samp_clk_pulse_polarity == clk_pulse_polarity
assert sim_6535_di_single_line_task.triggers.pause_trigger.dig_lvl_when == pause_when
assert (
sim_6535_di_single_line_task.export_signals.rdy_for_xfer_event_lvl_active_lvl
== ready_event_active_level
)
Loading