diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c979fcd..fdbdf8a2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -559,6 +559,7 @@ - Added - (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies. - Added the `nidigital_load_sheets_and_burst.py` example. + - Added the `nidigital_tdr_measurement.py` example. - Changed - Removed diff --git a/docs/nidigital/examples.rst b/docs/nidigital/examples.rst index cde76451e..63c7c75db 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_tdr_measurement.py +---------------------------- + +.. literalinclude:: ../../src/nidigital/examples/nidigital_tdr_measurement/nidigital_tdr_measurement.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(nidigital_tdr_measurement.py) `_ + nidigital_ppmu_source_and_measure.py ------------------------------------ diff --git a/src/nidigital/examples/nidigital_tdr_measurement/PinMap.pinmap b/src/nidigital/examples/nidigital_tdr_measurement/PinMap.pinmap new file mode 100644 index 000000000..80a2297e9 --- /dev/null +++ b/src/nidigital/examples/nidigital_tdr_measurement/PinMap.pinmap @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/nidigital/examples/nidigital_tdr_measurement/nidigital_tdr_measurement.py b/src/nidigital/examples/nidigital_tdr_measurement/nidigital_tdr_measurement.py new file mode 100644 index 000000000..d4149667b --- /dev/null +++ b/src/nidigital/examples/nidigital_tdr_measurement/nidigital_tdr_measurement.py @@ -0,0 +1,72 @@ +#!/usr/bin/python + +import argparse +import nidigital +import os +import sys + + +def example(resource_name, options, channel_list, endpoint_termination, apply_offsets): + directory = os.path.dirname(os.path.abspath(__file__)) + + with nidigital.Session(resource_name=resource_name, options=options, reset_device=True) as session: + try: + pin_map_filename = os.path.join(directory, 'PinMap.pinmap') + session.load_pin_map(pin_map_filename) + + session.tdr_endpoint_termination = endpoint_termination + + # Measure propagation delays and optionally apply the offsets to compensate for them. + print('Start TDR Measurement') + offsets = session.channels[channel_list].tdr(apply_offsets=apply_offsets) + offsets_in_seconds = [offset.total_seconds() for offset in offsets] + + print('TDR Offsets (seconds): {}'.format(offsets_in_seconds)) + finally: + session.channels[channel_list].selected_function = nidigital.SelectedFunction.DISCONNECT + + print('Done TDR Measurement') + return offsets + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Demonstrates how to use Time-Domain Reflectometry (TDR) to measure propagation delays through cables, connectors, and load boards. Use a 50 ohm controlled-impedance system and ensure an open or short exists at the selected TDR plane.', 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('-c', '--channel-list', default='PinGroup1', help='List of channels or pins to measure.') + parser.add_argument('-e', '--tdr-endpoint-termination', default='OPEN', type=str.upper, choices=nidigital.TDREndpointTermination.__members__, help='Specifies whether TDR Channels are connected to an open circuit or a short to ground.') + parser.add_argument('-a', '--apply-offsets', default='True', choices=['True', 'False'], help='A Boolean that specifies whether to apply the measured TDR offsets.') + args = parser.parse_args(argsv) + + example(args.resource_name, + 'Simulate=1, DriverSetup=Model:6570' if args.simulate == 'True' else '', + args.channel_list, + nidigital.TDREndpointTermination[args.tdr_endpoint_termination], + args.apply_offsets == 'True') + + +def main(): + _main(sys.argv[1:]) + + +def test_main(): + _main([]) + _main(['--tdr-endpoint-termination', 'SHORT_TO_GROUND', '--apply-offsets', 'False']) + + +def test_example(): + resource_name = 'PXI1Slot2,PXI1Slot3' + options = {'simulate': True, 'driver_setup': {'Model': '6570'}, } + channel_list = 'PinGroup1' + + endpoint_termination = nidigital.TDREndpointTermination.OPEN + example(resource_name, options, channel_list, endpoint_termination, apply_offsets=True) + example(resource_name, options, channel_list, endpoint_termination, apply_offsets=False) + + endpoint_termination = nidigital.TDREndpointTermination.SHORT_TO_GROUND + example(resource_name, options, channel_list, endpoint_termination, apply_offsets=True) + example(resource_name, options, channel_list, endpoint_termination, apply_offsets=False) + + +if __name__ == '__main__': + main() diff --git a/src/nidigital/examples/nidigital_tdr_measurement/tdr_measurement.digiproj b/src/nidigital/examples/nidigital_tdr_measurement/tdr_measurement.digiproj new file mode 100644 index 000000000..0cdbde6d5 --- /dev/null +++ b/src/nidigital/examples/nidigital_tdr_measurement/tdr_measurement.digiproj @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file