-
Couldn't load subscription status.
- Fork 0
Add Configured Aquisition example #132
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
hellovolcano
merged 3 commits into
main
from
users/DilmiWickramanayake/niscope_configured
Aug 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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. This example uses NI oscilloscopes and digitizers like the NI PXIe-5114 | ||
|
|
||
| ## Sample | ||
|
|
||
| This is an nipanel example that displays an interactive Streamlit app and updates and fetches data from an NI device. | ||
|
|
||
| ### Feature | ||
|
|
||
| Script demonstrates waveform data getting continuously acquired and being converted to binary data. | ||
| - Supports various data types | ||
|
|
||
| ### Required Software | ||
|
|
||
| - Python 3.9 or later | ||
|
|
||
| ### Usage | ||
|
|
||
| ```pwsh | ||
| poetry install --with examples | ||
| poetry run examples\niscope\niscope_configured_acquisition\niscope_configured_acquisition.py | ||
| ``` | ||
119 changes: 119 additions & 0 deletions
119
examples/niscope/niscope_configured_acquisition/niscope_configured_acquisition.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,119 @@ | ||
| """Continuously acquires waveforms from NI-SCOPE, processes/scales them.""" | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import hightime | ||
| import niscope | ||
| import numpy as np | ||
| from niscope.errors import Error | ||
|
|
||
| import nipanel | ||
|
|
||
| panel_script_path = Path(__file__).with_name("niscope_configured_acquisition_panel.py") | ||
| panel = nipanel.create_streamlit_panel(panel_script_path) | ||
|
|
||
| panel.set_value("is_running", False) | ||
| panel.set_value("run_button", False) | ||
|
|
||
| try: | ||
| panel.set_value("scope_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) | ||
| with niscope.Session(resource_name=panel.get_value("resource_name", "Dev1")) as session: | ||
| session.configure_vertical( | ||
| range=panel.get_value("vertical_range", 5.0), | ||
| coupling=niscope.VerticalCoupling.DC, | ||
| offset=panel.get_value("vertical_offset", 0.0), | ||
| ) | ||
| session.configure_chan_characteristics( | ||
| input_impedance=panel.get_value("input_impedance", 1.0e6), | ||
| max_input_frequency=panel.get_value("max_input_frequency", 100.0e6), | ||
| ) | ||
| session.configure_horizontal_timing( | ||
| min_sample_rate=panel.get_value("min_sample_rate", 10.0e6), | ||
| min_num_pts=panel.get_value("min_record_length", 1000), | ||
| ref_position=panel.get_value("ref_position", 0.0), | ||
| num_records=1000, | ||
| enforce_realtime=panel.get_value("enforce_realtime", True), | ||
| ) | ||
| trigger_type = int(panel.get_value("trigger_type", "1")) | ||
| if trigger_type == 1: | ||
| immediate = session.configure_trigger_immediate() | ||
| elif trigger_type == 2: | ||
| edge = session.configure_trigger_edge( | ||
| trigger_source=str(panel.get_value("edge_source", 0)), | ||
| level=panel.get_value("edge_level", 0.0), | ||
| slope=panel.get_value("edge_slope", niscope.TriggerSlope.POSITIVE), | ||
| trigger_coupling=panel.get_value("edge_coupling", niscope.TriggerCoupling.DC), | ||
| delay=hightime.timedelta(seconds=panel.get_value("digital_delay", 0.0)), | ||
| ) | ||
| elif trigger_type == 3: | ||
| digital = session.configure_trigger_digital( | ||
| trigger_source=panel.get_value("digital_source", "PFI 1"), | ||
| slope=panel.get_value("digital_slope", niscope.TriggerSlope.POSITIVE), | ||
| delay=hightime.timedelta(seconds=panel.get_value("digital_delay", 0.0)), | ||
| ) | ||
| elif trigger_type == 4: | ||
| window = session.configure_trigger_window( | ||
| trigger_source=str(panel.get_value("window_source", 0)), | ||
| window_mode=panel.get_value("window_mode", niscope.TriggerWindowMode.ENTERING), | ||
| low_level=panel.get_value("window_low_level", -0.1), | ||
| high_level=panel.get_value("window_high_level", 0.1), | ||
| trigger_coupling=panel.get_value("window_coupling", niscope.TriggerCoupling.DC), | ||
| delay=hightime.timedelta(seconds=panel.get_value("digital_delay", 0.0)), | ||
| ) | ||
| else: | ||
| hysteresis = session.configure_trigger_hysteresis( | ||
| trigger_source=str(panel.get_value("hysteresis_source", 0)), | ||
| level=panel.get_value("hysteresis_level", 0.0), | ||
| hysteresis=panel.get_value("hysteresis", 0.05), | ||
| slope=panel.get_value("hysteresis_slope", niscope.TriggerSlope.POSITIVE), | ||
| trigger_coupling=panel.get_value( | ||
| "hysteresis_coupling", niscope.TriggerCoupling.DC | ||
| ), | ||
| delay=hightime.timedelta(seconds=panel.get_value("digital_delay", 0.0)), | ||
| ) | ||
|
|
||
| with session.initiate(): | ||
| wfm = np.array( | ||
| session.channels[panel.get_value("channel_number", 0)].fetch( | ||
| num_samples=1000, | ||
| num_records=1000, | ||
| relative_to=niscope.FetchRelativeTo.READ_POINTER, | ||
| offset=0, | ||
| timeout=hightime.timedelta(seconds=panel.get_value("timeout", 5.0)), | ||
| ) | ||
| ) | ||
| try: | ||
| panel.set_value("is_running", True) | ||
|
|
||
| panel.set_value("stop_button", False) | ||
| while not panel.get_value("stop_button", False): | ||
|
|
||
| for i in range(len(wfm)): | ||
| if panel.get_value("stop_button", True): | ||
| break | ||
| else: | ||
| data = wfm[i].samples.tolist() | ||
| panel.set_value("waveform_data", data) | ||
| panel.set_value("actual_record_length", session.horz_record_length) | ||
| panel.set_value("actual_sample_rate", session.samp_clk_timebase_rate) | ||
| panel.set_value("auto_triggered", session.trigger_auto_triggered) | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| panel.set_value("is_running", False) | ||
|
|
||
| except Error as e: | ||
| scope_error = str(e) | ||
| print(scope_error) | ||
| panel.set_value("scope_error", scope_error) | ||
|
|
||
| except KeyboardInterrupt: | ||
| pass | ||
Oops, something went wrong.
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.