-
Notifications
You must be signed in to change notification settings - Fork 0
Add Analog Input Example #85
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 41 commits into
main
from
users/DilmiWickramanayake/Analog_Input
Jun 25, 2025
Merged
Changes from 16 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
b7abc39
Analog Input - Voltage and Thermocouple Single Task
65e0005
Analog input graph
f2c476a
Analog input graph
aa6488a
Merge branch 'main' of https://github.com/ni/nipanel-python
6d2ec85
Merge branch 'main' of https://github.com/ni/nipanel-python
1bfa9ad
merge main
0460d77
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input
797a8b5
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input
ce8590c
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
4c78816
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
c25f298
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
dd28651
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
59bff05
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
75bd664
Update nidaqmx_continuous_analog_input.py
DilmiWickramanayake 37cf999
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
2898155
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
3fa3dd7
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
281e49b
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
5a6652c
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
4ed087a
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
89d9c2e
Merge branch 'main' of https://github.com/ni/nipanel-python
56c0749
Merge branch 'main' into users/DilmiWickramanayake/Analog_Input
b7c2c91
Analog Input - Voltage and Thermocouple
4583c7a
Fixing formatting issues
acc447f
add daqmx and streamlit_echarts to mypy override
hellovolcano 0d7a6c2
add daqmx and streamlit_echarts to mypy override
hellovolcano 8b3393a
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
d439066
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
ceba012
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
a9c22e7
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
92e7076
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
df977f0
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
f62f13d
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
173e66a
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
d47149f
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
5e0ee0a
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
fd3906d
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
11b3c97
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
cacd19a
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
92b39fe
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
d8ddecd
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://gith…
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,20 @@ | ||
| Prerequisites | ||
| =============== | ||
| Requires a Physical or Simulated Device : https://github.com/ni/nidaqmx-python/blob/master/README.rst (Getting Started Section) | ||
|
|
||
| ## Sample | ||
|
|
||
| This is a nipanel example that displays an interactive Streamlit app and updates continuous analog input examples. | ||
|
|
||
| ### Feature | ||
|
|
||
| - Supports various data types | ||
|
|
||
| ### Required Software | ||
|
|
||
| - Python 3.9 or later | ||
|
|
||
| ### Usage | ||
|
|
||
| Run `poetry run examples/nidaqmx_continuous_analog_input/nidaqmx_continuous_analog_input.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,35 @@ | ||
| """Streamlit application script for displaying values using nipanel package.""" | ||
|
|
||
| import pathlib | ||
|
|
||
| import nidaqmx | ||
| from nidaqmx.constants import AcquisitionType | ||
|
|
||
| import nipanel | ||
|
|
||
| script_path = pathlib.Path(__file__) | ||
| panel_script_path = str(script_path.with_name("nidaqmx_continuous_analog_input_panel.py")) | ||
|
|
||
| panel = nipanel.StreamlitPanel( | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| panel_id="nidaqmx_continuous_analog_input_panel", | ||
| streamlit_script_path=panel_script_path, | ||
| ) | ||
| print(f"Panel URL: {panel.panel_url}") | ||
|
|
||
| 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 | ||
| ) | ||
| task.start() | ||
| try: | ||
| print(f"\nPress Ctrl + C to stop") | ||
| while True: | ||
| data = task.read(number_of_samples_per_channel=1000) | ||
| panel.set_value("voltage_data", data[0]) | ||
| panel.set_value("thermocouple_data", data[1]) | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| task.stop() | ||
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,91 @@ | ||
| """Streamlit script for displaying values from nidaqmx_continuous_analog_input.py.""" | ||
|
|
||
| import streamlit as st | ||
| from streamlit_echarts import st_echarts | ||
jfriedri-ni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import nipanel | ||
|
|
||
| panel = nipanel.initialize_panel() | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| st.title("Analog Input - Voltage and Thermocouple in a Single Task") | ||
| voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"]) | ||
|
|
||
| st.markdown( | ||
| """ | ||
| <style> | ||
| div[data-baseweb="select"] { | ||
| width: 190px !important; /* Adjust the width as needed */ | ||
| } | ||
| </style> | ||
| """, | ||
| unsafe_allow_html=True, | ||
| ) | ||
|
|
||
| list_of_therm_amp = panel.get_value("thermocouple_data", [0.0]) | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| list_of_voltage_amp = panel.get_value("voltage_data", [0.0]) | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| st.header("Voltage & Thermocouple") | ||
| voltage_therm_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["voltage_amplitude", "thermocouple_amplitude"]}, | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "xAxis": { | ||
| "type": "category", | ||
| "data": list(range(len(list_of_voltage_amp))), | ||
| "name": "Time", | ||
DilmiWickramanayake marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| "yAxis": {"type": "value", "name": "Voltage and Thermocouple Amplitude"}, | ||
DilmiWickramanayake marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "series": [ | ||
| { | ||
| "name": "voltage_amplitude", | ||
| "type": "line", | ||
| "data": list_of_voltage_amp, | ||
| "emphasis": {"focus": "series"}, | ||
| "smooth": True, | ||
| "seriesLayoutBy": "row", | ||
| }, | ||
| { | ||
| "name": "thermocouple_amplitude", | ||
| "type": "line", | ||
| "data": list_of_therm_amp, | ||
| "color": "red", | ||
| "emphasis": {"focus": "series"}, | ||
| "smooth": True, | ||
| "seriesLayoutBy": "row", | ||
| }, | ||
| ], | ||
| } | ||
| st_echarts(options=voltage_therm_graph, height="400px") | ||
|
|
||
| voltage_tab.header("Voltage") | ||
| with voltage_tab: | ||
| left_volt_tab, center_volt_tab, right_volt_tab = st.columns(3) | ||
| with left_volt_tab: | ||
| st.selectbox(options=["Dev1/ai0"], label="Physical Channels", disabled=True) | ||
| st.selectbox(options=["Off"], label="Logging Modes", disabled=False) | ||
| with center_volt_tab: | ||
| st.selectbox(options=["-5"], label="Min Value") | ||
| st.selectbox(options=["5"], label="Max Value") | ||
| st.selectbox(options=["1000"], label="Samples per Loops", disabled=False) | ||
| with right_volt_tab: | ||
| st.selectbox(options=["default"], label="Terminal Configurations") | ||
| st.selectbox(options=["OnboardClock"], label="Sample Clock Sources", disabled=False) | ||
|
|
||
|
|
||
| thermocouple_tab.header("Thermocouple") | ||
| with thermocouple_tab: | ||
| left, middle, right = st.columns(3) | ||
| with left: | ||
| st.selectbox(options=["Dev1/ai1"], label="Physical Channel", disabled=True) | ||
| st.selectbox(options=["0"], label="Min", disabled=False) | ||
| st.selectbox(options=["100"], label="Max", disabled=False) | ||
| st.selectbox(options=["Off"], label="Logging Mode", disabled=False) | ||
|
|
||
| with middle: | ||
| st.selectbox(options=["Deg C"], label="Units", disabled=False) | ||
| st.selectbox(options=["J"], label="Thermocouple Type", disabled=False) | ||
| st.selectbox(options=["Constant Value"], label="CJC Source", disabled=False) | ||
| st.selectbox(options=["1000"], label="Samples per Loop", disabled=False) | ||
| with right: | ||
| st.selectbox(options=["25"], label="CJC Value", disabled=False) | ||
| st.selectbox(options=["OnboardClock"], label="Sample Clock Source", disabled=False) | ||
| st.selectbox(options=[" "], label="Actual Sample Rate", disabled=True) | ||
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.