Skip to content

Adding Continuous Acquisition Chart Multiple Samples example in NI-DMM - #2220

Open
NI-velmurugan wants to merge 20 commits into
ni:masterfrom
NI-velmurugan:users/velmurugan/add-nidmm-cont-acq-chart-multiple-samples
Open

NI-velmurugan wants to merge 20 commits into
ni:masterfrom
NI-velmurugan:users/velmurugan/add-nidmm-cont-acq-chart-multiple-samples

Conversation

@NI-velmurugan

@NI-velmurugan NI-velmurugan commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
    - [ ] I've added tests applicable for this pull request

What does this Pull Request accomplish?

This PR adds nidmm_cont_acq_chart_multiple_samples.py, a Python adaptation of the LabVIEW Cont Acq & Chart Multiple Samples.vi

What testing has been done?

  • Manually tested the example using simulated hardware and the real hardware

@codecov-commenter

codecov-commenter commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.18%. Comparing base (5375937) to head (fb642b9).

❗ There is a different number of reports uploaded between BASE (5375937) and HEAD (fb642b9). Click for more details.

HEAD has 47 uploads less than BASE
Flag BASE (5375937) HEAD (fb642b9)
nitclkunittests 10 5
nifakeunittests 10 5
nimodinstunittests 10 5
nidcpowerunittests 10 5
niscopeunittests 10 5
nidigitalunittests 10 5
nirfsaunittests 10 5
codegenunittests 2 1
niscopesystemtests 1 0
nidigitalsystemtests 1 0
nidmmsystemtests 1 0
nirfsgsystemtests 1 0
nimodinstsystemtests 1 0
nisesystemtests 1 0
niswitchsystemtests 1 0
nidcpowersystemtests 1 0
nirfsasystemtests 1 0
nifgensystemtests 1 0
nitclksystemtests 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2220       +/-   ##
===========================================
- Coverage   88.12%   75.18%   -12.94%     
===========================================
  Files          88       42       -46     
  Lines       22830     6633    -16197     
===========================================
- Hits        20118     4987    -15131     
+ Misses       2712     1646     -1066     
Flag Coverage Δ
codegenunittests 84.78% <ø> (ø)
nidcpowersystemtests ?
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests ?
nidigitalunittests 68.43% <ø> (ø)
nidmmsystemtests ?
nifakeunittests 86.08% <ø> (ø)
nifgensystemtests ?
nimodinstsystemtests ?
nimodinstunittests 94.20% <ø> (ø)
nirfsasystemtests ?
nirfsaunittests 63.37% <ø> (ø)
nirfsgsystemtests ?
niscopesystemtests ?
niscopeunittests 43.20% <ø> (ø)
nisesystemtests ?
niswitchsystemtests ?
nitclksystemtests ?
nitclkunittests 98.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NI-velmurugan

Copy link
Copy Markdown
Contributor Author

The plotting approach in this example follows the existing gRPC Device Server example continuous-acquire-graph-multiple-points.py , which displays the continuous data with matplotlib.

@divakar-selvam07

Copy link
Copy Markdown
Contributor

@jarnoldNI, the PR is ready for your review.

