From ac6f0b62bdb9c4d88e1b01b8b77e0cd936eaa473 Mon Sep 17 00:00:00 2001 From: ni-juoca <164403404+ni-juoca@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:34:46 -0500 Subject: [PATCH] [NI-DCPower] Address timeout issues with nidcpower_advanced_sequence.py (#2052) * initial changes detailed in github issue * timeout calculation accounting for aperture time * updated CHANGELOG.md * removing extra whitespace --------- Co-authored-by: Justin Oca --- CHANGELOG.md | 1 + .../examples/nidcpower_advanced_sequence.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c60824b..774ac42fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. * ### `nidcpower` (NI-DCPower) * #### Added * #### Changed + * Fix [#1664](https://github.com/ni/nimi-python/issues/1970): nidcpower_advanced_sequence.py has several issues preventing it from working out of the box on real hardware. * #### Removed * ### `nidigital` (NI-Digital Pattern Driver) * #### Added diff --git a/src/nidcpower/examples/nidcpower_advanced_sequence.py b/src/nidcpower/examples/nidcpower_advanced_sequence.py index 9d2b0c2c9..5942f602a 100644 --- a/src/nidcpower/examples/nidcpower_advanced_sequence.py +++ b/src/nidcpower/examples/nidcpower_advanced_sequence.py @@ -6,15 +6,13 @@ import sys -def example(resource_name, options, voltage_max, current_max, points_per_output_function, delay_in_seconds): - timeout = hightime.timedelta(seconds=(delay_in_seconds + 1.0)) - +def example(resource_name, options, voltage_max, current_max, points_per_output_function, source_delay): with nidcpower.Session(resource_name=resource_name, options=options) as session: # Configure the session. session.source_mode = nidcpower.SourceMode.SEQUENCE session.voltage_level_autorange = True session.current_limit_autorange = True - session.source_delay = hightime.timedelta(seconds=delay_in_seconds) + session.source_delay = hightime.timedelta(seconds=source_delay) properties_used = ['output_function', 'voltage_level', 'current_level'] session.create_advanced_sequence(sequence_name='my_sequence', property_names=properties_used, set_as_active_sequence=True) @@ -30,11 +28,15 @@ def example(resource_name, options, voltage_max, current_max, points_per_output_ session.output_function = nidcpower.OutputFunction.DC_CURRENT session.current_level = current_per_step * i + # Calculate the timeout. + aperture_time = session.aperture_time + total_points = points_per_output_function * 2 + timeout = hightime.timedelta(seconds=((source_delay + aperture_time) * total_points + 1.0)) + with session.initiate(): - session.wait_for_event(nidcpower.Event.SEQUENCE_ENGINE_DONE) channel_indices = f'0-{session.channel_count - 1}' channels = session.get_channel_names(channel_indices) - measurement_group = [session.channels[name].fetch_multiple(points_per_output_function * 2, timeout=timeout) for name in channels] + measurement_group = [session.channels[name].fetch_multiple(total_points, timeout=timeout) for name in channels] session.delete_advanced_sequence(sequence_name='my_sequence') line_format = '{:<15} {:<4} {:<10} {:<10} {:<6}' @@ -50,7 +52,7 @@ def example(resource_name, options, voltage_max, current_max, points_per_output_ def _main(argsv): parser = argparse.ArgumentParser(description='Output ramping voltage to voltage max, then ramping current to current max.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-n', '--resource-name', default='PXI1Slot2/0, PXI1Slot3/0-1', help='Resource names of NI SMUs.') - parser.add_argument('-s', '--number-steps', default=256, help='Number of steps per output function') + parser.add_argument('-s', '--number-steps', default=256, type=int, help='Number of steps per output function') parser.add_argument('-v', '--voltage-max', default=1.0, type=float, help='Maximum voltage (V)') parser.add_argument('-i', '--current-max', default=0.001, type=float, help='Maximum Current (I)') parser.add_argument('-d', '--delay', default=0.05, type=float, help='Source delay (s)')