Skip to content

Adding example in NI-DC Power , NI-DMM , NI-Switch - #2192

Open
bkumarng-NI wants to merge 8 commits into
ni:masterfrom
bkumarng-NI:master
Open

Adding example in NI-DC Power , NI-DMM , NI-Switch#2192
bkumarng-NI wants to merge 8 commits into
ni:masterfrom
bkumarng-NI:master

Conversation

@bkumarng-NI

@bkumarng-NI bkumarng-NI commented Aug 11, 2026

Copy link
Copy Markdown

What does this Pull Request accomplish?

  • One additional example added in dcpower, dmm and switch drivers.
  • nidcpower_hardware_timed_single_point.py, nidmm_triggered_fetch_waveform.py, niswitch_software_scanning.py
  • Update CHANGELOG.md to call out the new examples in unreleased section.

List issues fixed by this Pull Request below, if any.

None

What testing has been done?

  • tox completed successfully.
  • pytest src/nidmm/system_tests -c generated/nidmm/tox-system_tests.ini
  • pytest src/nidcpower/system_tests -c generated/nidcpower/tox-system_tests.ini
  • pytest src/niswitch/system_tests -c generated/niswitch/tox-system_tests.ini

Adding one new example each in NI-DMM, NI-DCPower, and NI-SWITCH.
updated CHANGELOG.md to include additional examples added in nidcpower, nidmm, niswitch in "unreleased section.
@codecov-commenter

codecov-commenter commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.59%. Comparing base (5f12b7a) to head (6005021).

