From dc608b9ca1084fdf13a2b5380303fb88a7a1ce41 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 27 Oct 2026 07:47:13 +0000 Subject: [PATCH 1/9] Adding Measurement Library example in NI-Scope --- CHANGELOG.md | 1 + build/templates/tox-system_tests.ini.mako | 3 + docs/niscope/examples.rst | 9 ++ generated/niscope/tox-system_tests.ini | 1 + .../examples/niscope_measurement_library.py | 133 ++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 src/niscope/examples/niscope_measurement_library.py diff --git a/CHANGELOG.md b/CHANGELOG.md index cfa7540d47..55a425b3d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1900,6 +1900,7 @@ #### [niscope] Unreleased - Added - (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies. + - Added the `niscope_measurement_library.py` example. - Changed - Removed diff --git a/build/templates/tox-system_tests.ini.mako b/build/templates/tox-system_tests.ini.mako index c2b3d9131d..9c7f07cb3e 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 == 'niscope': + ${module_name}-system_tests: matplotlib; sys_platform != "win32" % endif ${module_name}-system_tests: pytest ${module_name}-system_tests: coverage diff --git a/docs/niscope/examples.rst b/docs/niscope/examples.rst index 71f84c469c..3cbdb11097 100644 --- a/docs/niscope/examples.rst +++ b/docs/niscope/examples.rst @@ -30,6 +30,15 @@ niscope_fetch_into.py :encoding: utf8 :caption: `(niscope_fetch_into.py) `_ +niscope_measurement_library.py +------------------------------ + +.. literalinclude:: ../../src/niscope/examples/niscope_measurement_library.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(niscope_measurement_library.py) `_ + niscope_read.py --------------- diff --git a/generated/niscope/tox-system_tests.ini b/generated/niscope/tox-system_tests.ini index 2f232d27ab..afadc34815 100644 --- a/generated/niscope/tox-system_tests.ini +++ b/generated/niscope/tox-system_tests.ini @@ -39,6 +39,7 @@ commands = deps = niscope-wheel_dep: build + niscope-system_tests: matplotlib; sys_platform != "win32" niscope-system_tests: pytest niscope-system_tests: coverage niscope-system_tests: numpy diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py new file mode 100644 index 0000000000..a44573ec0a --- /dev/null +++ b/src/niscope/examples/niscope_measurement_library.py @@ -0,0 +1,133 @@ +#!/usr/bin/python + +import argparse +import niscope +import pytest +import sys + +_TIMEOUT_ERROR_CODE = -1074126845 # "Maximum time exceeded before the operation completed" + + +def _create_chart(plt): + figure, axes = plt.subplots() + axes.set_title('Waveform Graph') + axes.set_xlabel('Time (s)') + axes.set_ylabel('Amplitude (V)') + axes.grid(True) + figure.tight_layout() + return figure, axes + + +def _update_chart(axes, waveforms): + while len(axes.lines) < len(waveforms): + axes.plot([], [], label=waveforms[len(axes.lines)].channel) + axes.legend(loc='upper right') + for line, waveform in zip(axes.lines, waveforms): + x = [waveform.relative_initial_x + i * waveform.x_increment for i in range(len(waveform.samples))] + # read() returns samples as a memoryview, which matplotlib cannot copy + line.set_data(x, list(waveform.samples)) + axes.relim() + axes.autoscale_view() + + +def example(resource_name, channels, options, vertical_range, vertical_coupling, min_sample_rate, min_record_length, + enforce_realtime, trigger_type, trigger_source, trigger_level, trigger_slope, trigger_coupling, timeout, + scalar_measurement, reference_level_units, low_ref, mid_ref, high_ref, iterations): + import matplotlib.pyplot as plt + + with niscope.Session(resource_name=resource_name, options=options) as session: + session.configure_vertical(range=vertical_range, coupling=niscope.VerticalCoupling[vertical_coupling]) + session.configure_horizontal_timing(min_sample_rate=min_sample_rate, min_num_pts=min_record_length, ref_position=50.0, num_records=1, enforce_realtime=enforce_realtime) + if trigger_type == 'EDGE': + session.configure_trigger_edge(trigger_source, trigger_level, niscope.TriggerCoupling[trigger_coupling], niscope.TriggerSlope[trigger_slope]) + else: + session.configure_trigger_immediate() + + channel = session.channels[channels] + channel.meas_ref_level_units = niscope.RefLevelUnits[reference_level_units] + channel.meas_chan_low_ref_level = low_ref + channel.meas_chan_mid_ref_level = mid_ref + channel.meas_chan_high_ref_level = high_ref + + figure, axes = _create_chart(plt) + + iteration = 0 + try: + # Run until the chart is closed, Ctrl+C is pressed, or the iteration limit is reached. + while plt.fignum_exists(figure.number) and (iterations is None or iteration < iterations): + # The statistics accumulate once per acquisition, so read a new waveform before each fetch. + try: + waveforms = channel.read(num_samples=min_record_length, timeout=timeout) + except niscope.errors.DriverError as e: + if e.code != _TIMEOUT_ERROR_CODE: + raise + print(f'Timed out after {timeout} s waiting for a trigger; check the trigger source and level, or use --trigger-type immediate.') + plt.pause(0.02) + continue + _update_chart(axes, waveforms) + stats = channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) + print(f'Acquisition {iteration}: {scalar_measurement}') + for stat in stats: + print(stat) + iteration += 1 + plt.pause(0.02) + + # Keep the final plot window open after acquisition stops until the user closes it. + if iterations is not None and plt.fignum_exists(figure.number): + plt.show() + except KeyboardInterrupt: + pass + finally: + plt.close(figure) + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Fetches scalar measurements and their statistics from an NI digitizer.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-n', '--resource-name', default='PXI1Slot3', help='Specifies the resource name of the device to initialize') + parser.add_argument('-m', '--scalar-measurement', default='FFT_FREQUENCY', choices=niscope.ScalarMeasurement.__members__.keys(), type=str.upper, help='The scalar measurement to be performed on each fetched waveform.') + parser.add_argument('--reference-level-units', default='PERCENTAGE', choices=niscope.RefLevelUnits.__members__.keys(), type=str.upper, help='Specifies the units of the reference levels.') + parser.add_argument('--low-ref', default=10.0, type=float, help='Stores the low reference level used in many scalar measurements.') + parser.add_argument('--mid-ref', default=50.0, type=float, help='Stores the mid reference level used in many scalar measurements.') + parser.add_argument('--high-ref', default=90.0, type=float, help='Stores the high reference level used in many scalar measurements.') + parser.add_argument('-s', '--min-sample-rate', default=1000000.0, type=float, help='Specify the sampling rate for the acquisition in Samples per second.') + parser.add_argument('-l', '--min-record-length', default=1000, type=int, help='Specifies the minimum number of points you require in the waveform record for each channel.') + parser.add_argument('--enforce-realtime', action=argparse.BooleanOptionalAction, default=True, help='Indicates whether the digitizer enforces real-time measurements or allows equivalent-time measurements.') + parser.add_argument('-c', '--channels', default='0', help='Comma-separated list of channels to plot, one line per channel') + parser.add_argument('-v', '--vertical-range', default=2.0, type=float, help='Specifies the absolute value of the input range for a channel in volts.') + parser.add_argument('--vertical-coupling', default='DC', choices=niscope.VerticalCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the input signal for the channel.') + parser.add_argument('--trigger-type', default='EDGE', choices=['EDGE', 'IMMEDIATE'], type=str.upper, help='Selects edge or immediate triggering.') + parser.add_argument('--trigger-source', default='0', help='Specifies the source the digitizer monitors for the trigger event.') + parser.add_argument('--trigger-level', default=0.0, type=float, help='Specifies the voltage threshold for the trigger subsystem.') + parser.add_argument('--trigger-slope', default='POSITIVE', choices=niscope.TriggerSlope.__members__.keys(), type=str.upper, help='Specifies if a rising or a falling edge triggers the digitizer.') + parser.add_argument('--trigger-coupling', default='DC', choices=niscope.TriggerCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the trigger source.') + parser.add_argument('-t', '--timeout', default=5.0, type=float, help='The time to wait in seconds for data to be acquired; using 0 for this parameter tells NI-SCOPE to fetch whatever is currently available.') + parser.add_argument('--total-iterations', default=None, type=int, help='Stops after this many acquisitions 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('-op', '--option-string', default='', type=str, help='Specifies the initial value of certain properties for the session.') + args = parser.parse_args(argsv) + example(args.resource_name, args.channels, args.option_string, args.vertical_range, args.vertical_coupling, + args.min_sample_rate, args.min_record_length, args.enforce_realtime, args.trigger_type, args.trigger_source, + args.trigger_level, args.trigger_slope, args.trigger_coupling, args.timeout, args.scalar_measurement, + args.reference_level_units, args.low_ref, args.mid_ref, args.high_ref, args.total_iterations) + + +def main(): + _main(sys.argv[1:]) + + +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': '5164', 'BoardType': 'PXIe', }, } + example('PXI1Slot2', '0', options, 2.0, 'DC', 1000000.0, 1000, True, 'IMMEDIATE', '0', 0.0, 'POSITIVE', 'DC', 5.0, + 'FREQUENCY', 'PERCENTAGE', 10.0, 50.0, 90.0, 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:5164; BoardType:PXIe', '--trigger-type', 'immediate', '--total-iterations', '2', ] + _main(cmd_line) + + +if __name__ == '__main__': + main() From 5b21e43d27607ab8f14123b9417176a5e345dda5 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 27 Oct 2026 08:49:43 +0000 Subject: [PATCH 2/9] Removing error handling for the trigger source We can use immediate trigger to run the example and the external trigger depends on the external input --- src/niscope/examples/niscope_measurement_library.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py index a44573ec0a..4c458cfdfe 100644 --- a/src/niscope/examples/niscope_measurement_library.py +++ b/src/niscope/examples/niscope_measurement_library.py @@ -5,8 +5,6 @@ import pytest import sys -_TIMEOUT_ERROR_CODE = -1074126845 # "Maximum time exceeded before the operation completed" - def _create_chart(plt): figure, axes = plt.subplots() @@ -56,14 +54,7 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, # Run until the chart is closed, Ctrl+C is pressed, or the iteration limit is reached. while plt.fignum_exists(figure.number) and (iterations is None or iteration < iterations): # The statistics accumulate once per acquisition, so read a new waveform before each fetch. - try: - waveforms = channel.read(num_samples=min_record_length, timeout=timeout) - except niscope.errors.DriverError as e: - if e.code != _TIMEOUT_ERROR_CODE: - raise - print(f'Timed out after {timeout} s waiting for a trigger; check the trigger source and level, or use --trigger-type immediate.') - plt.pause(0.02) - continue + waveforms = channel.read(num_samples=min_record_length, timeout=timeout) _update_chart(axes, waveforms) stats = channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) print(f'Acquisition {iteration}: {scalar_measurement}') From 8b77fbd68ac08dd7055c088dcc24fa86bb82e593 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Wed, 28 Oct 2026 07:06:43 +0000 Subject: [PATCH 3/9] Resolving PR comments --- .../examples/niscope_measurement_library.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py index 4c458cfdfe..721e168a53 100644 --- a/src/niscope/examples/niscope_measurement_library.py +++ b/src/niscope/examples/niscope_measurement_library.py @@ -28,9 +28,10 @@ def _update_chart(axes, waveforms): axes.autoscale_view() -def example(resource_name, channels, options, vertical_range, vertical_coupling, min_sample_rate, min_record_length, - enforce_realtime, trigger_type, trigger_source, trigger_level, trigger_slope, trigger_coupling, timeout, - scalar_measurement, reference_level_units, low_ref, mid_ref, high_ref, iterations): +def example(resource_name, channels, options, vertical_range, vertical_coupling, + min_sample_rate, min_record_length, enforce_realtime, trigger_type, trigger_source, + trigger_level, trigger_slope, trigger_coupling, timeout, scalar_measurement, + reference_level_units, low_ref, mid_ref, high_ref, iterations): import matplotlib.pyplot as plt with niscope.Session(resource_name=resource_name, options=options) as session: @@ -49,18 +50,18 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, figure, axes = _create_chart(plt) - iteration = 0 + acquisition_count = 1 try: # Run until the chart is closed, Ctrl+C is pressed, or the iteration limit is reached. - while plt.fignum_exists(figure.number) and (iterations is None or iteration < iterations): + while plt.fignum_exists(figure.number) and (iterations is None or acquisition_count <= iterations): # The statistics accumulate once per acquisition, so read a new waveform before each fetch. waveforms = channel.read(num_samples=min_record_length, timeout=timeout) _update_chart(axes, waveforms) stats = channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) - print(f'Acquisition {iteration}: {scalar_measurement}') + print(f'Acquisition {acquisition_count}: {scalar_measurement}') for stat in stats: print(stat) - iteration += 1 + acquisition_count += 1 plt.pause(0.02) # Keep the final plot window open after acquisition stops until the user closes it. @@ -92,7 +93,7 @@ def _main(argsv): parser.add_argument('--trigger-slope', default='POSITIVE', choices=niscope.TriggerSlope.__members__.keys(), type=str.upper, help='Specifies if a rising or a falling edge triggers the digitizer.') parser.add_argument('--trigger-coupling', default='DC', choices=niscope.TriggerCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the trigger source.') parser.add_argument('-t', '--timeout', default=5.0, type=float, help='The time to wait in seconds for data to be acquired; using 0 for this parameter tells NI-SCOPE to fetch whatever is currently available.') - parser.add_argument('--total-iterations', default=None, type=int, help='Stops after this many acquisitions 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-iterations', default=None, type=int, help='Specifies the maximum number of acquisitions; omit to run until the chart closes or Ctrl+C is pressed.') parser.add_argument('-op', '--option-string', default='', type=str, help='Specifies the initial value of certain properties for the session.') args = parser.parse_args(argsv) example(args.resource_name, args.channels, args.option_string, args.vertical_range, args.vertical_coupling, From 52c95639a18bcdaa14ef779e74a32a35f125859b Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Mon, 2 Nov 2026 11:54:01 +0000 Subject: [PATCH 4/9] Remved graph plotting --- build/templates/tox-system_tests.ini.mako | 3 - generated/niscope/tox-system_tests.ini | 1 - .../examples/niscope_measurement_library.py | 62 ++++--------------- 3 files changed, 12 insertions(+), 54 deletions(-) diff --git a/build/templates/tox-system_tests.ini.mako b/build/templates/tox-system_tests.ini.mako index 9c7f07cb3e..c2b3d9131d 100644 --- a/build/templates/tox-system_tests.ini.mako +++ b/build/templates/tox-system_tests.ini.mako @@ -76,9 +76,6 @@ deps = % endif % if module_name == 'nidigital': ${module_name}-system_tests: nisync -% endif -% if module_name == 'niscope': - ${module_name}-system_tests: matplotlib; sys_platform != "win32" % endif ${module_name}-system_tests: pytest ${module_name}-system_tests: coverage diff --git a/generated/niscope/tox-system_tests.ini b/generated/niscope/tox-system_tests.ini index afadc34815..2f232d27ab 100644 --- a/generated/niscope/tox-system_tests.ini +++ b/generated/niscope/tox-system_tests.ini @@ -39,7 +39,6 @@ commands = deps = niscope-wheel_dep: build - niscope-system_tests: matplotlib; sys_platform != "win32" niscope-system_tests: pytest niscope-system_tests: coverage niscope-system_tests: numpy diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py index 721e168a53..28749a5ebd 100644 --- a/src/niscope/examples/niscope_measurement_library.py +++ b/src/niscope/examples/niscope_measurement_library.py @@ -2,38 +2,14 @@ import argparse import niscope -import pytest import sys -def _create_chart(plt): - figure, axes = plt.subplots() - axes.set_title('Waveform Graph') - axes.set_xlabel('Time (s)') - axes.set_ylabel('Amplitude (V)') - axes.grid(True) - figure.tight_layout() - return figure, axes - - -def _update_chart(axes, waveforms): - while len(axes.lines) < len(waveforms): - axes.plot([], [], label=waveforms[len(axes.lines)].channel) - axes.legend(loc='upper right') - for line, waveform in zip(axes.lines, waveforms): - x = [waveform.relative_initial_x + i * waveform.x_increment for i in range(len(waveform.samples))] - # read() returns samples as a memoryview, which matplotlib cannot copy - line.set_data(x, list(waveform.samples)) - axes.relim() - axes.autoscale_view() - - def example(resource_name, channels, options, vertical_range, vertical_coupling, min_sample_rate, min_record_length, enforce_realtime, trigger_type, trigger_source, trigger_level, trigger_slope, trigger_coupling, timeout, scalar_measurement, reference_level_units, low_ref, mid_ref, high_ref, iterations): - import matplotlib.pyplot as plt - + print(f'Starting acquisition on resource {resource_name}, for {iterations if iterations is not None else "continuous"} iterations.') with niscope.Session(resource_name=resource_name, options=options) as session: session.configure_vertical(range=vertical_range, coupling=niscope.VerticalCoupling[vertical_coupling]) session.configure_horizontal_timing(min_sample_rate=min_sample_rate, min_num_pts=min_record_length, ref_position=50.0, num_records=1, enforce_realtime=enforce_realtime) @@ -48,29 +24,18 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, channel.meas_chan_mid_ref_level = mid_ref channel.meas_chan_high_ref_level = high_ref - figure, axes = _create_chart(plt) - - acquisition_count = 1 + acquisition_count = 0 try: - # Run until the chart is closed, Ctrl+C is pressed, or the iteration limit is reached. - while plt.fignum_exists(figure.number) and (iterations is None or acquisition_count <= iterations): + # Run until Ctrl+C is pressed or the iteration limit is reached. + while iterations is None or acquisition_count < iterations: # The statistics accumulate once per acquisition, so read a new waveform before each fetch. - waveforms = channel.read(num_samples=min_record_length, timeout=timeout) - _update_chart(axes, waveforms) - stats = channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) - print(f'Acquisition {acquisition_count}: {scalar_measurement}') - for stat in stats: - print(stat) + channel.read(num_samples=min_record_length, timeout=timeout) + channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) acquisition_count += 1 - plt.pause(0.02) - - # Keep the final plot window open after acquisition stops until the user closes it. - if iterations is not None and plt.fignum_exists(figure.number): - plt.show() except KeyboardInterrupt: pass - finally: - plt.close(figure) + + print('Completed {} acquisitions.'.format(acquisition_count)) def _main(argsv): @@ -84,7 +49,7 @@ def _main(argsv): parser.add_argument('-s', '--min-sample-rate', default=1000000.0, type=float, help='Specify the sampling rate for the acquisition in Samples per second.') parser.add_argument('-l', '--min-record-length', default=1000, type=int, help='Specifies the minimum number of points you require in the waveform record for each channel.') parser.add_argument('--enforce-realtime', action=argparse.BooleanOptionalAction, default=True, help='Indicates whether the digitizer enforces real-time measurements or allows equivalent-time measurements.') - parser.add_argument('-c', '--channels', default='0', help='Comma-separated list of channels to plot, one line per channel') + parser.add_argument('-c', '--channels', default='0', help='Comma-separated list of channels to acquire') parser.add_argument('-v', '--vertical-range', default=2.0, type=float, help='Specifies the absolute value of the input range for a channel in volts.') parser.add_argument('--vertical-coupling', default='DC', choices=niscope.VerticalCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the input signal for the channel.') parser.add_argument('--trigger-type', default='EDGE', choices=['EDGE', 'IMMEDIATE'], type=str.upper, help='Selects edge or immediate triggering.') @@ -93,13 +58,14 @@ def _main(argsv): parser.add_argument('--trigger-slope', default='POSITIVE', choices=niscope.TriggerSlope.__members__.keys(), type=str.upper, help='Specifies if a rising or a falling edge triggers the digitizer.') parser.add_argument('--trigger-coupling', default='DC', choices=niscope.TriggerCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the trigger source.') parser.add_argument('-t', '--timeout', default=5.0, type=float, help='The time to wait in seconds for data to be acquired; using 0 for this parameter tells NI-SCOPE to fetch whatever is currently available.') - parser.add_argument('--total-iterations', default=None, type=int, help='Specifies the maximum number of acquisitions; omit to run until the chart closes or Ctrl+C is pressed.') + parser.add_argument('--total-iterations', default=100, type=int, help='Number of acquisitions to perform before stopping.') + parser.add_argument('--continuous', action='store_true', help='Acquire until Ctrl+C is pressed; overrides --total-iterations.') parser.add_argument('-op', '--option-string', default='', type=str, help='Specifies the initial value of certain properties for the session.') args = parser.parse_args(argsv) example(args.resource_name, args.channels, args.option_string, args.vertical_range, args.vertical_coupling, args.min_sample_rate, args.min_record_length, args.enforce_realtime, args.trigger_type, args.trigger_source, args.trigger_level, args.trigger_slope, args.trigger_coupling, args.timeout, args.scalar_measurement, - args.reference_level_units, args.low_ref, args.mid_ref, args.high_ref, args.total_iterations) + args.reference_level_units, args.low_ref, args.mid_ref, args.high_ref, None if args.continuous else args.total_iterations) def main(): @@ -107,16 +73,12 @@ 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': '5164', 'BoardType': 'PXIe', }, } example('PXI1Slot2', '0', options, 2.0, 'DC', 1000000.0, 1000, True, 'IMMEDIATE', '0', 0.0, 'POSITIVE', 'DC', 5.0, 'FREQUENCY', 'PERCENTAGE', 10.0, 50.0, 90.0, 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:5164; BoardType:PXIe', '--trigger-type', 'immediate', '--total-iterations', '2', ] _main(cmd_line) From 5979fc77e50b4b64b50965a908cd9523fb90f421 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Mon, 2 Nov 2026 13:37:41 +0000 Subject: [PATCH 5/9] Removing continuous option --- .../examples/niscope_measurement_library.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py index 28749a5ebd..75768d4e20 100644 --- a/src/niscope/examples/niscope_measurement_library.py +++ b/src/niscope/examples/niscope_measurement_library.py @@ -9,7 +9,7 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, min_sample_rate, min_record_length, enforce_realtime, trigger_type, trigger_source, trigger_level, trigger_slope, trigger_coupling, timeout, scalar_measurement, reference_level_units, low_ref, mid_ref, high_ref, iterations): - print(f'Starting acquisition on resource {resource_name}, for {iterations if iterations is not None else "continuous"} iterations.') + print(f'Starting acquisition on resource {resource_name}, for {iterations} iterations.') with niscope.Session(resource_name=resource_name, options=options) as session: session.configure_vertical(range=vertical_range, coupling=niscope.VerticalCoupling[vertical_coupling]) session.configure_horizontal_timing(min_sample_rate=min_sample_rate, min_num_pts=min_record_length, ref_position=50.0, num_records=1, enforce_realtime=enforce_realtime) @@ -25,15 +25,11 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, channel.meas_chan_high_ref_level = high_ref acquisition_count = 0 - try: - # Run until Ctrl+C is pressed or the iteration limit is reached. - while iterations is None or acquisition_count < iterations: - # The statistics accumulate once per acquisition, so read a new waveform before each fetch. - channel.read(num_samples=min_record_length, timeout=timeout) - channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) - acquisition_count += 1 - except KeyboardInterrupt: - pass + while acquisition_count < iterations: + # The statistics accumulate once per acquisition, so read a new waveform before each fetch. + channel.read(num_samples=min_record_length, timeout=timeout) + channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) + acquisition_count += 1 print('Completed {} acquisitions.'.format(acquisition_count)) @@ -59,13 +55,12 @@ def _main(argsv): parser.add_argument('--trigger-coupling', default='DC', choices=niscope.TriggerCoupling.__members__.keys(), type=str.upper, help='Specifies how the digitizer couples the trigger source.') parser.add_argument('-t', '--timeout', default=5.0, type=float, help='The time to wait in seconds for data to be acquired; using 0 for this parameter tells NI-SCOPE to fetch whatever is currently available.') parser.add_argument('--total-iterations', default=100, type=int, help='Number of acquisitions to perform before stopping.') - parser.add_argument('--continuous', action='store_true', help='Acquire until Ctrl+C is pressed; overrides --total-iterations.') parser.add_argument('-op', '--option-string', default='', type=str, help='Specifies the initial value of certain properties for the session.') args = parser.parse_args(argsv) example(args.resource_name, args.channels, args.option_string, args.vertical_range, args.vertical_coupling, args.min_sample_rate, args.min_record_length, args.enforce_realtime, args.trigger_type, args.trigger_source, args.trigger_level, args.trigger_slope, args.trigger_coupling, args.timeout, args.scalar_measurement, - args.reference_level_units, args.low_ref, args.mid_ref, args.high_ref, None if args.continuous else args.total_iterations) + args.reference_level_units, args.low_ref, args.mid_ref, args.high_ref, args.total_iterations) def main(): From c219bd0447523c9a4119848f5f011a261c2f660c Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Mon, 2 Nov 2026 13:52:42 +0000 Subject: [PATCH 6/9] Reverting stats printing --- src/niscope/examples/niscope_measurement_library.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/niscope/examples/niscope_measurement_library.py b/src/niscope/examples/niscope_measurement_library.py index 75768d4e20..11461e68da 100644 --- a/src/niscope/examples/niscope_measurement_library.py +++ b/src/niscope/examples/niscope_measurement_library.py @@ -28,8 +28,11 @@ def example(resource_name, channels, options, vertical_range, vertical_coupling, while acquisition_count < iterations: # The statistics accumulate once per acquisition, so read a new waveform before each fetch. channel.read(num_samples=min_record_length, timeout=timeout) - channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) + stats = channel.fetch_measurement_stats(niscope.ScalarMeasurement[scalar_measurement]) acquisition_count += 1 + print(f'Acquisition {acquisition_count}: {scalar_measurement}') + for stat in stats: + print(stat) print('Completed {} acquisitions.'.format(acquisition_count)) From 5ff15cc9e36b661b2d5a1e2b4883e79b02153f63 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Thu, 5 Nov 2026 15:45:42 +0000 Subject: [PATCH 7/9] Adding Source Waveform example in NI-Digital --- CHANGELOG.md | 1 + docs/nidigital/examples.rst | 9 ++ .../examples/source_waveform/Pattern.digipat | Bin 0 -> 5413 bytes .../source_waveform/PinLevels.digilevels | 15 +++ .../examples/source_waveform/PinMap.pinmap | 51 +++++++++ .../source_waveform/SourceWaveform.tdms | Bin 0 -> 1619 bytes .../source_waveform/Specifications.specs | 9 ++ .../source_waveform/Timing.digitiming | 23 ++++ .../nidigital_source_waveform.py | 100 ++++++++++++++++++ .../source_waveform/source_waveform.digiproj | 39 +++++++ 10 files changed, 247 insertions(+) create mode 100644 src/nidigital/examples/source_waveform/Pattern.digipat create mode 100644 src/nidigital/examples/source_waveform/PinLevels.digilevels create mode 100644 src/nidigital/examples/source_waveform/PinMap.pinmap create mode 100644 src/nidigital/examples/source_waveform/SourceWaveform.tdms create mode 100644 src/nidigital/examples/source_waveform/Specifications.specs create mode 100644 src/nidigital/examples/source_waveform/Timing.digitiming create mode 100644 src/nidigital/examples/source_waveform/nidigital_source_waveform.py create mode 100644 src/nidigital/examples/source_waveform/source_waveform.digiproj diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d1d3267b..7fefe411b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -558,6 +558,7 @@ #### [nidigital] Unreleased - Added - (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies. + - Added the `nidigital_source_waveform.py` example. - Changed - Removed diff --git a/docs/nidigital/examples.rst b/docs/nidigital/examples.rst index b8c8cc689a..303dcff661 100644 --- a/docs/nidigital/examples.rst +++ b/docs/nidigital/examples.rst @@ -30,3 +30,12 @@ nidigital_ppmu_source_and_measure.py :encoding: utf8 :caption: `(nidigital_ppmu_source_and_measure.py) `_ +nidigital_source_waveform.py +---------------------------- + +.. literalinclude:: ../../src/nidigital/examples/source_waveform/nidigital_source_waveform.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(nidigital_source_waveform.py) `_ + diff --git a/src/nidigital/examples/source_waveform/Pattern.digipat b/src/nidigital/examples/source_waveform/Pattern.digipat new file mode 100644 index 0000000000000000000000000000000000000000..0ee9d4fef983edd6c923bfa0c4eeb74e1a9f9bf2 GIT binary patch literal 5413 zcmcgwTXP#V6y9(x<&uWN3^Ux6;bDhPr*2vb<=zk%aGTOh?KV7-S=(}~va2<+T(@uG zjTv6~A^Zz|Ryp79IgXsz9dCj;6XjdW(sw>dM@L$>>dow>D2mLRQPd`c39isHO6@7x z3-o|ulT0hZm#OR|-fL%HrN^!wcAOb_lUsZXdy$GaJ}sJ~0)CQ_@8?e8BUvl(ezB~I z1gE^?L+BkYtsd_UN(CX$W#$n)#&ez;Y~|U&q`JFneE)%VLz0aFk)02@J}&Db!DC#n zQ3LLOCwZ7Vkf70tNsOIM@+B(~Jf`FWYH-I`lZ`SAF7c+F>bf(Jw3{B_N~lff1Q(;d z*)=|Y7VQ_TR`3|@`_!PGkL|uox_UQp*4X{KwwXNAQ)17pg<@qz1;P3Xm0J9xCK?wb zPEk20Ai?zpeT`T*gfKyLLtsp}YB5b?rmc_PqiRJ3O^(`gR58aJsz=uNy`gtBI>lYX z0c~)dAUvF#WM!|4N-< zf*^aFN-Y+$;^_yMj|NLzf7wiekn!#u8QgzNqil2*<_1R-R7u8@1Wr=7MP-7Tb`Av%bi?lf^sBM4?Bk8ny$MWHb^x-Ll+cnk_~!SJ*cqWL4A< zB4HePrIcMNUcTk#=w5MSh(~6aN=0&Q-VEs1={bzC!+kd=+@~CbiLS}4^?0mN4~yOrNCCy;L=|GfAp; z>2$5_Xu569jj7lfZ8$X`T;4H&@wBjS+4Zh-z*f zVFQPBSNMzY0H@$ literal 0 HcmV?d00001 diff --git a/src/nidigital/examples/source_waveform/PinLevels.digilevels b/src/nidigital/examples/source_waveform/PinLevels.digilevels new file mode 100644 index 0000000000..1908b117fa --- /dev/null +++ b/src/nidigital/examples/source_waveform/PinLevels.digilevels @@ -0,0 +1,15 @@ + + + + + + 0 + 3.3 + 0.8 + 2 + 0 + HighZ + + + + \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/PinMap.pinmap b/src/nidigital/examples/source_waveform/PinMap.pinmap new file mode 100644 index 0000000000..46d985a9f9 --- /dev/null +++ b/src/nidigital/examples/source_waveform/PinMap.pinmap @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/SourceWaveform.tdms b/src/nidigital/examples/source_waveform/SourceWaveform.tdms new file mode 100644 index 0000000000000000000000000000000000000000..4f85ffcdff1deaa6c969a39131b2c23dc77153ea GIT binary patch literal 1619 zcmeHHO-sW-5RD&IL{L!CYi_yq<6_T-C{~CTQtdG;$=VJyA8fYv>Oa>vX%^N(iQ=^b z!`sg8yf?ee%p{1iBgb**0uE#|xQ8`+?+bQ_1$!pH-QL$8soQexlM{)z>w2n!!^{*zbxRh zN!h{f1?(=lZ=Sg4*rKsxin46R#R-UfRfseZm9|wzwT9yuY*E>`$@-ZdFqnmQ!BqdzGNJ6} bRs2T8V2cRmsr_7UQdP~Y?_g)p?RWd%nF`^h literal 0 HcmV?d00001 diff --git a/src/nidigital/examples/source_waveform/Specifications.specs b/src/nidigital/examples/source_waveform/Specifications.specs new file mode 100644 index 0000000000..65c615cfd6 --- /dev/null +++ b/src/nidigital/examples/source_waveform/Specifications.specs @@ -0,0 +1,9 @@ + + +
+ + 1 µs + +
+ +
\ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/Timing.digitiming b/src/nidigital/examples/source_waveform/Timing.digitiming new file mode 100644 index 0000000000..b5908eabfb --- /dev/null +++ b/src/nidigital/examples/source_waveform/Timing.digitiming @@ -0,0 +1,23 @@ + + + + + + timing.period + + + + 0 ns + timing.period / 2 + timing.period + + + (3 * timing.period) / 4 + + Pattern + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/nidigital_source_waveform.py b/src/nidigital/examples/source_waveform/nidigital_source_waveform.py new file mode 100644 index 0000000000..266d731ca5 --- /dev/null +++ b/src/nidigital/examples/source_waveform/nidigital_source_waveform.py @@ -0,0 +1,100 @@ +#!/usr/bin/python + +import argparse +import nidigital +import os +import sys + + +def example(resource_name, options, source_waveform_type='PARALLEL', data_mapping='BROADCAST', waveform_name='new_waveform', start_label='new_pattern', + parallel_channel_list='PinGroup1', serial_channel_list='DUTPin1', sample_width=32, bit_order='MSB', waveform_file=None, write_waveform_data=True): + + with nidigital.Session(resource_name=resource_name, options=options) as session: + + dir = os.path.join(os.path.dirname(__file__)) + if waveform_file is None: + waveform_file = os.path.join(dir, 'SourceWaveform.tdms') + + session.load_pin_map(os.path.join(dir, 'PinMap.pinmap')) + + spec_filename = os.path.join(dir, 'Specifications.specs') + levels_filename = os.path.join(dir, 'PinLevels.digilevels') + timing_filename = os.path.join(dir, 'Timing.digitiming') + session.load_specifications_levels_and_timing(spec_filename, levels_filename, timing_filename) + + session.apply_levels_and_timing(levels_filename, timing_filename) + + session.load_pattern(os.path.join(dir, 'Pattern.digipat')) + + mapping = nidigital.SourceDataMapping[data_mapping] + + # Configure the source waveform type + if source_waveform_type == 'PARALLEL': + session.pins[parallel_channel_list].create_source_waveform_parallel(waveform_name, mapping) + elif source_waveform_type == 'SERIAL': + session.pins[serial_channel_list].create_source_waveform_serial(waveform_name, mapping, sample_width, nidigital.BitOrder[bit_order]) + elif source_waveform_type == 'TDMS': + # Waveform configuration and data are read from the TDMS file + session.create_source_waveform_from_file_tdms(waveform_name, waveform_file, write_waveform_data) + + # Write the source waveform data + if source_waveform_type != 'TDMS': + # Placeholder ramp data for illustration; replace with your own waveform samples + sample_count = 2 ** min(sample_width, 8) if source_waveform_type == 'SERIAL' else 256 + samples = [i % sample_count for i in range(sample_count)] + if mapping == nidigital.SourceDataMapping.BROADCAST: + session.write_source_waveform_broadcast(waveform_name, samples) + else: + # Site-unique data is a dict of site number to samples; both sites use the same placeholder data here + session.write_source_waveform_site_unique(waveform_name, {0: samples, 1: samples}) + + print('Start bursting pattern') + session.burst_pattern(start_label=start_label) + + session.selected_function = nidigital.SelectedFunction.DISCONNECT + print('Done bursting pattern') + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Demonstrates how to configure, write, and burst a source waveform using NI-Digital source memory.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-n', '--resource-name', default='PXI1Slot2,PXI1Slot3', help='The specified resource name shown in Measurement & Automation Explorer (MAX) for a digital pattern instrument, for example, PXI1Slot3, where PXI1Slot3 is an instrument resource name.') + parser.add_argument('-s', '--simulate', default='True', choices=['True', 'False'], help='Whether to run on simulated hardware or real hardware') + parser.add_argument('-w', '--waveform-name', default='new_waveform', help='The name to assign to the waveform. Use the waveform_name with source_start opcode in your pattern.') + parser.add_argument('-l', '--start-label', default='new_pattern', help='Pattern name or exported pattern label from which to start bursting the pattern.') + parser.add_argument('-d', '--data-mapping', default='BROADCAST', choices=nidigital.SourceDataMapping.__members__.keys(), type=str.upper, help='Parameter that specifies how to map data on multiple sites.') + parser.add_argument('-t', '--source-waveform-type', default='PARALLEL', choices=['PARALLEL', 'SERIAL', 'TDMS'], type=str.upper, help='Type of source waveform to configure.') + parser.add_argument('--parallel-channel-list', default='PinGroup1', help='Pins that source data for a parallel waveform.') + parser.add_argument('--serial-channel-list', default='DUTPin1', help='Pins that source data for a serial waveform.') + parser.add_argument('--sample-width', default=32, type=int, help='Width in bits of each serial sample. Valid values are between 1 and 32.') + parser.add_argument('--bit-order', default='MSB', choices=nidigital.BitOrder.__members__.keys(), type=str.upper, help='Order in which to shift the bits.') + parser.add_argument('--waveform-file', default=None, help='Absolute file path to the load source waveform file (.tdms). Defaults to SourceWaveform.tdms next to this example.') + parser.add_argument('--write-waveform-data', default='True', choices=['True', 'False'], help='A Boolean that writes waveform data to source memory if True and the waveform data is in the file.') + args = parser.parse_args(argsv) + + example(args.resource_name, + 'Simulate=1, DriverSetup=Model:6571' if args.simulate == 'True' else '', + args.source_waveform_type, args.data_mapping, args.waveform_name, args.start_label, + args.parallel_channel_list, args.serial_channel_list, args.sample_width, args.bit_order, + args.waveform_file, args.write_waveform_data == 'True') + + +def main(): + _main(sys.argv[1:]) + + +def test_main(): + _main([]) + _main(['--source-waveform-type', 'SERIAL', '--data-mapping', 'SITE_UNIQUE']) + _main(['--source-waveform-type', 'TDMS']) + + +def test_example(): + resource_name = 'PXI1Slot2,PXI1Slot3' + options = {'simulate': True, 'driver_setup': {'Model': '6571'}, } + example(resource_name, options) + example(resource_name, options, 'SERIAL', 'SITE_UNIQUE') + example(resource_name, options, 'TDMS') + + +if __name__ == '__main__': + main() diff --git a/src/nidigital/examples/source_waveform/source_waveform.digiproj b/src/nidigital/examples/source_waveform/source_waveform.digiproj new file mode 100644 index 0000000000..971b8ff9b9 --- /dev/null +++ b/src/nidigital/examples/source_waveform/source_waveform.digiproj @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b151b5e8b7604a4af3dfd2d50237b939146de0b8 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Thu, 5 Nov 2026 15:46:25 +0000 Subject: [PATCH 8/9] Revert "Adding Source Waveform example in NI-Digital" This reverts commit 5ff15cc9e36b661b2d5a1e2b4883e79b02153f63. --- CHANGELOG.md | 1 - docs/nidigital/examples.rst | 9 -- .../examples/source_waveform/Pattern.digipat | Bin 5413 -> 0 bytes .../source_waveform/PinLevels.digilevels | 15 --- .../examples/source_waveform/PinMap.pinmap | 51 --------- .../source_waveform/SourceWaveform.tdms | Bin 1619 -> 0 bytes .../source_waveform/Specifications.specs | 9 -- .../source_waveform/Timing.digitiming | 23 ---- .../nidigital_source_waveform.py | 100 ------------------ .../source_waveform/source_waveform.digiproj | 39 ------- 10 files changed, 247 deletions(-) delete mode 100644 src/nidigital/examples/source_waveform/Pattern.digipat delete mode 100644 src/nidigital/examples/source_waveform/PinLevels.digilevels delete mode 100644 src/nidigital/examples/source_waveform/PinMap.pinmap delete mode 100644 src/nidigital/examples/source_waveform/SourceWaveform.tdms delete mode 100644 src/nidigital/examples/source_waveform/Specifications.specs delete mode 100644 src/nidigital/examples/source_waveform/Timing.digitiming delete mode 100644 src/nidigital/examples/source_waveform/nidigital_source_waveform.py delete mode 100644 src/nidigital/examples/source_waveform/source_waveform.digiproj diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fefe411b8..83d1d3267b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -558,7 +558,6 @@ #### [nidigital] Unreleased - Added - (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies. - - Added the `nidigital_source_waveform.py` example. - Changed - Removed diff --git a/docs/nidigital/examples.rst b/docs/nidigital/examples.rst index 303dcff661..b8c8cc689a 100644 --- a/docs/nidigital/examples.rst +++ b/docs/nidigital/examples.rst @@ -30,12 +30,3 @@ nidigital_ppmu_source_and_measure.py :encoding: utf8 :caption: `(nidigital_ppmu_source_and_measure.py) `_ -nidigital_source_waveform.py ----------------------------- - -.. literalinclude:: ../../src/nidigital/examples/source_waveform/nidigital_source_waveform.py - :language: python - :linenos: - :encoding: utf8 - :caption: `(nidigital_source_waveform.py) `_ - diff --git a/src/nidigital/examples/source_waveform/Pattern.digipat b/src/nidigital/examples/source_waveform/Pattern.digipat deleted file mode 100644 index 0ee9d4fef983edd6c923bfa0c4eeb74e1a9f9bf2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5413 zcmcgwTXP#V6y9(x<&uWN3^Ux6;bDhPr*2vb<=zk%aGTOh?KV7-S=(}~va2<+T(@uG zjTv6~A^Zz|Ryp79IgXsz9dCj;6XjdW(sw>dM@L$>>dow>D2mLRQPd`c39isHO6@7x z3-o|ulT0hZm#OR|-fL%HrN^!wcAOb_lUsZXdy$GaJ}sJ~0)CQ_@8?e8BUvl(ezB~I z1gE^?L+BkYtsd_UN(CX$W#$n)#&ez;Y~|U&q`JFneE)%VLz0aFk)02@J}&Db!DC#n zQ3LLOCwZ7Vkf70tNsOIM@+B(~Jf`FWYH-I`lZ`SAF7c+F>bf(Jw3{B_N~lff1Q(;d z*)=|Y7VQ_TR`3|@`_!PGkL|uox_UQp*4X{KwwXNAQ)17pg<@qz1;P3Xm0J9xCK?wb zPEk20Ai?zpeT`T*gfKyLLtsp}YB5b?rmc_PqiRJ3O^(`gR58aJsz=uNy`gtBI>lYX z0c~)dAUvF#WM!|4N-< zf*^aFN-Y+$;^_yMj|NLzf7wiekn!#u8QgzNqil2*<_1R-R7u8@1Wr=7MP-7Tb`Av%bi?lf^sBM4?Bk8ny$MWHb^x-Ll+cnk_~!SJ*cqWL4A< zB4HePrIcMNUcTk#=w5MSh(~6aN=0&Q-VEs1={bzC!+kd=+@~CbiLS}4^?0mN4~yOrNCCy;L=|GfAp; z>2$5_Xu569jj7lfZ8$X`T;4H&@wBjS+4Zh-z*f zVFQPBSNMzY0H@$ diff --git a/src/nidigital/examples/source_waveform/PinLevels.digilevels b/src/nidigital/examples/source_waveform/PinLevels.digilevels deleted file mode 100644 index 1908b117fa..0000000000 --- a/src/nidigital/examples/source_waveform/PinLevels.digilevels +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - 0 - 3.3 - 0.8 - 2 - 0 - HighZ - - - - \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/PinMap.pinmap b/src/nidigital/examples/source_waveform/PinMap.pinmap deleted file mode 100644 index 46d985a9f9..0000000000 --- a/src/nidigital/examples/source_waveform/PinMap.pinmap +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/SourceWaveform.tdms b/src/nidigital/examples/source_waveform/SourceWaveform.tdms deleted file mode 100644 index 4f85ffcdff1deaa6c969a39131b2c23dc77153ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1619 zcmeHHO-sW-5RD&IL{L!CYi_yq<6_T-C{~CTQtdG;$=VJyA8fYv>Oa>vX%^N(iQ=^b z!`sg8yf?ee%p{1iBgb**0uE#|xQ8`+?+bQ_1$!pH-QL$8soQexlM{)z>w2n!!^{*zbxRh zN!h{f1?(=lZ=Sg4*rKsxin46R#R-UfRfseZm9|wzwT9yuY*E>`$@-ZdFqnmQ!BqdzGNJ6} bRs2T8V2cRmsr_7UQdP~Y?_g)p?RWd%nF`^h diff --git a/src/nidigital/examples/source_waveform/Specifications.specs b/src/nidigital/examples/source_waveform/Specifications.specs deleted file mode 100644 index 65c615cfd6..0000000000 --- a/src/nidigital/examples/source_waveform/Specifications.specs +++ /dev/null @@ -1,9 +0,0 @@ - - -
- - 1 µs - -
- -
\ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/Timing.digitiming b/src/nidigital/examples/source_waveform/Timing.digitiming deleted file mode 100644 index b5908eabfb..0000000000 --- a/src/nidigital/examples/source_waveform/Timing.digitiming +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - timing.period - - - - 0 ns - timing.period / 2 - timing.period - - - (3 * timing.period) / 4 - - Pattern - - - - - - \ No newline at end of file diff --git a/src/nidigital/examples/source_waveform/nidigital_source_waveform.py b/src/nidigital/examples/source_waveform/nidigital_source_waveform.py deleted file mode 100644 index 266d731ca5..0000000000 --- a/src/nidigital/examples/source_waveform/nidigital_source_waveform.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/python - -import argparse -import nidigital -import os -import sys - - -def example(resource_name, options, source_waveform_type='PARALLEL', data_mapping='BROADCAST', waveform_name='new_waveform', start_label='new_pattern', - parallel_channel_list='PinGroup1', serial_channel_list='DUTPin1', sample_width=32, bit_order='MSB', waveform_file=None, write_waveform_data=True): - - with nidigital.Session(resource_name=resource_name, options=options) as session: - - dir = os.path.join(os.path.dirname(__file__)) - if waveform_file is None: - waveform_file = os.path.join(dir, 'SourceWaveform.tdms') - - session.load_pin_map(os.path.join(dir, 'PinMap.pinmap')) - - spec_filename = os.path.join(dir, 'Specifications.specs') - levels_filename = os.path.join(dir, 'PinLevels.digilevels') - timing_filename = os.path.join(dir, 'Timing.digitiming') - session.load_specifications_levels_and_timing(spec_filename, levels_filename, timing_filename) - - session.apply_levels_and_timing(levels_filename, timing_filename) - - session.load_pattern(os.path.join(dir, 'Pattern.digipat')) - - mapping = nidigital.SourceDataMapping[data_mapping] - - # Configure the source waveform type - if source_waveform_type == 'PARALLEL': - session.pins[parallel_channel_list].create_source_waveform_parallel(waveform_name, mapping) - elif source_waveform_type == 'SERIAL': - session.pins[serial_channel_list].create_source_waveform_serial(waveform_name, mapping, sample_width, nidigital.BitOrder[bit_order]) - elif source_waveform_type == 'TDMS': - # Waveform configuration and data are read from the TDMS file - session.create_source_waveform_from_file_tdms(waveform_name, waveform_file, write_waveform_data) - - # Write the source waveform data - if source_waveform_type != 'TDMS': - # Placeholder ramp data for illustration; replace with your own waveform samples - sample_count = 2 ** min(sample_width, 8) if source_waveform_type == 'SERIAL' else 256 - samples = [i % sample_count for i in range(sample_count)] - if mapping == nidigital.SourceDataMapping.BROADCAST: - session.write_source_waveform_broadcast(waveform_name, samples) - else: - # Site-unique data is a dict of site number to samples; both sites use the same placeholder data here - session.write_source_waveform_site_unique(waveform_name, {0: samples, 1: samples}) - - print('Start bursting pattern') - session.burst_pattern(start_label=start_label) - - session.selected_function = nidigital.SelectedFunction.DISCONNECT - print('Done bursting pattern') - - -def _main(argsv): - parser = argparse.ArgumentParser(description='Demonstrates how to configure, write, and burst a source waveform using NI-Digital source memory.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('-n', '--resource-name', default='PXI1Slot2,PXI1Slot3', help='The specified resource name shown in Measurement & Automation Explorer (MAX) for a digital pattern instrument, for example, PXI1Slot3, where PXI1Slot3 is an instrument resource name.') - parser.add_argument('-s', '--simulate', default='True', choices=['True', 'False'], help='Whether to run on simulated hardware or real hardware') - parser.add_argument('-w', '--waveform-name', default='new_waveform', help='The name to assign to the waveform. Use the waveform_name with source_start opcode in your pattern.') - parser.add_argument('-l', '--start-label', default='new_pattern', help='Pattern name or exported pattern label from which to start bursting the pattern.') - parser.add_argument('-d', '--data-mapping', default='BROADCAST', choices=nidigital.SourceDataMapping.__members__.keys(), type=str.upper, help='Parameter that specifies how to map data on multiple sites.') - parser.add_argument('-t', '--source-waveform-type', default='PARALLEL', choices=['PARALLEL', 'SERIAL', 'TDMS'], type=str.upper, help='Type of source waveform to configure.') - parser.add_argument('--parallel-channel-list', default='PinGroup1', help='Pins that source data for a parallel waveform.') - parser.add_argument('--serial-channel-list', default='DUTPin1', help='Pins that source data for a serial waveform.') - parser.add_argument('--sample-width', default=32, type=int, help='Width in bits of each serial sample. Valid values are between 1 and 32.') - parser.add_argument('--bit-order', default='MSB', choices=nidigital.BitOrder.__members__.keys(), type=str.upper, help='Order in which to shift the bits.') - parser.add_argument('--waveform-file', default=None, help='Absolute file path to the load source waveform file (.tdms). Defaults to SourceWaveform.tdms next to this example.') - parser.add_argument('--write-waveform-data', default='True', choices=['True', 'False'], help='A Boolean that writes waveform data to source memory if True and the waveform data is in the file.') - args = parser.parse_args(argsv) - - example(args.resource_name, - 'Simulate=1, DriverSetup=Model:6571' if args.simulate == 'True' else '', - args.source_waveform_type, args.data_mapping, args.waveform_name, args.start_label, - args.parallel_channel_list, args.serial_channel_list, args.sample_width, args.bit_order, - args.waveform_file, args.write_waveform_data == 'True') - - -def main(): - _main(sys.argv[1:]) - - -def test_main(): - _main([]) - _main(['--source-waveform-type', 'SERIAL', '--data-mapping', 'SITE_UNIQUE']) - _main(['--source-waveform-type', 'TDMS']) - - -def test_example(): - resource_name = 'PXI1Slot2,PXI1Slot3' - options = {'simulate': True, 'driver_setup': {'Model': '6571'}, } - example(resource_name, options) - example(resource_name, options, 'SERIAL', 'SITE_UNIQUE') - example(resource_name, options, 'TDMS') - - -if __name__ == '__main__': - main() diff --git a/src/nidigital/examples/source_waveform/source_waveform.digiproj b/src/nidigital/examples/source_waveform/source_waveform.digiproj deleted file mode 100644 index 971b8ff9b9..0000000000 --- a/src/nidigital/examples/source_waveform/source_waveform.digiproj +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 13959474416c8683a5485c5796f1384e91ccba7a Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Wed, 11 Nov 2026 14:35:41 +0000 Subject: [PATCH 9/9] Trigger CI build