Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@
- Added the `nidmm_cont_acq_multiple_samples_ext_trig.py` example.
- Added the `nidmm_diode_test.py` example.
- Added the `nidmm_measure_capacitance.py` example.
- Added the `nidmm_measure_frequency.py` example.
- Added the `nidmm_measure_temperature_rtd.py` example.
- Added the `nidmm_measure_temperature_thermistor.py` example.
- Added the `nidmm_measure_temperature_thermocouple.py` example.
Expand Down
9 changes: 9 additions & 0 deletions docs/nidmm/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ nidmm_measure_capacitance.py
:encoding: utf8
:caption: `(nidmm_measure_capacitance.py) <https://github.com/ni/nimi-python/blob/master/src/nidmm/examples/nidmm_measure_capacitance.py>`_

nidmm_measure_frequency.py
--------------------------

.. literalinclude:: ../../src/nidmm/examples/nidmm_measure_frequency.py
:language: python
:linenos:
:encoding: utf8
:caption: `(nidmm_measure_frequency.py) <https://github.com/ni/nimi-python/blob/master/src/nidmm/examples/nidmm_measure_frequency.py>`_

nidmm_measure_temperature_rtd.py
--------------------------------

Expand Down
54 changes: 54 additions & 0 deletions src/nidmm/examples/nidmm_measure_frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python

import argparse
import nidmm
import sys
import warnings

# NIDMM_WARN_UNDERRANGE; reported by read() when the input is under range and used here to indicate "signal not detected"
SIGNAL_NOT_DETECTED_WARNING_CODE = 0x3FFA4F80
Comment thread
NI-velmurugan marked this conversation as resolved.
Resolved


def example(resource_name, options, function, range, max_amplitude, resolution_digits=5.5):
with nidmm.Session(resource_name=resource_name, options=options) as session:
session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=range, resolution_digits=resolution_digits)
session.freq_voltage_range = max_amplitude
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always')
measurement = session.read()
signal_not_detected = any(f'Warning {SIGNAL_NOT_DETECTED_WARNING_CODE} occurred' in str(warning.message) for warning in caught)
units = 'Hz' if function == 'FREQ' else 's'
print(f'Measurement ({units}): {measurement}')
print(f'Signal not Detected: {signal_not_detected}')


def _main(argsv):
parser = argparse.ArgumentParser(description='Performs a single frequency or period measurement using the NI-DMM API.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--resource-name', default='PXI1Slot2', help='Contains the resource_name of the device to initialize.')
parser.add_argument('-f', '--function', default='FREQ', choices=['FREQ', 'PERIOD'], type=str.upper, help='Specifies the measurement_function used to acquire the measurement.')
parser.add_argument('-r', '--range', default=20, type=float, help='Specifies the range for the measurement function. For FREQ, the minimum frequency expected in Hz; for PERIOD, the maximum period expected in seconds.')
parser.add_argument('--max-amplitude', default=50, type=float, help='Specifies the maximum amplitude of the input signal for frequency measurements.')
parser.add_argument('--resolution-digits', default=5.5, type=float, help='Specifies the resolution of the measurement in digits.')
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.max_amplitude, args.resolution_digits)


def main():
_main(sys.argv[1:])


def test_example():
options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, }
example('PXI1Slot2', options, 'FREQ', 100, 10)
example('PXI1Slot2', options, 'PERIOD', 0.01, 10)


def test_main():
cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe', ]
_main(cmd_line)
_main(cmd_line + ['--function', 'period', '--range', '0.02'])


if __name__ == '__main__':
main()
Loading