❌ Your project status has failed because the head coverage (81.59%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (5f12b7a) and HEAD (6005021). Click for more details.

HEAD has 14 uploads less than BASE
Flag BASE (5f12b7a) HEAD (6005021)
nidcpowerunittests 5 4
nidigitalunittests 5 4
nimodinstunittests 5 4
niscopeunittests 5 4
nitclkunittests 5 4
nisesystemtests 1 0
nirfsgsystemtests 1 0
nidigitalsystemtests 1 0
niswitchsystemtests 1 0
nifgensystemtests 1 0
nidmmsystemtests 1 0
niscopesystemtests 1 0
nidcpowersystemtests 1 0
nitclksystemtests 1 0
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2192      +/-   ##
==========================================
- Coverage   89.32%   81.59%   -7.73%     
==========================================
  Files          73       31      -42     
  Lines       19048     4308   -14740     
==========================================
- Hits        17014     3515   -13499     
+ Misses       2034      793    -1241     
Flag Coverage Δ
codegenunittests 84.90% <ø> (ø)
nidcpowersystemtests ?
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests ?
nidigitalunittests 68.44% <ø> (ø)
nidmmsystemtests ?
nifakeunittests 86.01% <ø> (ø)
nifgensystemtests ?
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
nirfsgsystemtests ?
niscopesystemtests ?
niscopeunittests 43.20% <ø> (ø)
nisesystemtests ?
niswitchsystemtests ?
nitclksystemtests ?
nitclkunittests 98.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 46 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f12b7a...6005021. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ni-jfitzger

Copy link
Copy Markdown
Collaborator

Summary
Added a new NI-DMM example.

Added a new NI-DCPower example.

Added a new NI-SWITCH example.

This contribution adheres to CONTRIBUTING.md

I've updated CHANGELOG.md.

Please stick to the pull request template.

- [ ] This contribution adheres to [CONTRIBUTING.md](https://github.com/ni/nimi-python/blob/master/CONTRIBUTING.md).
- [ ] I've updated [CHANGELOG.md](https://github.com/ni/nimi-python/blob/master/CHANGELOG.md) if applicable.
- [ ] I've added tests applicable for this pull request

Include all 3, place an X to fill in the checkbox, where appropriate, and strikethrough anything that doesn't apply.
Details about your changes can go in the "What does this Pull Request accomplish?" section.

@ni-jfitzger ni-jfitzger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to run tox -e codegen to regenerate the examples documentation and then commit the change, so that Travis CI won't fail.

@bkumarng-NI

Copy link
Copy Markdown
Author

You need to run tox -e codegen to regenerate the examples documentation and then commit the change, so that Travis CI won't fail.
I have ran tox -e codegen` and "Travis CI " is passing now. Also updated the PR details as per template. Kindly let me know if still any concerns.

import argparse # For parsing command-line arguments
import sys # For accessing command-line arguments via sys.argv

import nidcpower # NI-DCPower instrument driver (SMU trigger source)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't add this dependency on another nimi-python API without updating generated/nidmm/tox-system_tests.ini via changes to build/templates/tox-system_tests.ini.mako.

Whether we should add such an example is a separate issue. This change would also force changes to our post-release checks and internal test events.

def test_example():
"""Simulated hardware test — runs example() with virtual NI-2568 switch (no real HW needed)."""
example(
resource_name='PXI2568',

@ni-jfitzger ni-jfitzger Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why it should matter, but you may need to stick with the pattern of passing an empty string, established by the other niswitch examples. The driver doesn't seem to like you passing this string, when simulating.

Comment on lines +121 to +122
options = {'simulate': True, 'driver_setup': {'Model': '4139', 'BoardType': 'PXIe'}}
example('PXI1Slot1', options, 2.0, 4.0, 10.0, 0.01, 0.01, 0.05)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a DAQmx-based device. IVI Simulation of such devices sometimes fails. Pick a different device.

@marcoskirsch

Copy link
Copy Markdown
Member

Please spell product names correctly. e.g. driver is NI-SWITCH.
Please spell Python module names correctly. e.g. there is no dcpower.

This is a public repo and we should be professional.

@marcoskirsch

Copy link
Copy Markdown
Member

I reviewed only one example. Once the feedback is applied to the rest please reset my feedback.

:encoding: utf8
:caption: `(niswitch_relay_control.py) <https://github.com/ni/nimi-python/blob/master/src/niswitch/examples/niswitch_relay_control.py>`_

niswitch_software_scanning.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is wise to add scanning examples. This is a feature no longer supported by any of the switches developed in the last ~18 years.

-vl1 3.0 -vl2 5.0 -sd 0.1

iii. To simulate without hardware:
PowerShell: python nidcpower_hardware_timed_single_point.py \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Powershell and cmd instructions look the same to me. Do you need both? If you do, then you definitely need Linux.

But I don't think we need both.

"""

# Module imports
import argparse # For parsing command-line arguments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these comments consistent with all other examples? If they are, ok.
If they aren't please remove. I don't think they add much value.

"""Core measurement logic — sources two voltage levels sequentially and returns both measurements.

Args:
resource_name (str) : NI-MAX resource name, eg: "PXI1Slot2"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this consistent with all our other examples?
NI MAX is spelled with no dash, and is deprecated.

I would imagine the documentation when setting up argparse would suffice. DRY.

current_limit_range (float) : Current range — must be >= current_limit (A)
source_delay (float) : Delay before Source Complete Event fires(s)
"""
# 'with' block ensures session.abort() + session.close() are called automatically on exit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this with block only ensures session.close() is called.

with nidcpower.Session(resource_name=resource_name, reset=True, channels=0, options=options) as session:

# Configure source mode and output function.
# SINGLE_POINT: sources one value and holds; voltage_level can be changed mid-session.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of mid-session you should say it can be "set while in the running state"

session.source_delay = source_delay
session.measure_when = nidcpower.MeasureWhen.AUTOMATICALLY_AFTER_SOURCE_COMPLETE

# Commit sends all settings to hardware before initiate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, there is no point in explicitly calling commit


# Initiate output, fetch at voltage_level_1, change to voltage_level_2, fetch again.
# timeout=1.0 s — adjust if source_delay is longer than 1 s.
with session.initiate():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this context manager ensures abort() is closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants