Skip to content

Adding Continuous Acquisition Multiple Sample External Trigger example in NI-DMM - #2229

Draft
NI-velmurugan wants to merge 3 commits into
ni:masterfrom
NI-velmurugan:users/velmurugan/add-nidmm-cont-acq-multiple-samples-ext-trig
Draft

NI-velmurugan wants to merge 3 commits into
ni:masterfrom
NI-velmurugan:users/velmurugan/add-nidmm-cont-acq-multiple-samples-ext-trig

Conversation

@NI-velmurugan

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_multiple_samples_ext_trig.py, a Python adaptation of the LabVIEW Cont Acq Multiple Samples - Ext Trig - Ext SampleTrig.vi

What testing has been done?

Manually tested the example using simulated hardware and the real hardware

@NI-velmurugan

Copy link
Copy Markdown
Contributor Author

@divakar-selvam07 this PR ready for your review.

@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.03%. Comparing base (cdbd8f2) to head (ae5f4bd).

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

HEAD has 44 uploads less than BASE
Flag BASE (cdbd8f2) HEAD (ae5f4bd)
nifakeunittests 10 5
nidcpowerunittests 10 5
nidigitalunittests 10 5
nimodinstunittests 10 5
nirfsaunittests 10 5
niscopeunittests 10 5
nitclkunittests 10 5
codegenunittests 2 1
nisesystemtests 1 0
niscopesystemtests 1 0
nidigitalsystemtests 1 0
nidmmsystemtests 1 0
nirfsasystemtests 1 0
nirfsgsystemtests 1 0
nidcpowersystemtests 1 0
nitclksystemtests 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2229      +/-   ##
==========================================
- Coverage   88.11%   80.03%   -8.08%     
==========================================
  Files          88       54      -34     
  Lines       22832    10235   -12597     
==========================================
- Hits        20119     8192   -11927     
+ Misses       2713     2043     -670     
Flag Coverage Δ
codegenunittests 84.78% <ø> (ø)
nidcpowersystemtests ?
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests ?
nidigitalunittests 68.43% <ø> (ø)
nidmmsystemtests ?
nifakeunittests 86.08% <ø> (ø)
nifgensystemtests 94.34% <ø> (ø)
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
nirfsasystemtests ?
nirfsaunittests 63.40% <ø> (ø)
nirfsgsystemtests ?
niscopesystemtests ?
niscopeunittests 43.20% <ø> (ø)
nisesystemtests ?
niswitchsystemtests 81.66% <ø> (ø)
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 NI-velmurugan changed the title Users/velmurugan/add nidmm cont acq multiple samples ext trig Adding Continuous Acquisition Multiple Sample External Trigger example in NI-DMM Oct 21, 2026
def _update_chart(plt, axes, line, measurements, new_samples, samples_fetched):
measurements.extend(new_samples)
samples_fetched += len(new_samples)
# The x-axis keeps absolute sample numbers, so it starts after the samples dropped from the history

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# The x-axis keeps absolute sample numbers, so it starts after the samples dropped from the history
# Keep X coordinates absolute as old readings leave the history buffer.


with nidmm.Session(resource_name=resource_name, options=options) as session:
session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=measurement_range, resolution_digits=digits)
# Trigger and sample trigger slope are not configured: the slope properties and enums are not in the Python API (#875)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# Trigger and sample trigger slope are not configured: the slope properties and enums are not in the Python API (#875)
# Trigger slopes use driver defaults because the public API has no slope configuration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FYR, #875

session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=measurement_range, resolution_digits=digits)
# Trigger and sample trigger slope are not configured: the slope properties and enums are not in the Python API (#875)
session.configure_trigger(trigger_source=nidmm.TriggerSource[trigger_source])
# The sample trigger uses the same source as the trigger; a sample_count of 0 configures a continuous acquisition

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I feel there are too many comments. Let's remove the comments where the code is self-explanatory and only add comments where something needs to be described or explained, as shown above.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The same applies to lines 47 and 49, and comments inside the try block.

total_samples is None or samples_fetched < total_samples
):
backlog, _ = session.read_status()
if backlog > 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For readability, could we handle the idle case first and continue, keeping the fetch-and-update path less nested? Something like

if total_samples is not None:
    # Prevent the last fetch from exceeding the requested total.
     backlog = min(backlog, total_samples - samples_fetched)
if backlog > 0:
    new_samples = session.fetch_multi_point(array_size=backlog)
    samples_fetched = _update_chart(plt, axes, line, measurements, new_samples, samples_fetched)
else:
    # Process chart events while waiting for the next trigger.
    plt.pause(0.001)

def example(resource_name, options, function, measurement_range, digits, trigger_source, total_samples):
# Imported lazily because matplotlib is unavailable on some platforms (e.g. 32-bit Python)
import matplotlib.pyplot as plt

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I understand that the model numbers are not currently handled in the LabVIEW VI, and the errors are being thrown by the driver. But can we handle this gracefully here by providing a meaningful error message when the model is 408x and the external trigger is selected?

# Imported lazily because matplotlib is unavailable on some platforms (e.g. 32-bit Python)
import matplotlib.pyplot as plt

with nidmm.Session(resource_name=resource_name, options=options) as session:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we set reset_device=True here? The VI explicitly does this during initialization, but the Python API defaults to False.

parser.add_argument('-r', '--range', default=10, type=float, help='Specifies the range for the function specified in the Measurement_Function parameter.')
parser.add_argument('-d', '--digits', default=5.5, type=float, help='Specifies the resolution of the measurement in digits.')
parser.add_argument('-t', '--trigger-source', default='EXTERNAL', choices=nidmm.TriggerSource.__members__.keys(), type=str.upper, help='Specifies the trigger source that initiates the acquisition.')
parser.add_argument('--total-samples', default=None, type=int, help='Stops fetching after this many samples and keeps the chart open until its window is closed; omit to run until the chart window is closed or Ctrl+C is pressed.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit:

Suggested change
parser.add_argument('--total-samples', default=None, type=int, help='Stops fetching after this many samples and keeps the chart open until its window is closed; omit to run until the chart window is closed or Ctrl+C is pressed.')
parser.add_argument('--total-samples', default=None, type=int, help='Stops fetching after this many samples and keeps the chart open until its window is closed; omit to run until the chart window is closed.')

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.

3 participants