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

service: Add create_nidaqmx_task(s) API #432

Merged
merged 3 commits into from
Oct 5, 2023

Conversation

bkeryan
Copy link
Collaborator

@bkeryan bkeryan commented Oct 4, 2023

What does this Pull Request accomplish?

Add reservation.create_nidaqmx_task(s).

Why should this Pull Request be merged?

Part of new session management API.

What testing has been done?

Ran new unit tests.
Updated DAQmx example to use new API (not part of this PR).

@bkeryan
Copy link
Collaborator Author

bkeryan commented Oct 4, 2023

Example:

diff --git a/examples/nidaqmx_analog_input/measurement.py b/examples/nidaqmx_analog_input/measurement.py
index c22569e..629f562 100644
--- a/examples/nidaqmx_analog_input/measurement.py
+++ b/examples/nidaqmx_analog_input/measurement.py
@@ -49,24 +49,19 @@ def measure(pin_name: str, sample_rate: float, number_of_samples: int) -> Tuple[
         sample_rate,
         number_of_samples,
     )
-    session_management_client = create_session_management_client(measurement_service)
-    with session_management_client.reserve_session(
-        context=measurement_service.context.pin_map_context, pin_or_relay_names=[pin_name]
-    ) as reservation:
-        task: Optional[nidaqmx.Task] = None
-
-        def cancel_callback() -> None:
-            logging.info("Canceling measurement")
-            task_to_abort = task
-            if task_to_abort is not None:
-                task_to_abort.control(TaskMode.TASK_ABORT)
-
-        measurement_service.context.add_cancel_callback(cancel_callback)
-
-        grpc_device_channel = get_grpc_device_channel(measurement_service, nidaqmx, service_options)
-        with create_task(reservation.session_info, grpc_device_channel) as task:
-            if not reservation.session_info.session_exists:
-                task.ai_channels.add_ai_voltage_chan(reservation.session_info.channel_list)
+    with measurement_service.context.reserve_session(pin_name) as reservation:
+        with reservation.create_nidaqmx_task() as session_info:
+            task = session_info.session
+            if not session_info.session_exists:
+                task.ai_channels.add_ai_voltage_chan(session_info.channel_list)
+
+            def cancel_callback() -> None:
+                logging.info("Canceling measurement")
+                task_to_abort = task
+                if task_to_abort is not None:
+                    task_to_abort.control(TaskMode.TASK_ABORT)
+
+            measurement_service.context.add_cancel_callback(cancel_callback)

             task.timing.cfg_samp_clk_timing(
                 rate=sample_rate,
diff --git a/examples/nidaqmx_analog_input/pyproject.toml b/examples/nidaqmx_analog_input/pyproject.toml
index 71b60fb..05a898c 100644
--- a/examples/nidaqmx_analog_input/pyproject.toml
+++ b/examples/nidaqmx_analog_input/pyproject.toml
@@ -7,7 +7,7 @@ authors = ["National Instruments"]
 [tool.poetry.dependencies]
 python = "^3.8"
 nidaqmx = { version = ">=0.8.0", extras = ["grpc"] }
-ni-measurementlink-service = {version = "^1.1.0"}
+ni-measurementlink-service = {version = "^1.1.0", extras = ["nidaqmx"]}
 click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558

 [tool.poetry.group.dev.dependencies]
@@ -15,7 +15,7 @@ mypy = ">=1.0"
 grpc-stubs = "^1.53"
 # Uncomment to use prerelease dependencies.
 # nidaqmx = { git = "https://github.com/ni/nidaqmx-python.git", branch = "master", extras = ["grpc"]}
-# ni-measurementlink-service = {path = "../..", develop = true}
+ni-measurementlink-service = {path = "../..", develop = true, extras = ["nidaqmx"]}

 [build-system]
 requires = ["poetry-core>=1.2.0"]

Base automatically changed from users/bkeryan/create-driver-specific-sessions to main October 5, 2023 21:28
@bkeryan bkeryan force-pushed the users/bkeryan/create-nidaqmx-sessions branch from bc80c4a to 01159d4 Compare October 5, 2023 21:30
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Test Results

       30 files  ±  0       30 suites  ±0   12m 24s ⏱️ +34s
     338 tests +  3     271 ✔️ +  3       67 💤 ±  0  0 ±0 
10 110 runs  +90  7 565 ✔️ +45  2 545 💤 +45  0 ±0 

Results for commit cbacc8f. ± Comparison against base commit 8ea277b.

@bkeryan bkeryan merged commit 09628af into main Oct 5, 2023
20 checks passed
@bkeryan bkeryan deleted the users/bkeryan/create-nidaqmx-sessions branch October 5, 2023 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants