-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bkeryan
requested review from
csjall,
pbirkhol-ni,
dixonjoel,
mshafer-NI and
nstokes-nati
as code owners
October 4, 2023 22:18
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"] |
pbirkhol-ni
approved these changes
Oct 5, 2023
Base automatically changed from
users/bkeryan/create-driver-specific-sessions
to
main
October 5, 2023 21:28
bkeryan
force-pushed
the
users/bkeryan/create-nidaqmx-sessions
branch
from
October 5, 2023 21:30
bc80c4a
to
01159d4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).