Repository navigation
Adding Continuous Acquisition Multiple Sample External Trigger example in NI-DMM - #2229
NI-velmurugan wants to merge 3 commits into
Conversation
|
@divakar-selvam07 this PR ready for your review. |
Codecov Report✅ All modified and coverable lines are covered by tests.
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| 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 |
There was a problem hiding this comment.
| # 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) |
There was a problem hiding this comment.
| # 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. |
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.') |
There was a problem hiding this comment.
nit:
| 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.') |
- [ ] I've added tests applicable for this pull requestWhat 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.viWhat testing has been done?
Manually tested the example using simulated hardware and the real hardware