try:
with session.initiate():
# A fetch_count of None runs until the chart window is closed or Ctrl+C is pressed
while plt.fignum_exists(figure.number) and (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally skipped the LabVIEW STOP button behavior to keep the example simple.
The loop stops when the chart window is closed or Ctrl+C is pressed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's certainly precedent for leaving out something like in our Python examples.
niscope_fetch_forever.py terminates its fetch while loop after fetching after a configured number of samples.

This, like that, is a continuous acquisition, so perhaps we should use a similar termination mechanism?
Does your current code update the graph continuously?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to niscope_fetch_forever.py, we now have a termination mechanism using total_samples. The user can configure the total number of samples to acquire, and the acquisition will stop once that count is reached.

If total_samples is not specified, the acquisition will continue until the user terminates it by pressing Ctrl+C or closing the chart window.

Please let me know if this aligns with what you had in mind.

Does your current code update the graph continuously?

Yes, the graph is updated continuously as new measurements are fetched. After each fetch, the newly acquired measurements are added to the chart, and the graph is refreshed to display the latest measurements. The chart maintains a rolling window of the most recent 250 measurements.

@ni-jfitzger ni-jfitzger Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this seems to do basically the same thing.
Not sure how well it meshes with the plotting (the graph may disappear before the user can view it, in practice), but users don't have to pass a value and you've defaulted to keeping the graph open.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. The chart won't disappear when total_samples is reached. After the acquisition stops, the example calls plt.show(), which keeps the final chart on screen until the user closes the window. If total_samples is omitted, it runs until the chart window is closed or Ctrl+C is pressed.

Please let me know if you'd like any changes to this behavior.

@NI-velmurugan NI-velmurugan changed the title feat: add nidmm cont acq chart multiple samples example Adding Continuous Acquisition Chart Multiple Samples example in NI-DMM Oct 12, 2026
@NI-velmurugan
NI-velmurugan marked this pull request as ready for review October 14, 2026 04:54
@ni-jfitzger

ni-jfitzger commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

The plotting approach in this example follows the existing gRPC Device Server example continuous-acquire-graph-multiple-points.py , which displays the continuous data with matplotlib.

Can you post a screenshot of what the plot looks like?

@NI-velmurugan

Copy link
Copy Markdown
Contributor Author

The plotting approach in this example follows the existing gRPC Device Server example continuous-acquire-graph-multiple-points.py , which displays the continuous data with matplotlib.

Can you post a screenshot of what the plot looks like?

Thanks for pointing that out. I've attached screenshots of the plot below with additional details for clarity:

Screenshot 1: Shows the plot generated with Python example.
Screenshot 2: Shows the plot generated with LabVIEW.

Please let me know if there's any other information you'd like me to include.

image image

Comment on lines +23 to +28
figure, axes = plt.subplots()
(line,) = axes.plot([])
axes.set_title('Measurements')
axes.set_xlabel('Samples')
axes.set_ylabel('Measured value')
axes.grid(True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this matplotlib stuff feels like a distraction from the demonstration of how to use nidmm. @marcoskirsch what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit more involved than what we did for the nidaqmx examples:

But that might be because it's doing a chart rather than a single graph.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent was to demonstrate continuous acquisition by fetching measurements in batches and displaying them on a live-updating chart. While this adds some complexity compared to plotting a single acquired dataset, I believe the current implementation is a reasonable approach for demonstrating continuous acquisition and live chart updates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the nidmm usage front and center, I moved all matplotlib code into two private helpers, _create_chart() and _update_chart(). example() now shows only the NI-DMM flow: configure a continuous acquisition, initiate, then fetch batches with fetch_multi_point(). The chart is updated with a single _update_chart() call per batch. Readers can ignore the helpers when learning the driver API.

@NI-velmurugan

Copy link
Copy Markdown
Contributor Author

@ni-jfitzger, I’ve addressed the comments you mentioned. Could you please take a look and let me know if you have any additional suggestions?

Comment on lines +58 to +61
# The last fetch only takes the samples still needed to reach total_samples
samples_in_this_fetch = samples_to_fetch
if total_samples is not None:
samples_in_this_fetch = min(samples_to_fetch, total_samples - samples_fetched)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unnecessary.
This is a continuous acquisition, so I would view samples_to_fetch as a minimum. It should be fine to fetch more samples than needed on the last acquisition.
The only reason I would consider this worth doing is if we were managing a buffer that we need to avoid overflowing.

@NI-velmurugan NI-velmurugan Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I removed the clamp. samples_to_fetch is now a minimum, and the last fetch may return more samples than total_samples needs.

Following your buffer point, each iteration now calls read_status() and fetches max(samples_to_fetch, backlog), capped at 100,000, the per-call maximum for a continuous acquisition. The driver docs say a growing backlog eventually overwrites data and raises an error. Fetching the whole backlog lets the chart catch up if plotting is slower than acquisition.


def _update_chart(plt, axes, line, measurements, new_samples, samples_fetched):
measurements.extend(new_samples)
samples_fetched += len(new_samples)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samples_fetched += len(new_samples)
This statement should happen before _update_chart is called. There's no reason for this function to handle updating that value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved samples_fetched += len(new_samples) into the main loop, before the _update_chart call. _update_chart now only draws the chart and no longer returns a value.

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.

6 participants