From 9e19dc5116a750854c4d1095f608cac831475c8a Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 13 Oct 2026 12:46:04 +0000 Subject: [PATCH 1/4] Adding Measure Capacitance example in NI-DMM --- CHANGELOG.md | 1 + docs/nidmm/examples.rst | 9 ++++ .../examples/nidmm_measure_capacitance.py | 47 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/nidmm/examples/nidmm_measure_capacitance.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 86a8d9eb3..370a19d08 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_measure_capacitance.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..f57e5d071 100644 --- a/docs/nidmm/examples.rst +++ b/docs/nidmm/examples.rst @@ -21,6 +21,15 @@ nidmm_measure_ac_volts.py :encoding: utf8 :caption: `(nidmm_measure_ac_volts.py) `_ +nidmm_measure_capacitance.py +---------------------------- + +.. literalinclude:: ../../src/nidmm/examples/nidmm_measure_capacitance.py + :language: python + :linenos: + :encoding: utf8 + :caption: `(nidmm_measure_capacitance.py) `_ + nidmm_measurement.py -------------------- diff --git a/src/nidmm/examples/nidmm_measure_capacitance.py b/src/nidmm/examples/nidmm_measure_capacitance.py new file mode 100644 index 000000000..0872fd596 --- /dev/null +++ b/src/nidmm/examples/nidmm_measure_capacitance.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +import argparse +import math +import nidmm +import sys + + +def example(resource_name, options, function, range, measurements_to_average): + with nidmm.Session(resource_name=resource_name, options=options) as session: + # Resolution is ignored for capacitance and inductance, but the driver still validates it (3.5, 4.5, 5.5 or 6.5). + session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=range, resolution_digits=5.5) + session.lc_number_meas_to_average = measurements_to_average + measurement = session.read() + # NI-DMM reports an underrange condition as negative infinity. + under_range = math.isinf(measurement) and measurement < 0 + print(f'Measurement (Farads): {measurement}') + print(f'Signal Under Range: {under_range}') + + +def _main(argsv): + parser = argparse.ArgumentParser(description='Performs a single capacitance measurement using the NI-DMM API (NI 4072/4082 only).', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('-n', '--resource-name', default='PXI1Slot4', help='Contains the resource_name of the device to initialize.') + parser.add_argument('-f', '--function', default='CAPACITANCE', choices=list(('CAPACITANCE', 'INDUCTANCE')), type=str.upper, help='Specifies the measurement_function used to acquire the measurement.') + parser.add_argument('-r', '--range', default=3e-10, type=float, help='Specifies the range for the function specified in the Measurement_Function parameter.') + parser.add_argument('-a', '--measurements-to-average', default=1, type=int, help='For the NI 4072 only, specifies the number of LC measurements that are averaged to produce one reading.') + 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) + example(args.resource_name, args.option_string, args.function, args.range, args.measurements_to_average) + + +def main(): + _main(sys.argv[1:]) + + +def test_example(): + options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, } + example('PXI1Slot2', options, 'CAPACITANCE', 3e-10, 1) + + +def test_main(): + cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe', ] + _main(cmd_line) + + +if __name__ == '__main__': + main() From 93b80b113afcbda268e7421370b0aa72447a99ba Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Tue, 13 Oct 2026 13:00:02 +0000 Subject: [PATCH 2/4] Adding Measure Capacitance example in NI-DMM --- src/nidmm/examples/nidmm_measure_capacitance.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/nidmm/examples/nidmm_measure_capacitance.py b/src/nidmm/examples/nidmm_measure_capacitance.py index 0872fd596..c5c62af96 100644 --- a/src/nidmm/examples/nidmm_measure_capacitance.py +++ b/src/nidmm/examples/nidmm_measure_capacitance.py @@ -3,11 +3,20 @@ import argparse import math import nidmm +import re import sys +# Only these models support capacitance measurements. +SUPPORTED_MODELS = ('4072', '4082') + def example(resource_name, options, function, range, measurements_to_average): with nidmm.Session(resource_name=resource_name, options=options) as session: + model_match = re.search('[0-9]+', session.instrument_model) + model = model_match.group() if model_match else '' + if model not in SUPPORTED_MODELS: + print(f'{session.instrument_model} does not support capacitance measurements.\r\nSupported models: NI {", NI ".join(SUPPORTED_MODELS)}.') + return # Resolution is ignored for capacitance and inductance, but the driver still validates it (3.5, 4.5, 5.5 or 6.5). session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=range, resolution_digits=5.5) session.lc_number_meas_to_average = measurements_to_average @@ -19,9 +28,10 @@ def example(resource_name, options, function, range, measurements_to_average): def _main(argsv): + supported_functions = list(nidmm.Function.__members__.keys()) parser = argparse.ArgumentParser(description='Performs a single capacitance measurement using the NI-DMM API (NI 4072/4082 only).', formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('-n', '--resource-name', default='PXI1Slot4', help='Contains the resource_name of the device to initialize.') - parser.add_argument('-f', '--function', default='CAPACITANCE', choices=list(('CAPACITANCE', 'INDUCTANCE')), type=str.upper, help='Specifies the measurement_function used to acquire the measurement.') + parser.add_argument('-n', '--resource-name', default='PXI1Slot2', help='Contains the resource_name of the device to initialize.') + parser.add_argument('-f', '--function', default='CAPACITANCE', choices=supported_functions, type=str.upper, help='Specifies the measurement_function used to acquire the measurement.') parser.add_argument('-r', '--range', default=3e-10, type=float, help='Specifies the range for the function specified in the Measurement_Function parameter.') parser.add_argument('-a', '--measurements-to-average', default=1, type=int, help='For the NI 4072 only, specifies the number of LC measurements that are averaged to produce one reading.') parser.add_argument('-op', '--option-string', default='', type=str, help='Sets the initial value of certain attributes for the session.') From e7d6b1a8152e3e3c364906719fdf41701cc9a914 Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Wed, 14 Oct 2026 05:21:35 +0000 Subject: [PATCH 3/4] Trigger CI build From e92fc8d47267608a12dd7a72521681a69760e6da Mon Sep 17 00:00:00 2001 From: NI-velmurugan Date: Wed, 14 Oct 2026 06:00:47 +0000 Subject: [PATCH 4/4] Trigger CI build