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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,13 @@
#### [nidmm] Unreleased
- Added
- Added the `nidmm_measure_ac_volts.py` example.
- Added the `nidmm_measure_temperature_thermistor.py` example.
- Added the `nidmm_improve_dc_noise_rejection.py` example.
- 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_temperature_rtd.py` example.
- Added the `nidmm_measure_temperature_thermistor.py` example.
- Added the `nidmm_measure_temperature_thermocouple.py` example.
- Added the `nidmm_improve_dc_noise_rejection.py` example.
- (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies.
- Changed
- Removed
Expand Down
9 changes: 9 additions & 0 deletions docs/nidmm/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Examples

`You can download all nidmm examples for latest version here <https://github.com/ni/nimi-python/releases/download/nidmm-1.5.0/nidmm_examples.zip>`_

nidmm_cont_acq_multiple_samples_ext_trig.py
-------------------------------------------

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

nidmm_diode_test.py
-------------------

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

import argparse
import nidmm
import sys

# Maximum points a single fetch_multi_point call can return in a continuous acquisition, per the array_size documentation
MAX_SAMPLES_PER_FETCH = 100000


def example(resource_name, options, function, measurement_range, digits, trigger_source, total_samples):
print(f'Starting acquisition on resource {resource_name}, for {total_samples} samples.')
with nidmm.Session(resource_name=resource_name, reset_device=True, options=options) as session:
session.configure_measurement_digits(measurement_function=nidmm.Function[function], range=measurement_range, resolution_digits=digits)
# Trigger slopes use driver defaults because the public API has no slope configuration (#875).
session.configure_trigger(trigger_source=nidmm.TriggerSource[trigger_source])
# The sample trigger uses the same source as the trigger; a sample_count of 0 configures a continuous acquisition
session.configure_multi_point(trigger_count=1, sample_count=0, sample_trigger=nidmm.SampleTrigger[trigger_source])

samples_fetched = 0
with session.initiate():
while samples_fetched < total_samples:
backlog, _ = session.read_status()
if backlog > 0:
new_samples = session.fetch_multi_point(array_size=min(backlog, MAX_SAMPLES_PER_FETCH))
samples_fetched += len(new_samples)

print(f'Fetched {samples_fetched} readings.')


def _main(argsv):
parser = argparse.ArgumentParser(description='Acquires measurements on each trigger 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='DC_VOLTS', choices=nidmm.Function.__members__.keys(), type=str.upper, help='Specifies the measurement_function used to acquire the measurement.')
parser.add_argument('-r', '--range', default=10, type=float, help='Specifies the range for the function specified in the Measurement_Function parameter.')
parser.add_argument('-d', '--digits', default=5.5, type=float, help='Specifies the resolution of the measurement in digits.')
parser.add_argument('-t', '--trigger-source', default='EXTERNAL', choices=nidmm.TriggerSource.__members__.keys(), type=str.upper, help='Specifies the trigger source that initiates the acquisition.')
parser.add_argument('--total-samples', default=100, type=int, help='Number of readings to fetch before stopping.')
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.digits, args.trigger_source, args.total_samples)


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


def test_example():
options = {'simulate': True, 'driver_setup': {'Model': '4082', 'BoardType': 'PXIe', }, }
example('PXI1Slot2', options, 'DC_VOLTS', 10, 5.5, 'IMMEDIATE', 10)


def test_main():
cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:4082; BoardType:PXIe', '--trigger-source', 'IMMEDIATE', '--total-samples', '10', ]
_main(cmd_line)


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