-
Notifications
You must be signed in to change notification settings - Fork 0
Analog Input - Filtering #114
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
Merged
DilmiWickramanayake
merged 130 commits into
main
from
users/DilmiWickramanayake/Analog_Input_filtering
Jul 25, 2025
Merged
Changes from all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
b7abc39
Analog Input - Voltage and Thermocouple Single Task
aa6488a
Merge branch 'main' of https://github.com/ni/nipanel-python
6d2ec85
Merge branch 'main' of https://github.com/ni/nipanel-python
89d9c2e
Merge branch 'main' of https://github.com/ni/nipanel-python
871f6e1
add niscope
336d7b5
Rename
31e7f0c
Merge branch 'main' of https://github.com/ni/nipanel-python
5f7776f
Merge branch 'main' into users/DilmiWickramanayake/niscope_ex_fetch_f…
1b00959
Merge branch 'main' into users/DilmiWickramanayake/niscope_ex_fetch_f…
5534c9a
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
6083519
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
01a2e08
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
435aedd
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
8dbd7d0
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
b6e43c6
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
9643953
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
66808fb
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
afeb185
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
eb3da14
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
8b9cc4a
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
b27c77f
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
94a0afc
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
0d720c5
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
be1839f
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
4e7e158
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
c394513
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
fe6a780
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
498c199
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
c4d6d7d
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
414257d
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
5b7d789
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
742b685
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
e50dadc
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
838cd70
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
7338e2c
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
e99a548
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
93fede0
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
b2bfe84
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
5cdc785
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
a80d753
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
2056cf3
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
f1395d6
Merge branch 'users/DilmiWickramanayake/niscope_ex_fetch_forever' of …
a8f847b
Analog Input Filtering
24c532b
Merge branch 'main' of https://github.com/ni/nipanel-python into user…
27a8154
Merge branch 'main' of https://github.com/ni/nipanel-python
4d49c37
Merge branch 'main' of https://github.com/ni/nipanel-python
2fedc38
Merge branch 'main' of https://github.com/ni/nipanel-python into user…
8c70ac5
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
4937acd
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
d50204f
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
5d2d549
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
577b344
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
4807eb1
Merge branch 'main' of https://github.com/ni/nipanel-python
0a8da81
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input_filte…
a82f608
Completed Task Settings
c62c497
Merge branch 'main' of https://github.com/ni/nipanel-python
e667025
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input_filte…
39959b5
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input_filte…
0988885
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
0f7ddc1
Added README.md
79ae4db
fixed mypy & lint errors
957ef54
fixed mypy & lint errors
8422770
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
ee296f9
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
a03250b
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
2655fd9
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
9efb83a
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
886623e
Revert changes
28f2209
simple graph changes
709d47e
simple graph changes
372531f
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
a2a803e
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
7c6737b
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
56f5e10
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
374ef68
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
219c2de
Update simple_graph.py
DilmiWickramanayake 809ced3
Poetry lock
fcbc70c
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
e5e2b9b
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
f241821
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
81114c4
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
fd75741
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
3a043a7
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
ee3ff1d
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
ffca8c1
update lint errors
66faa59
update lint errors
29835f5
Merge branch 'main' of https://github.com/ni/nipanel-python
82c2b7f
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input_filte…
a69ad29
fix changes to filtering
2f569a8
fix changes to filtering
fb2b46f
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
c385fb2
changes to poetry lock file
1ab9fa6
changes to poetry lock file
85a7856
Merge branch 'users/DilmiWickramanayake/Analog_Input_filtering' of ht…
6354786
Pyright error
722c3d5
lint error
bbdeb81
fixed errors
065d6f4
Fixed panel comments
3a22846
Fixed panel comments
f48c26b
format number input
92b3260
format number input
68db2a4
adding number format
ee3f07a
lint errors fixed
62aa111
fixing lint errors
d89726c
changed source settings
4ca3b00
setting source up
098d9fb
fixing lint error
d0cb228
resolved comments
ded87ce
deleting unecessary variables
585f3e4
Merge branch 'main' of https://github.com/ni/nipanel-python
2d31d50
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input_filte…
f158a15
updated run button and panel methods
be3c739
setting default values
207fe57
adding daq errors
f19d608
README.md changes
d06a4fd
error handling
338424d
rename daq_errors -> daq_error
2b1af62
rename daq_error
25294c4
source now works
ec42095
fix lint errors
4721e33
remove comment
9105a3a
remove logging
e4a9179
disable run button
8440772
added onboard clock
76a8d26
renaming hide_button method
9d2f392
fixing mypy error
282c530
lint error
80970c4
removed function and simplified code
2d4b95e
remove analog output and markdown
5401b66
renaming labels
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Prerequisites | ||
| =============== | ||
| Requires a Physical or Simulated Device. Refer to the [Getting Started Section](https://github.com/ni/nidaqmx-python/blob/master/README.rst) to learn how to create a simulated device. | ||
| ## Sample | ||
|
|
||
| This is an nipanel example that displays an interactive Streamlit app and updates and fetches data from device. | ||
|
|
||
| ### Feature | ||
|
|
||
| Script demonstrates analog input data getting continuously acquired, and being filtered. | ||
| - Supports various data types | ||
|
|
||
| ### Required Software | ||
|
|
||
| - Python 3.9 or later | ||
|
|
||
| ### Usage | ||
|
|
||
| ```pwsh | ||
| poetry install --with examples | ||
| poetry run python examples\nidaqmx\nidaqmx_analog_input_filtering\nidaqmx_analog_input_filtering.py | ||
| ``` | ||
|
|
154 changes: 154 additions & 0 deletions
154
examples/nidaqmx/nidaqmx_analog_input_filtering/nidaqmx_analog_input_filtering.py
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,154 @@ | ||
| """Data acquisition script that continuously acquires analog input data.""" | ||
|
|
||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import nidaqmx | ||
| import nidaqmx.system | ||
| from nidaqmx.constants import ( | ||
| AcquisitionType, | ||
| CurrentShuntResistorLocation, | ||
| CurrentUnits, | ||
| Edge, | ||
| ExcitationSource, | ||
| FilterResponse, | ||
| Slope, | ||
| StrainGageBridgeType, | ||
| TerminalConfiguration, | ||
| ) | ||
| from nidaqmx.errors import DaqError | ||
|
|
||
| import nipanel | ||
|
|
||
| panel_script_path = Path(__file__).with_name("nidaqmx_analog_input_filtering_panel.py") | ||
| panel = nipanel.create_streamlit_panel(panel_script_path) | ||
| panel.set_value("is_running", False) | ||
|
|
||
| system = nidaqmx.system.System.local() | ||
|
|
||
| available_channel_names = [] | ||
| for dev in system.devices: | ||
| for chan in dev.ai_physical_chans: | ||
| available_channel_names.append(chan.name) | ||
| panel.set_value("available_channel_names", available_channel_names) | ||
|
|
||
| available_trigger_sources = [""] | ||
| for dev in system.devices: | ||
| if hasattr(dev, "terminals"): | ||
| for term in dev.terminals: | ||
| available_trigger_sources.append(term) | ||
| panel.set_value("available_trigger_sources", available_trigger_sources) | ||
| try: | ||
| panel.set_value("daq_error", "") | ||
| print(f"Panel URL: {panel.panel_url}") | ||
| print(f"Waiting for the 'Run' button to be pressed...") | ||
| print(f"(Press Ctrl + C to quit)") | ||
| while True: | ||
| panel.set_value("run_button", False) | ||
| while not panel.get_value("run_button", False): | ||
| time.sleep(0.1) | ||
| # How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/ | ||
| with nidaqmx.Task() as task: | ||
|
|
||
| chan_type = panel.get_value("chan_type", "1") | ||
|
|
||
| if chan_type == "2": | ||
| chan = task.ai_channels.add_ai_current_chan( | ||
| panel.get_value("physical_channel", ""), | ||
| max_val=panel.get_value("max_value_current", 0.01), | ||
| min_val=panel.get_value("min_value_current", -0.01), | ||
| ext_shunt_resistor_val=panel.get_value("shunt_resistor_value", 249.0), | ||
| shunt_resistor_loc=panel.get_value( | ||
| "shunt_location", CurrentShuntResistorLocation.EXTERNAL | ||
| ), | ||
| units=panel.get_value("units", CurrentUnits.AMPS), | ||
| ) | ||
|
|
||
| elif chan_type == "3": | ||
| chan = task.ai_channels.add_ai_strain_gage_chan( | ||
| panel.get_value("physical_channel", ""), | ||
| nominal_gage_resistance=panel.get_value("gage_resistance", 350.0), | ||
| voltage_excit_source=ExcitationSource.EXTERNAL, # Only mode that works | ||
| max_val=panel.get_value("max_value_strain", 0.001), | ||
| min_val=panel.get_value("min_value_strain", -0.001), | ||
| poisson_ratio=panel.get_value("poisson_ratio", 0.3), | ||
| lead_wire_resistance=panel.get_value("wire_resistance", 0.0), | ||
| initial_bridge_voltage=panel.get_value("initial_voltage", 0.0), | ||
| gage_factor=panel.get_value("gage_factor", 2.0), | ||
| voltage_excit_val=panel.get_value("voltage_excitation_value", 0.0), | ||
| strain_config=panel.get_value( | ||
| "strain_configuration", StrainGageBridgeType.FULL_BRIDGE_I | ||
| ), | ||
| ) | ||
| else: | ||
| chan = task.ai_channels.add_ai_voltage_chan( | ||
| panel.get_value("physical_channel", ""), | ||
| terminal_config=panel.get_value( | ||
| "terminal_configuration", TerminalConfiguration.DEFAULT | ||
| ), | ||
| max_val=panel.get_value("max_value_voltage", 5.0), | ||
| min_val=panel.get_value("min_value_voltage", -5.0), | ||
| ) | ||
| task.timing.cfg_samp_clk_timing( | ||
| source=panel.get_value("source", ""), # "" - means Onboard Clock (default value) | ||
| rate=panel.get_value("rate", 1000.0), | ||
| sample_mode=AcquisitionType.CONTINUOUS, | ||
| samps_per_chan=panel.get_value("total_samples", 100), | ||
| ) | ||
| panel.set_value("sample_rate", task.timing.samp_clk_rate) | ||
| # Not all hardware supports all filter types. | ||
| # Refer to your device documentation for more information. | ||
| if panel.get_value("filter", "Filter") == "Filter": | ||
| chan.ai_filter_enable = True | ||
| chan.ai_filter_freq = panel.get_value("filter_freq", 0.0) | ||
| chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB) | ||
| chan.ai_filter_order = panel.get_value("filter_order", 1) | ||
| panel.set_value("actual_filter_freq", chan.ai_filter_freq) | ||
| panel.set_value("actual_filter_response", chan.ai_filter_response) | ||
| panel.set_value("actual_filter_order", chan.ai_filter_order) | ||
| else: | ||
| panel.set_value("actual_filter_freq", 0.0) | ||
| panel.set_value("actual_filter_response", FilterResponse.COMB) | ||
| panel.set_value("actual_filter_order", 0) | ||
| # Not all hardware supports all filter types. | ||
| # Refer to your device documentation for more information. | ||
| trigger_type = panel.get_value("trigger_type") | ||
| if trigger_type == "5": | ||
| task.triggers.start_trigger.cfg_anlg_edge_start_trig( | ||
| trigger_source=panel.get_value("analog_source", ""), | ||
| trigger_slope=panel.get_value("slope", Slope.FALLING), | ||
| trigger_level=panel.get_value("level", 0.0), | ||
| ) | ||
|
|
||
| if trigger_type == "2": | ||
| task.triggers.start_trigger.cfg_dig_edge_start_trig( | ||
| trigger_source=panel.get_value("digital_source", ""), | ||
| trigger_edge=panel.get_value("edge", Edge.FALLING), | ||
| ) | ||
| task.triggers.start_trigger.anlg_edge_hyst = hysteresis = panel.get_value( | ||
| "hysteresis", 0.0 | ||
| ) | ||
|
|
||
| try: | ||
| task.start() | ||
| panel.set_value("is_running", True) | ||
|
|
||
| panel.set_value("stop_button", False) | ||
| while not panel.get_value("stop_button", False): | ||
| data = task.read( | ||
| number_of_samples_per_channel=100 # pyright: ignore[reportArgumentType] | ||
| ) | ||
| panel.set_value("acquired_data", data) | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| task.stop() | ||
| panel.set_value("is_running", False) | ||
|
|
||
| except DaqError as e: | ||
| daq_error = str(e) | ||
| print(daq_error) | ||
| panel.set_value("daq_error", daq_error) | ||
|
|
||
| except KeyboardInterrupt: | ||
| pass | ||
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.