Repository navigation
Adding Measure Frequency in NI-DMM #2226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NI-velmurugan
wants to merge
8
commits into
ni:master
Choose a base branch
from
NI-velmurugan:users/velmurugan/add-nidmm-measure-frequency
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f135c6a
Adding Measure Frequency in NI-DMM
NI-velmurugan c607911
Rename the function for frequency
NI-velmurugan 65f1330
updating the CLI parms
NI-velmurugan d6f79b5
Fixing the PR comments
NI-velmurugan ac5b768
Trigger CI build
NI-velmurugan c9c70cb
Trigger CI build
NI-velmurugan d841f3e
Apply nits to frequency example
divakar-selvam07 4ae565a
Trigger CI build
NI-velmurugan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||
| #!/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 | ||||||
| # Required by configure_measurement_digits(); 5.5 is the driver's documented default | ||||||
| RESOLUTION_DIGITS = 5.5 | ||||||
|
|
||||||
|
|
||||||
| def example(resource_name, options, function, range, max_amplitude): | ||||||
| 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 | ||||||
| # The driver reports warnings through Python's warnings module; the warning code is included in the message. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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(word.message) for word 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('-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) | ||||||
|
|
||||||
|
|
||||||
| 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() | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.