From 1ee80b2416809d7d3f89ee0133bc47f231765653 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Mon, 12 Oct 2026 13:52:32 +0000 Subject: [PATCH 1/6] feat: add nidmm cont acq chart multiple samples example --- CHANGELOG.md | 1 + docs/nidmm/examples.rst | 9 + .../nidmm_cont_acq_chart_multiple_samples.py | 169 ++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 86a8d9eb3..f73acd916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -799,6 +799,7 @@ #### [nidmm] Unreleased - Added - Added the `nidmm_measure_ac_volts.py` example. + - Added the `nidmm_cont_acq_chart_multiple_samples.py` example. - (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies. - Changed - Removed diff --git a/docs/nidmm/examples.rst b/docs/nidmm/examples.rst index ec6b3ee3e..72dfbdebd 100644 --- a/docs/nidmm/examples.rst +++ b/docs/nidmm/examples.rst @@ -3,6 +3,15 @@ Examples `You can download all nidmm examples for latest version here `_ +nidmm_cont_acq_chart_multiple_samples.py +---------------------------------------- + +.. literalinclude:: ../../src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(nidmm_cont_acq_chart_multiple_samples.py) `_ + nidmm_fetch_waveform.py ----------------------- diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py new file mode 100644 index 000000000..8c8c49747 --- /dev/null +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -0,0 +1,169 @@ +#!/usr/bin/python + +import argparse +from collections import deque +from contextlib import redirect_stdout +import io +import nidmm +import signal +import sys + + +class LiveChart: + """Live matplotlib chart of a rolling window of measurements with a Stop button. + + `stopped` becomes True when the Stop button is clicked, the window is closed, or Ctrl+C is pressed. + """ + + def __init__(self, title, max_points=250): + import matplotlib.pyplot as plt + from matplotlib.widgets import Button + + self._plt = plt + self.stopped = False + self._y = deque(maxlen=max_points) + self._x = deque(maxlen=max_points) + self._count = 0 + + self.figure, self.axes = plt.subplots() + self.figure.subplots_adjust(bottom=0.3) + (self._line,) = self.axes.plot([], []) + self.axes.set_title(title) + self.axes.set_xlabel('Samples') + self.axes.set_ylabel('Amplitude (Volts)') + self.axes.grid(True) + + self._button = Button(self.figure.add_axes([0.4, 0.05, 0.2, 0.08]), 'Stop') + self._button.on_clicked(self._stop) + self.figure.canvas.mpl_connect('close_event', self._stop) + # Tk swallows KeyboardInterrupt raised inside draw callbacks, so Ctrl+C sets the flag instead. + self._previous_sigint_handler = signal.signal(signal.SIGINT, self._stop) + plt.show(block=False) + + def _stop(self, *_args): + self.stopped = True + + def update(self, measurements): + for value in measurements: + self._x.append(self._count) + self._y.append(value) + self._count += 1 + self._line.set_data(self._x, self._y) + self.axes.relim() + self.axes.autoscale_view() + self._plt.pause(0.001) + + def close(self): + signal.signal(signal.SIGINT, self._previous_sigint_handler) + self._plt.close(self.figure) + + +def print_measurements(measurements): + text = 'Measurements: {}'.format(list(measurements)) + # \r returns to the line start and \033[K erases leftovers from a longer previous line + print('\r' + text + '\033[K', end='', flush=True) + + +def example(resource_name, options, function, measurement_range, digits, fetch_size): + if fetch_size < 1: + raise ValueError('fetch_size must be greater than zero') + + total_samples = 0 + + 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, + ) + # One trigger with sample_count=0 acquires continuously until the session is aborted. + session.configure_multi_point(trigger_count=1, sample_count=0) + + # Opens the live chart window with its Stop button. + chart = LiveChart('NI-DMM continuous acquisition chart multiple samples ({})'.format(function)) + try: + with session.initiate(): + while not chart.stopped: + measurement = session.fetch_multi_point(array_size=fetch_size) + total_samples += len(measurement) + print_measurements(measurement) + chart.update(measurement) + except KeyboardInterrupt: + pass + finally: + chart.close() + + print('\nAcquisition stopped. Total measurements: {}'.format(total_samples)) + + return total_samples + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Configures a continuous multipoint acquisition and fetches measurements using the NI-DMM API.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-n', '--resource-name', default='PXI1Slot2', help='Contains the resource_name of the device to initialize.') + parser.add_argument('-f', '--function', default='DC_VOLTS', choices=nidmm.Function.__members__.keys(), type=str.upper, help='Specifies the measurement_function used to acquire the measurement.') + 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('-s', '--fetch-size', default=4, type=int, help='Specifies the number of measurements to acquire.') + parser.add_argument('-op', '--option-string', default='', type=str, help='Sets the initial value of certain attributes for the session.') + args = parser.parse_args(argsv) + if args.fetch_size < 1: + parser.error('--fetch-size must be greater than zero') + return example(args.resource_name, args.option_string, args.function, args.range, args.digits, args.fetch_size) + + +def main(): + _main(sys.argv[1:]) + + +class _StubChart: + # Simulates the user clicking Stop after two batches. + def __init__(self, title): + self.stopped = False + self._updates = 0 + + def update(self, measurements): + self._updates += 1 + self.stopped = self._updates >= 2 + + def close(self): + pass + + +def test_example(monkeypatch, capsys): + monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _StubChart) + options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } + total_samples = example('Dev1', options, 'DC_VOLTS', 10, 5.5, 4) + assert total_samples == 8 + assert 'Total measurements: 8' in capsys.readouterr().out + + +class _InterruptingChart(_StubChart): + def update(self, measurements): + raise KeyboardInterrupt + + +def test_example_keyboard_interrupt(monkeypatch, capsys): + monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _InterruptingChart) + options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } + total_samples = example('Dev1', options, 'DC_VOLTS', 10, 5.5, 4) + assert total_samples == 4 + assert 'Total measurements: 4' in capsys.readouterr().out + + +def test_main(monkeypatch): + monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _StubChart) + cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe'] + assert _main(cmd_line) == 8 + + +def test_print_measurements(): + output = io.StringIO() + with redirect_stdout(output): + print_measurements([1.0, 2.0]) + print_measurements([3.0, 4.0]) + assert output.getvalue() == '\rMeasurements: [1.0, 2.0]\033[K\rMeasurements: [3.0, 4.0]\033[K' + + +if __name__ == '__main__': + main() From 3d7669bf5467e59c7179011a4c87790d2a5237e7 Mon Sep 17 00:00:00 2001 From: "Selvam, Divakar" Date: Mon, 12 Oct 2026 20:43:30 +0530 Subject: [PATCH 2/6] simplify plotting --- .../nidmm_cont_acq_chart_multiple_samples.py | 166 ++++-------------- 1 file changed, 35 insertions(+), 131 deletions(-) diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py index 8c8c49747..876db0807 100644 --- a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -1,168 +1,72 @@ #!/usr/bin/python import argparse -from collections import deque -from contextlib import redirect_stdout -import io +import matplotlib.pyplot as plt import nidmm -import signal import sys -class LiveChart: - """Live matplotlib chart of a rolling window of measurements with a Stop button. +# Number of most recent measurements kept on the chart +CHART_HISTORY_SIZE = 2048 - `stopped` becomes True when the Stop button is clicked, the window is closed, or Ctrl+C is pressed. - """ - - def __init__(self, title, max_points=250): - import matplotlib.pyplot as plt - from matplotlib.widgets import Button - - self._plt = plt - self.stopped = False - self._y = deque(maxlen=max_points) - self._x = deque(maxlen=max_points) - self._count = 0 - - self.figure, self.axes = plt.subplots() - self.figure.subplots_adjust(bottom=0.3) - (self._line,) = self.axes.plot([], []) - self.axes.set_title(title) - self.axes.set_xlabel('Samples') - self.axes.set_ylabel('Amplitude (Volts)') - self.axes.grid(True) - - self._button = Button(self.figure.add_axes([0.4, 0.05, 0.2, 0.08]), 'Stop') - self._button.on_clicked(self._stop) - self.figure.canvas.mpl_connect('close_event', self._stop) - # Tk swallows KeyboardInterrupt raised inside draw callbacks, so Ctrl+C sets the flag instead. - self._previous_sigint_handler = signal.signal(signal.SIGINT, self._stop) - plt.show(block=False) - - def _stop(self, *_args): - self.stopped = True - - def update(self, measurements): - for value in measurements: - self._x.append(self._count) - self._y.append(value) - self._count += 1 - self._line.set_data(self._x, self._y) - self.axes.relim() - self.axes.autoscale_view() - self._plt.pause(0.001) - - def close(self): - signal.signal(signal.SIGINT, self._previous_sigint_handler) - self._plt.close(self.figure) - - -def print_measurements(measurements): - text = 'Measurements: {}'.format(list(measurements)) - # \r returns to the line start and \033[K erases leftovers from a longer previous line - print('\r' + text + '\033[K', end='', flush=True) - - -def example(resource_name, options, function, measurement_range, digits, fetch_size): - if fetch_size < 1: - raise ValueError('fetch_size must be greater than zero') - - total_samples = 0 +def example(resource_name, options, function, measurement_range, digits, samples_to_fetch, fetch_count=None): 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, - ) - # One trigger with sample_count=0 acquires continuously until the session is aborted. + session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=measurement_range, resolution_digits=digits) + # A sample_count of 0 configures a continuous acquisition session.configure_multi_point(trigger_count=1, sample_count=0) - # Opens the live chart window with its Stop button. - chart = LiveChart('NI-DMM continuous acquisition chart multiple samples ({})'.format(function)) + figure, axes = plt.subplots() + (line,) = axes.plot([]) + axes.set_title('Measurements') + axes.set_xlabel('Samples') + axes.set_ylabel('Amplitude (Volts)') + axes.grid(True) + + measurements = [] + fetches = 0 try: with session.initiate(): - while not chart.stopped: - measurement = session.fetch_multi_point(array_size=fetch_size) - total_samples += len(measurement) - print_measurements(measurement) - chart.update(measurement) + # A fetch_count of None runs until the chart window is closed or Ctrl+C is pressed + while plt.fignum_exists(figure.number) and fetches != fetch_count: + measurements = (measurements + list(session.fetch_multi_point(array_size=samples_to_fetch)))[-CHART_HISTORY_SIZE:] + line.set_data(range(len(measurements)), measurements) + axes.relim() + axes.autoscale_view() + plt.pause(0.001) + fetches += 1 except KeyboardInterrupt: pass - finally: - chart.close() - - print('\nAcquisition stopped. Total measurements: {}'.format(total_samples)) - - return total_samples + plt.close(figure) def _main(argsv): - parser = argparse.ArgumentParser(description='Configures a continuous multipoint acquisition and fetches measurements using the NI-DMM API.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(description='Continuously acquires measurements and displays them on a chart using the NI-DMM API.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-n', '--resource-name', default='PXI1Slot2', help='Contains the resource_name of the device to initialize.') parser.add_argument('-f', '--function', default='DC_VOLTS', choices=nidmm.Function.__members__.keys(), type=str.upper, help='Specifies the measurement_function used to acquire the measurement.') 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('-s', '--fetch-size', default=4, type=int, help='Specifies the number of measurements to acquire.') + parser.add_argument('-s', '--samples-to-fetch', default=4, type=int, help='Specifies the number of measurements to fetch at a time.') + parser.add_argument('--fetch-count', default=None, type=int, help='Stops after this many fetches; omit to run until the chart window is closed or Ctrl+C is pressed.') parser.add_argument('-op', '--option-string', default='', type=str, help='Sets the initial value of certain attributes for the session.') args = parser.parse_args(argsv) - if args.fetch_size < 1: - parser.error('--fetch-size must be greater than zero') - return example(args.resource_name, args.option_string, args.function, args.range, args.digits, args.fetch_size) + example(args.resource_name, args.option_string, args.function, args.range, args.digits, args.samples_to_fetch, args.fetch_count) def main(): _main(sys.argv[1:]) -class _StubChart: - # Simulates the user clicking Stop after two batches. - def __init__(self, title): - self.stopped = False - self._updates = 0 - - def update(self, measurements): - self._updates += 1 - self.stopped = self._updates >= 2 - - def close(self): - pass - - -def test_example(monkeypatch, capsys): - monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _StubChart) +def test_example(): + plt.switch_backend('Agg') # Avoid opening a chart window during the test options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } - total_samples = example('Dev1', options, 'DC_VOLTS', 10, 5.5, 4) - assert total_samples == 8 - assert 'Total measurements: 8' in capsys.readouterr().out - - -class _InterruptingChart(_StubChart): - def update(self, measurements): - raise KeyboardInterrupt - - -def test_example_keyboard_interrupt(monkeypatch, capsys): - monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _InterruptingChart) - options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } - total_samples = example('Dev1', options, 'DC_VOLTS', 10, 5.5, 4) - assert total_samples == 4 - assert 'Total measurements: 4' in capsys.readouterr().out - - -def test_main(monkeypatch): - monkeypatch.setattr(sys.modules[__name__], 'LiveChart', _StubChart) - cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe'] - assert _main(cmd_line) == 8 + example('PXI1Slot2', options, 'DC_VOLTS', 10, 5.5, 4, 2) -def test_print_measurements(): - output = io.StringIO() - with redirect_stdout(output): - print_measurements([1.0, 2.0]) - print_measurements([3.0, 4.0]) - assert output.getvalue() == '\rMeasurements: [1.0, 2.0]\033[K\rMeasurements: [3.0, 4.0]\033[K' +def test_main(): + plt.switch_backend('Agg') # Avoid opening a chart window during the test + cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe', '--fetch-count', '2', ] + _main(cmd_line) if __name__ == '__main__': From 20c6c25e606cb4fa6237728753f3074529f67723 Mon Sep 17 00:00:00 2001 From: "Selvam, Divakar" Date: Mon, 12 Oct 2026 21:58:23 +0530 Subject: [PATCH 3/6] implement minor improvements and include matplotlib in tox env --- build/templates/tox-system_tests.ini.mako | 3 +++ generated/nidmm/tox-system_tests.ini | 1 + .../examples/nidmm_cont_acq_chart_multiple_samples.py | 11 +++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/build/templates/tox-system_tests.ini.mako b/build/templates/tox-system_tests.ini.mako index c2b3d9131..9a06f6c25 100644 --- a/build/templates/tox-system_tests.ini.mako +++ b/build/templates/tox-system_tests.ini.mako @@ -76,6 +76,9 @@ deps = % endif % if module_name == 'nidigital': ${module_name}-system_tests: nisync +% endif +% if module_name == 'nidmm': + ${module_name}-system_tests: matplotlib % endif ${module_name}-system_tests: pytest ${module_name}-system_tests: coverage diff --git a/generated/nidmm/tox-system_tests.ini b/generated/nidmm/tox-system_tests.ini index 7d155899a..ad7c51492 100644 --- a/generated/nidmm/tox-system_tests.ini +++ b/generated/nidmm/tox-system_tests.ini @@ -32,6 +32,7 @@ commands = nidmm-coverage: coverage report --rcfile=../../tools/coverage_system_tests.rc deps = + nidmm-system_tests: matplotlib nidmm-system_tests: pytest nidmm-system_tests: coverage nidmm-system_tests: numpy diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py index 876db0807..0185a850f 100644 --- a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -10,7 +10,7 @@ CHART_HISTORY_SIZE = 2048 -def example(resource_name, options, function, measurement_range, digits, samples_to_fetch, fetch_count=None): +def example(resource_name, options, function, measurement_range, digits, samples_to_fetch, fetch_count): 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) # A sample_count of 0 configures a continuous acquisition @@ -20,7 +20,7 @@ def example(resource_name, options, function, measurement_range, digits, samples (line,) = axes.plot([]) axes.set_title('Measurements') axes.set_xlabel('Samples') - axes.set_ylabel('Amplitude (Volts)') + axes.set_ylabel('Measured value') axes.grid(True) measurements = [] @@ -28,7 +28,9 @@ def example(resource_name, options, function, measurement_range, digits, samples 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 fetches != fetch_count: + while plt.fignum_exists(figure.number) and ( + fetch_count is None or fetches < fetch_count + ): measurements = (measurements + list(session.fetch_multi_point(array_size=samples_to_fetch)))[-CHART_HISTORY_SIZE:] line.set_data(range(len(measurements)), measurements) axes.relim() @@ -37,7 +39,8 @@ def example(resource_name, options, function, measurement_range, digits, samples fetches += 1 except KeyboardInterrupt: pass - plt.close(figure) + finally: + plt.close(figure) def _main(argsv): From 4d53b59d70ab95a076483e32b7ab3f63fc0c17a4 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 13 Oct 2026 06:34:17 +0000 Subject: [PATCH 4/6] Adding fix for testing the examples with matplotlib --- build/templates/tox-system_tests.ini.mako | 2 +- generated/nidmm/tox-system_tests.ini | 2 +- .../nidmm_cont_acq_chart_multiple_samples.py | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build/templates/tox-system_tests.ini.mako b/build/templates/tox-system_tests.ini.mako index 9a06f6c25..6684fce36 100644 --- a/build/templates/tox-system_tests.ini.mako +++ b/build/templates/tox-system_tests.ini.mako @@ -78,7 +78,7 @@ deps = ${module_name}-system_tests: nisync % endif % if module_name == 'nidmm': - ${module_name}-system_tests: matplotlib + ${module_name}-system_tests: matplotlib; platform_machine != "x86" and (sys_platform != "win32" or platform_machine == "AMD64") % endif ${module_name}-system_tests: pytest ${module_name}-system_tests: coverage diff --git a/generated/nidmm/tox-system_tests.ini b/generated/nidmm/tox-system_tests.ini index ad7c51492..81d3ab82e 100644 --- a/generated/nidmm/tox-system_tests.ini +++ b/generated/nidmm/tox-system_tests.ini @@ -32,7 +32,7 @@ commands = nidmm-coverage: coverage report --rcfile=../../tools/coverage_system_tests.rc deps = - nidmm-system_tests: matplotlib + nidmm-system_tests: matplotlib; platform_machine != "x86" and (sys_platform != "win32" or platform_machine == "AMD64") nidmm-system_tests: pytest nidmm-system_tests: coverage nidmm-system_tests: numpy diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py index 0185a850f..c81f20580 100644 --- a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -1,16 +1,20 @@ #!/usr/bin/python import argparse -import matplotlib.pyplot as plt +import collections import nidmm +import pytest import sys # Number of most recent measurements kept on the chart -CHART_HISTORY_SIZE = 2048 +CHART_HISTORY_SIZE = 250 def example(resource_name, options, function, measurement_range, digits, samples_to_fetch, fetch_count): + # 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: session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=measurement_range, resolution_digits=digits) # A sample_count of 0 configures a continuous acquisition @@ -20,10 +24,10 @@ def example(resource_name, options, function, measurement_range, digits, samples (line,) = axes.plot([]) axes.set_title('Measurements') axes.set_xlabel('Samples') - axes.set_ylabel('Measured value') + axes.set_ylabel('Amplitude (volts)') axes.grid(True) - measurements = [] + measurements = collections.deque(maxlen=CHART_HISTORY_SIZE) fetches = 0 try: with session.initiate(): @@ -31,7 +35,7 @@ def example(resource_name, options, function, measurement_range, digits, samples while plt.fignum_exists(figure.number) and ( fetch_count is None or fetches < fetch_count ): - measurements = (measurements + list(session.fetch_multi_point(array_size=samples_to_fetch)))[-CHART_HISTORY_SIZE:] + measurements.extend(session.fetch_multi_point(array_size=samples_to_fetch)) line.set_data(range(len(measurements)), measurements) axes.relim() axes.autoscale_view() @@ -61,12 +65,14 @@ def main(): def test_example(): + plt = pytest.importorskip('matplotlib.pyplot') plt.switch_backend('Agg') # Avoid opening a chart window during the test options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } example('PXI1Slot2', options, 'DC_VOLTS', 10, 5.5, 4, 2) def test_main(): + plt = pytest.importorskip('matplotlib.pyplot') plt.switch_backend('Agg') # Avoid opening a chart window during the test cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe', '--fetch-count', '2', ] _main(cmd_line) From be80a33d38f5c1d919f562143dbd99323aac0289 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 13 Oct 2026 07:09:06 +0000 Subject: [PATCH 5/6] Reverting change on example, and fixing the pipeline error --- build/templates/tox-system_tests.ini.mako | 2 +- generated/nidmm/tox-system_tests.ini | 2 +- src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/templates/tox-system_tests.ini.mako b/build/templates/tox-system_tests.ini.mako index 6684fce36..41e42c05b 100644 --- a/build/templates/tox-system_tests.ini.mako +++ b/build/templates/tox-system_tests.ini.mako @@ -78,7 +78,7 @@ deps = ${module_name}-system_tests: nisync % endif % if module_name == 'nidmm': - ${module_name}-system_tests: matplotlib; platform_machine != "x86" and (sys_platform != "win32" or platform_machine == "AMD64") + ${module_name}-system_tests: matplotlib; sys_platform != "win32" % endif ${module_name}-system_tests: pytest ${module_name}-system_tests: coverage diff --git a/generated/nidmm/tox-system_tests.ini b/generated/nidmm/tox-system_tests.ini index 81d3ab82e..807c05d20 100644 --- a/generated/nidmm/tox-system_tests.ini +++ b/generated/nidmm/tox-system_tests.ini @@ -32,7 +32,7 @@ commands = nidmm-coverage: coverage report --rcfile=../../tools/coverage_system_tests.rc deps = - nidmm-system_tests: matplotlib; platform_machine != "x86" and (sys_platform != "win32" or platform_machine == "AMD64") + nidmm-system_tests: matplotlib; sys_platform != "win32" nidmm-system_tests: pytest nidmm-system_tests: coverage nidmm-system_tests: numpy diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py index c81f20580..8a4d84c6f 100644 --- a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -24,7 +24,7 @@ def example(resource_name, options, function, measurement_range, digits, samples (line,) = axes.plot([]) axes.set_title('Measurements') axes.set_xlabel('Samples') - axes.set_ylabel('Amplitude (volts)') + axes.set_ylabel('Measured value') axes.grid(True) measurements = collections.deque(maxlen=CHART_HISTORY_SIZE) From 0226df172b7e7048d4a8da1a79174b8ccfe23d4a Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 13 Oct 2026 13:08:34 +0000 Subject: [PATCH 6/6] Changes the plotting logic --- .../examples/nidmm_cont_acq_chart_multiple_samples.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py index 8a4d84c6f..288307c03 100644 --- a/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py +++ b/src/nidmm/examples/nidmm_cont_acq_chart_multiple_samples.py @@ -28,6 +28,7 @@ def example(resource_name, options, function, measurement_range, digits, samples axes.grid(True) measurements = collections.deque(maxlen=CHART_HISTORY_SIZE) + total_samples = 0 fetches = 0 try: with session.initiate(): @@ -35,8 +36,11 @@ def example(resource_name, options, function, measurement_range, digits, samples while plt.fignum_exists(figure.number) and ( fetch_count is None or fetches < fetch_count ): - measurements.extend(session.fetch_multi_point(array_size=samples_to_fetch)) - line.set_data(range(len(measurements)), measurements) + new_samples = session.fetch_multi_point(array_size=samples_to_fetch) + measurements.extend(new_samples) + total_samples += len(new_samples) + first_sample = total_samples - len(measurements) + line.set_data(range(first_sample, total_samples), measurements) axes.relim() axes.autoscale_view() plt.pause(0.001)