diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c979fcd..fdcade509 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_burst_with_conditional_trigger.py` example. - Added the `nidigital_load_sheets_and_burst.py` example. - Changed - Removed diff --git a/docs/nidigital/examples.rst b/docs/nidigital/examples.rst index cde76451e..047f4d33a 100644 --- a/docs/nidigital/examples.rst +++ b/docs/nidigital/examples.rst @@ -30,6 +30,15 @@ nidigital_load_sheets_and_burst.py :encoding: utf8 :caption: `(nidigital_load_sheets_and_burst.py) `_ +nidigital_burst_with_conditional_trigger.py +------------------------------------------- + +.. literalinclude:: ../../src/nidigital/examples/nidigital_burst_with_conditional_trigger/nidigital_burst_with_conditional_trigger.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(nidigital_burst_with_conditional_trigger.py) `_ + nidigital_ppmu_source_and_measure.py ------------------------------------ diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Pattern.digipat b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Pattern.digipat new file mode 100644 index 000000000..9bcce0423 Binary files /dev/null and b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Pattern.digipat differ diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/PinLevels.digilevels b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/PinLevels.digilevels new file mode 100644 index 000000000..35dc1d186 --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/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/nidigital_burst_with_conditional_trigger/PinMap.pinmap b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/PinMap.pinmap new file mode 100644 index 000000000..d6fa6148d --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/PinMap.pinmap @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Specifications.specs b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Specifications.specs new file mode 100644 index 000000000..51ba58bb5 --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Specifications.specs @@ -0,0 +1,9 @@ + + +
+ + 1 µs + +
+ +
\ No newline at end of file diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Timing.digitiming b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Timing.digitiming new file mode 100644 index 000000000..d020f8c7b --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/Timing.digitiming @@ -0,0 +1,23 @@ + + + + + + timing.period + + + + 0 µs + timing.period / 2 + timing.period + + + (3 * timing.period) / 4 + + Pattern + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/burst_with_conditional_trigger.digiproj b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/burst_with_conditional_trigger.digiproj new file mode 100644 index 000000000..4d3d3e03a --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/burst_with_conditional_trigger.digiproj @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/nidigital_burst_with_conditional_trigger/nidigital_burst_with_conditional_trigger.py b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/nidigital_burst_with_conditional_trigger.py new file mode 100644 index 000000000..e8d659d6b --- /dev/null +++ b/src/nidigital/examples/nidigital_burst_with_conditional_trigger/nidigital_burst_with_conditional_trigger.py @@ -0,0 +1,105 @@ +#!/usr/bin/python + +import argparse +import nidigital +import os +import sys + + +def example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger): + + with nidigital.Session(resource_name=resource_name, reset_device=True, options=options) as session: + + directory = os.path.dirname(os.path.abspath(__file__)) + + pin_map_filename = os.path.join(directory, 'PinMap.pinmap') + session.load_pin_map(pin_map_filename) + + spec_filename = os.path.join(directory, 'Specifications.specs') + levels_filename = os.path.join(directory, 'PinLevels.digilevels') + timing_filename = os.path.join(directory, 'Timing.digitiming') + session.load_specifications_levels_and_timing(spec_filename, levels_filename, timing_filename) + + session.apply_levels_and_timing(levels_filename, timing_filename) + + pattern_filename = os.path.join(directory, 'Pattern.digipat') + session.load_pattern(pattern_filename) + + trigger_identifier = 'conditionalJumpTrigger0' + conditional_trigger = session.conditional_jump_triggers[trigger_identifier] + conditional_trigger.conditional_jump_trigger_type = trigger_type + if trigger_type == nidigital.TriggerType.DIGITAL_EDGE: + conditional_trigger.digital_edge_conditional_jump_trigger_source = trigger_source + conditional_trigger.digital_edge_conditional_jump_trigger_edge = trigger_edge + + try: + print('Start bursting pattern') + if trigger_type == nidigital.TriggerType.SOFTWARE: + # Start the burst without blocking so the software conditional trigger can be sent + session.burst_pattern(start_label='new_pattern', wait_until_done=False) + if not send_software_trigger: + print('Pattern burst stopped without sending a software trigger') + return + + session.send_software_edge_trigger(nidigital.SoftwareTrigger.CONDITIONAL_JUMP, trigger_identifier) + session.wait_until_done() + else: + session.burst_pattern(start_label='new_pattern') + finally: + try: + session.abort() + finally: + session.selected_function = nidigital.SelectedFunction.DISCONNECT + print('Done bursting pattern') + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Demonstrates how to burst a pattern on the digital pattern instrument using a conditional trigger.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-n', '--resource-name', default='PXI1Slot2,PXI1Slot3', help='The specified resource name of 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('-tt', '--trigger-type', default='SOFTWARE', type=str.upper, choices=nidigital.TriggerType.__members__, help='Disables the conditional jump trigger or configures it for either hardware triggering or software triggering.') + parser.add_argument('-ts', '--trigger-source', default='/PXI1Slot2/PXI_Trig0', help='Configures the digital trigger source terminal for a conditional jump trigger instance.') + parser.add_argument('-te', '--trigger-edge', default='RISING', type=str.upper, choices=nidigital.DigitalEdge.__members__, help='Configures the active edge of the incoming trigger signal for the conditional jump trigger instance.') + parser.add_argument('--send-software-trigger', default='True', choices=['True', 'False'], help='Whether to send the software conditional trigger or stop the burst without sending it; applies only to SOFTWARE mode.') + args = parser.parse_args(argsv) + + example(args.resource_name, + 'Simulate=1, DriverSetup=Model:6570' if args.simulate == 'True' else '', + nidigital.TriggerType[args.trigger_type], args.trigger_source, + nidigital.DigitalEdge[args.trigger_edge], args.send_software_trigger == 'True') + + +def main(): + _main(sys.argv[1:]) + + +def test_main(): + _main([]) + _main(['--trigger-type', 'NONE']) + _main(['--trigger-type', 'DIGITAL_EDGE']) + _main(['--trigger-type', 'DIGITAL_EDGE', '--trigger-edge', 'FALLING']) + _main(['--send-software-trigger', 'False']) + + +def test_example(): + resource_name = 'PXI1Slot2,PXI1Slot3' + options = {'simulate': True, 'driver_setup': {'Model': '6570'}} + trigger_source = '/PXI1Slot2/PXI_Trig0' + trigger_edge = nidigital.DigitalEdge.RISING + + trigger_type = nidigital.TriggerType.SOFTWARE + example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger=True) + example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger=False) + + trigger_type = nidigital.TriggerType.NONE + example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger=True) + + trigger_type = nidigital.TriggerType.DIGITAL_EDGE + example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger=True) + + trigger_edge = nidigital.DigitalEdge.FALLING + example(resource_name, options, trigger_type, trigger_source, trigger_edge, send_software_trigger=True) + + +if __name__ == '__main__': + main()