-
Notifications
You must be signed in to change notification settings - Fork 0
Input improvements #106
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
Merged
Input improvements #106
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8be90f7
add numeric and enum inputs to the simple graph example
585948c
get_value returns the enum type when a default is provided
163735b
_sync_session_state()
acc1e9b
GetValueResponse.found
5c1e492
nipanel.enum_selectbox
5c64b0f
fix mypy
3c84a99
start improving daqmx example
0538676
Enhance enum support in Streamlit panel and tests
1fc1ce2
Refactor NI-DAQmx example to enhance channel settings and timing conf…
bd84426
finish updating daqmx example, so all the controls (except I/O) are f…
d4dd4c9
clean up lint and mypy
1b93e88
Merge remote-tracking branch 'origin/main' into users/mprosser/input-…
0cbbee4
update comment in proto file
2a0c4e4
revert simple_graph changes
285401f
put enum_selectbox in a controls folder
2731464
cosmetic improvements for the nidaqmx example panel
80f7d60
flag checkboxes control
3de247e
refactor: reorganize controls imports and update usage in examples
e77345e
cleanup
6d7df1e
feat: implement set_value_if_changed method to optimize value updates…
cb4a743
cleanup
0395bba
cleanup
7c8dc96
uptake latest proto file with optional value in GetValueResponse
4914880
misc feedback
de1a73b
type annotations
d23d9c1
Merge remote-tracking branch 'origin/main' into users/mprosser/input-…
fe0cfc3
improve run/stop button behavior in nidaqmx example
c7318d6
brad's feedback
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 |
|---|---|---|
| @@ -1,20 +1,40 @@ | ||
| """A Streamlit visualization panel for the all_types.py example script.""" | ||
|
|
||
| from enum import Enum, Flag | ||
|
|
||
| import streamlit as st | ||
| from define_types import all_types_with_values | ||
|
|
||
| import nipanel | ||
| import nipanel.controls as ni | ||
|
|
||
|
|
||
| st.set_page_config(page_title="All Types Example", page_icon="📊", layout="wide") | ||
| st.title("All Types Example") | ||
|
|
||
| panel = nipanel.get_panel_accessor() | ||
| for name in all_types_with_values.keys(): | ||
| col1, col2 = st.columns([0.4, 0.6]) | ||
| st.markdown("---") | ||
|
|
||
| default_value = all_types_with_values[name] | ||
| col1, col2, col3 = st.columns([0.2, 0.2, 0.6]) | ||
|
|
||
| with col1: | ||
| st.write(name) | ||
|
|
||
| with col2: | ||
| st.write(panel.get_value(name)) | ||
| if isinstance(default_value, bool): | ||
| st.checkbox(label=name, value=default_value, key=name) | ||
| elif isinstance(default_value, Flag): | ||
| ni.flag_checkboxes(panel, label=name, value=default_value, key=name) | ||
| elif isinstance(default_value, Enum) and not isinstance(default_value, Flag): | ||
| ni.enum_selectbox(panel, label=name, value=default_value, key=name) | ||
| elif isinstance(default_value, int) and not isinstance(default_value, Flag): | ||
| st.number_input(label=name, value=default_value, key=name) | ||
| elif isinstance(default_value, float): | ||
| st.number_input(label=name, value=default_value, key=name, format="%.2f") | ||
| elif isinstance(default_value, str): | ||
| st.text_input(label=name, value=default_value, key=name) | ||
|
|
||
| with col3: | ||
| st.write(panel.get_value(name, default_value=default_value)) | ||
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 |
|---|---|---|
| @@ -1,34 +1,83 @@ | ||
| """Data acquisition script that continuously acquires analog input data.""" | ||
|
|
||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import nidaqmx | ||
| from nidaqmx.constants import AcquisitionType | ||
| from nidaqmx.constants import ( | ||
| AcquisitionType, | ||
| TerminalConfiguration, | ||
| CJCSource, | ||
| TemperatureUnits, | ||
| ThermocoupleType, | ||
| LoggingMode, | ||
| LoggingOperation, | ||
| ) | ||
|
|
||
| import nipanel | ||
|
|
||
| panel_script_path = Path(__file__).with_name("nidaqmx_continuous_analog_input_panel.py") | ||
| panel = nipanel.create_panel(panel_script_path) | ||
|
|
||
| # How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/ | ||
| with nidaqmx.Task() as task: | ||
| task.ai_channels.add_ai_voltage_chan("Dev1/ai0") | ||
| task.ai_channels.add_ai_thrmcpl_chan("Dev1/ai1") | ||
| task.timing.cfg_samp_clk_timing( | ||
| rate=1000.0, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=3000 | ||
| ) | ||
| panel.set_value("sample_rate", task._timing.samp_clk_rate) | ||
| task.start() | ||
| try: | ||
| print(f"Panel URL: {panel.panel_url}") | ||
| try: | ||
| print(f"Press Ctrl + C to stop") | ||
| while True: | ||
| data = task.read( | ||
| number_of_samples_per_channel=1000 # pyright: ignore[reportArgumentType] | ||
| 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: | ||
| task.ai_channels.add_ai_voltage_chan( | ||
| physical_channel="Dev1/ai0", | ||
| min_val=panel.get_value("voltage_min_value", -5.0), | ||
| max_val=panel.get_value("voltage_max_value", 5.0), | ||
| terminal_config=panel.get_value( | ||
| "terminal_configuration", TerminalConfiguration.DEFAULT | ||
| ), | ||
| ) | ||
| task.ai_channels.add_ai_thrmcpl_chan( | ||
| "Dev1/ai1", | ||
| min_val=panel.get_value("thermocouple_min_value", 0.0), | ||
| max_val=panel.get_value("thermocouple_max_value", 100.0), | ||
| units=panel.get_value("thermocouple_units", TemperatureUnits.DEG_C), | ||
| thermocouple_type=panel.get_value("thermocouple_type", ThermocoupleType.K), | ||
| cjc_source=panel.get_value( | ||
| "thermocouple_cjc_source", CJCSource.CONSTANT_USER_VALUE | ||
| ), | ||
| cjc_val=panel.get_value("thermocouple_cjc_val", 25.0), | ||
| ) | ||
| task.timing.cfg_samp_clk_timing( | ||
| rate=panel.get_value("sample_rate_input", 1000.0), | ||
| sample_mode=AcquisitionType.CONTINUOUS, | ||
| samps_per_chan=panel.get_value("samples_per_channel", 3000), | ||
| ) | ||
| panel.set_value("voltage_data", data[0]) | ||
| panel.set_value("thermocouple_data", data[1]) | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| task.stop() | ||
| task.in_stream.configure_logging( | ||
| file_path=panel.get_value("tdms_file_path", "data.tdms"), | ||
| logging_mode=panel.get_value("logging_mode", LoggingMode.OFF), | ||
| operation=LoggingOperation.OPEN_OR_CREATE, | ||
| ) | ||
| panel.set_value("sample_rate", task._timing.samp_clk_rate) | ||
| try: | ||
| print(f"Starting data acquisition...") | ||
| 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=1000 # pyright: ignore[reportArgumentType] | ||
| ) | ||
| panel.set_value("voltage_data", data[0]) | ||
| panel.set_value("thermocouple_data", data[1]) | ||
| except KeyboardInterrupt: | ||
| raise | ||
| finally: | ||
| print(f"Stopping data acquisition...") | ||
| task.stop() | ||
| panel.set_value("is_running", False) | ||
|
|
||
| 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.