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

[PR1] Split the TestStand modules into specific modules for the nidcpower, nidigital and nidaqmx examples #460

Merged
25 changes: 20 additions & 5 deletions examples/nidaqmx_analog_input/NIDAQmxAnalogInput.seq

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
"""Functions to set up and tear down sessions of NI-Scope devices in NI TestStand."""
"""Functions to set up and tear down sessions of NI-DAQmx devices in NI TestStand."""
from typing import Any

import ni_measurementlink_service as nims
import nidaqmx
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _nidaqmx_helpers import create_task


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id


def create_nidaqmx_tasks(sequence_context: Any) -> None:
"""Create and register all NI-DAQmx tasks.

Expand Down
27 changes: 27 additions & 0 deletions examples/nidaqmx_analog_input/teststand_pin_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""TestStand code module for setting up pin maps with MeasurementLink."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/nidcpower_source_dc_voltage/_nidcpower_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import grpc
import ni_measurementlink_service as nims
import nidcpower
from _constants import USE_SIMULATION


def create_session(
session_info: nims.session_management.SessionInformation,
use_simulation: bool,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior: nidcpower.SessionInitializationBehavior = nidcpower.SessionInitializationBehavior.AUTO,
) -> nidcpower.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
if USE_SIMULATION:
if use_simulation:
options["simulate"] = True
options["driver_setup"] = {"Model": "4141"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,11 @@

import ni_measurementlink_service as nims
import nidcpower
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _constants import USE_SIMULATION
from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _nidcpower_helpers import create_session


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id


def create_nidcpower_sessions(sequence_context: Any) -> None:
"""Create and register all NI-DCPower sessions.

Expand Down Expand Up @@ -57,6 +35,7 @@ def create_nidcpower_sessions(sequence_context: Any) -> None:
# Leave session open
_ = create_session(
session_info,
USE_SIMULATION,
grpc_device_channel,
initialization_behavior=nidcpower.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)
Expand All @@ -80,6 +59,7 @@ def destroy_nidcpower_sessions() -> None:
for session_info in reservation.session_info:
session = create_session(
session_info,
USE_SIMULATION,
grpc_device_channel,
initialization_behavior=nidcpower.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)
Expand Down
27 changes: 27 additions & 0 deletions examples/nidcpower_source_dc_voltage/teststand_pin_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""TestStand code module for setting up pin maps with MeasurementLink."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id
40 changes: 32 additions & 8 deletions examples/nidigital_spi/NIDigitalSPI.seq

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,13 @@

import ni_measurementlink_service as nims
import nidigital
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _nidigital_helpers import create_session
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_DIGITAL_PATTERN,
)


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id


def create_nidigital_sessions(sequence_context: Any) -> None:
"""Create and register all NI-Digital sessions.

Expand Down
27 changes: 27 additions & 0 deletions examples/nidigital_spi/teststand_pin_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""TestStand code module for setting up pin maps with MeasurementLink."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport


def update_pin_map(pin_map_path: str, sequence_context: Any) -> str:
"""Update registered pin map contents.

Create and register a pin map if a pin map resource for the specified pin map id is not found.

Args:
pin_map_path:
An absolute or relative path to the pin map file.
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
teststand_support = TestStandSupport(sequence_context)
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
pin_map_client = PinMapClient(grpc_channel=grpc_channel_pool.pin_map_channel)
pin_map_id = pin_map_client.update_pin_map(pin_map_abs_path)

teststand_support.set_active_pin_map_id(pin_map_id)
return pin_map_id
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@


def create_nidcpower_sessions(sequence_context: Any) -> None:
"""Create and register all NI-DCPower sessions."""
"""Create and register all NI-DCPower sessions.

Args:
sequence_context:
The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
with GrpcChannelPoolHelper() as grpc_channel_pool:
session_management_client = nims.session_management.Client(
grpc_channel=grpc_channel_pool.session_management_channel
Expand Down