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 AI TEDS create channel tests #490

Merged
merged 9 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
504 changes: 463 additions & 41 deletions tests/component/_task_modules/channels/test_ai_channel.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/component/system/test_physical_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def test___invalid_file_path___write_to_teds_from_file___throws_data_error(


def test___valid_file_path___write_to_teds_from_array___throws_config_or_detection_error(
any_x_series_device, teds_file_path
any_x_series_device, voltage_teds_file_path
):
phys_chan = any_x_series_device.ai_physical_chans["ai0"]

with pytest.raises(nidaqmx.DaqError) as exc_info:
phys_chan.write_to_teds_from_file(str(teds_file_path))
phys_chan.write_to_teds_from_file(str(voltage_teds_file_path))

assert exc_info.value.error_code in [
DAQmxErrors.CANT_CONFIGURE_TEDS_FOR_CHAN,
Expand Down
41 changes: 21 additions & 20 deletions tests/component/system/test_physical_channel_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from nidaqmx.constants import TerminalConfiguration, UsageTypeAI
from nidaqmx.error_codes import DAQmxErrors
from nidaqmx.system import PhysicalChannel
from tests.helpers import configure_teds


def test___constructed_physical_channel___get_property___returns_value(init_kwargs):
Expand All @@ -31,14 +32,14 @@ def test___physical_channel___get_bool_property___returns_value(any_x_series_dev


def test___physical_channel_with_teds___get_bit_stream___returns_configured_value(
any_x_series_device, teds_file_path
sim_6363_device, voltage_teds_file_path
):
phys_chans = any_x_series_device.ai_physical_chans
expected_value = numpy.array(VALUES_IN_TED, dtype=numpy.uint8)

phys_chans["ai0"].configure_teds(str(teds_file_path))

assert (phys_chans["ai0"].teds_bit_stream == expected_value).all()
with configure_teds(
sim_6363_device.ai_physical_chans["ai0"], voltage_teds_file_path
) as phys_chan:
assert (phys_chan.teds_bit_stream == expected_value).all()


@pytest.mark.grpc_xfail(reason="Requires NI gRPC Device Server version 2.2 or later")
Expand All @@ -57,30 +58,30 @@ def test___physical_channel___get_int32_array_property___returns_default_value(


def test___physical_channel_with_teds___get_string_property___returns_configured_value(
any_x_series_device, teds_file_path
sim_6363_device, voltage_teds_file_path
):
phys_chans = any_x_series_device.ai_physical_chans
phys_chans["ai0"].configure_teds(str(teds_file_path))

assert phys_chans["ai0"].teds_version_letter == "A"
with configure_teds(
sim_6363_device.ai_physical_chans["ai0"], voltage_teds_file_path
) as phys_chan:
assert phys_chan.teds_version_letter == "A"


def test___physical_channel_with_teds___get_uint32_array_property___returns_configured_value(
any_x_series_device, teds_file_path
sim_6363_device, voltage_teds_file_path
):
phys_chans = any_x_series_device.ai_physical_chans
phys_chans["ai0"].configure_teds(str(teds_file_path))

assert phys_chans["ai0"].teds_template_ids == [30]
with configure_teds(
sim_6363_device.ai_physical_chans["ai0"], voltage_teds_file_path
) as phys_chan:
assert phys_chan.teds_template_ids == [30]


def test___physical_channel_with_teds___get_uint32_property___returns_configured_value(
any_x_series_device, teds_file_path
sim_6363_device, voltage_teds_file_path
):
phys_chans = any_x_series_device.ai_physical_chans
phys_chans["ai0"].configure_teds(str(teds_file_path))

assert phys_chans["ai0"].teds_mfg_id == 17
with configure_teds(
sim_6363_device.ai_physical_chans["ai0"], voltage_teds_file_path
) as phys_chan:
assert phys_chan.teds_mfg_id == 17


VALUES_IN_TED = [
Expand Down
108 changes: 106 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,110 @@ def interpreter(system: nidaqmx.system.System) -> BaseInterpreter:


@pytest.fixture
def teds_file_path(test_assets_directory):
def teds_assets_directory(test_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns the path to TEDS assets."""
return test_assets_directory / "teds"


@pytest.fixture
def voltage_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "Voltage.ted"


@pytest.fixture
def accelerometer_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "Accelerometer.ted"


@pytest.fixture
def bridge_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
# Our normal bridge sensor TEDS file is incompatible with most devices. It
# has a 1ohm bridge resistance.
return teds_assets_directory / "forcebridge.ted"


@pytest.fixture
def force_bridge_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "forcebridge.ted"


@pytest.fixture
def current_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "Current.ted"


@pytest.fixture
def force_iepe_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "ForceSensor.ted"


@pytest.fixture
def microphone_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "Microphone.ted"


@pytest.fixture
def lvdt_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "LVDT.ted"


@pytest.fixture
def rvdt_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "RVDT.ted"


@pytest.fixture
def pressure_bridge_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "pressurebridge.ted"


@pytest.fixture
def torque_bridge_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "torquebridge.ted"


@pytest.fixture
def resistance_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "Resistance.ted"


@pytest.fixture
def rtd_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "TempRTD.ted"


@pytest.fixture
def strain_gage_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "StrainGage.ted"


@pytest.fixture
def thermocouple_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "TempTC.ted"


@pytest.fixture
def thermistor_iex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return teds_assets_directory / "ThermistorIex.ted"


@pytest.fixture
def thermistor_vex_teds_file_path(teds_assets_directory: pathlib.Path) -> pathlib.Path:
"""Returns a TEDS file path."""
return pathlib.Path(test_assets_directory, "teds", "Voltage.ted")
return teds_assets_directory / "ThermistorVex.ted"
17 changes: 17 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""This contains the helpers methods used in the DAQmx tests."""

import contextlib
import pathlib
from typing import Generator

from nidaqmx.system.physical_channel import PhysicalChannel

# Power uses fixed-point scaling, so we have a pretty wide epsilon.
POWER_ABS_EPSILON = 1e-3
Expand All @@ -11,3 +16,15 @@ def generate_random_seed():
# (EnricoMi/publish-unit-test-result-action) report many added/removed
# tests, so use the same random seed every time.
return 42


@contextlib.contextmanager
def configure_teds(
phys_chan: PhysicalChannel, teds_file_path: pathlib.Path
) -> Generator[PhysicalChannel, None, None]:
"""Yields a physical channel with TEDS configured and then clears it after the test is done."""
phys_chan.configure_teds(str(teds_file_path))
try:
yield phys_chan
finally:
phys_chan.clear_teds()
49 changes: 24 additions & 25 deletions tests/legacy/test_teds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from nidaqmx.constants import TEDSUnits, TerminalConfiguration
from tests.helpers import generate_random_seed
from tests.helpers import configure_teds, generate_random_seed


class TestTEDS:
Expand All @@ -14,31 +14,30 @@ class TestTEDS:
"""

@pytest.mark.parametrize("seed", [generate_random_seed()])
def test_create_teds_ai_voltage_chan(self, task, any_x_series_device, seed, teds_file_path):
def test_create_teds_ai_voltage_chan(self, task, sim_6363_device, seed, voltage_teds_file_path):
"""Test to validate TEDS functionality."""
# Reset the pseudorandom number generator with seed.
random.seed(seed)

ai_phys_chan = random.choice(any_x_series_device.ai_physical_chans)

ai_phys_chan.configure_teds(str(teds_file_path))

assert ai_phys_chan.teds_mfg_id == 17
assert ai_phys_chan.teds_model_num == 1
assert ai_phys_chan.teds_version_letter == "A"
assert ai_phys_chan.teds_version_num == 1
assert ai_phys_chan.teds_template_ids == [30]

ai_channel = task.ai_channels.add_teds_ai_voltage_chan(
ai_phys_chan.name,
name_to_assign_to_channel="TEDSVoltageChannel",
terminal_config=TerminalConfiguration.DEFAULT,
min_val=-300.0,
max_val=100.0,
units=TEDSUnits.FROM_TEDS,
)

assert ai_channel.ai_teds_is_teds
assert ai_channel.ai_teds_units == "Kelvin"
assert ai_channel.ai_min == -300.0
assert ai_channel.ai_max == 100.0
with configure_teds(
random.choice(sim_6363_device.ai_physical_chans), voltage_teds_file_path
) as ai_phys_chan:
assert ai_phys_chan.teds_mfg_id == 17
assert ai_phys_chan.teds_model_num == 1
assert ai_phys_chan.teds_version_letter == "A"
assert ai_phys_chan.teds_version_num == 1
assert ai_phys_chan.teds_template_ids == [30]

ai_channel = task.ai_channels.add_teds_ai_voltage_chan(
ai_phys_chan.name,
name_to_assign_to_channel="TEDSVoltageChannel",
terminal_config=TerminalConfiguration.DEFAULT,
min_val=-300.0,
max_val=100.0,
units=TEDSUnits.FROM_TEDS,
)

assert ai_channel.ai_teds_is_teds
assert ai_channel.ai_teds_units == "Kelvin"
assert ai_channel.ai_min == -300.0
assert ai_channel.ai_max == 100.0
Binary file added tests/test_assets/teds/Accelerometer.ted
Binary file not shown.
Binary file added tests/test_assets/teds/Current.ted
Binary file not shown.
Binary file added tests/test_assets/teds/ForceSensor.ted
Binary file not shown.
Binary file added tests/test_assets/teds/LVDT.ted
Binary file not shown.
Binary file added tests/test_assets/teds/Microphone.ted
Binary file not shown.
Binary file added tests/test_assets/teds/RVDT.ted
Binary file not shown.
Binary file added tests/test_assets/teds/Resistance.ted
Binary file not shown.
Binary file added tests/test_assets/teds/StrainGage.ted
Binary file not shown.
Binary file added tests/test_assets/teds/TempRTD.ted
Binary file not shown.
Binary file added tests/test_assets/teds/TempTC.ted
Binary file not shown.
Binary file added tests/test_assets/teds/ThermistorIex.ted
Binary file not shown.
Binary file added tests/test_assets/teds/ThermistorVex.ted
Binary file not shown.
Binary file added tests/test_assets/teds/forcebridge.ted
Binary file not shown.
Binary file added tests/test_assets/teds/pressurebridge.ted
Binary file not shown.
Binary file added tests/test_assets/teds/torquebridge.ted
Binary file not shown.
Loading