- 
                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 all 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
    
  
  
    
              
  
    
      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,30 @@ | ||
| """Data acquisition script that continuously acquires analog input data.""" | ||
| 
     | 
||
| from pathlib import Path | ||
| 
     | 
||
| import nidaqmx | ||
| from nidaqmx.constants import AcquisitionType | ||
| 
     | 
||
| import nipanel | ||
| 
     | 
||
| panel_script_path = Path(__file__).with_name("nidaqmx_continuous_analog_input_panel.py") | ||
| panel = nipanel.create_panel(panel_script_path) | ||
| 
     | 
||
| 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"\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() | 
        
          
  
    
      
          
            101 changes: 101 additions & 0 deletions
          
          101 
        
  examples/nidaqmx/nidaqmx_continuous_analog_input_panel.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,101 @@ | ||
| """Streamlit visualization script to display data acquired by nidaqmx_continuous_analog_input.py.""" | ||
| 
     | 
||
| import streamlit as st | ||
| from streamlit_echarts import st_echarts | ||
| 
     | 
||
| import nipanel | ||
| 
     | 
||
| panel = nipanel.get_panel_accessor() | ||
| 
     | 
||
| 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, | ||
| ) | ||
| 
     | 
||
| thermocouple_data = panel.get_value("thermocouple_data", [0.0]) | ||
| voltage_data = panel.get_value("voltage_data", [0.0]) | ||
| 
     | 
||
| sample_rate = panel.get_value("sample_rate", 0) | ||
| 
     | 
||
| st.header("Voltage & Thermocouple") | ||
| voltage_therm_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["Voltage (V)", "Temperature (C)"]}, | ||
| "xAxis": { | ||
| "type": "category", | ||
| "data": [x / sample_rate for x in range(len(voltage_data))], | ||
| "name": "Time", | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| "nameLocation": "center", | ||
| "nameGap": 40, | ||
| }, | ||
| "yAxis": { | ||
| "type": "value", | ||
| "name": "Measurement", | ||
| "nameRotate": 90, | ||
| "nameLocation": "center", | ||
| "nameGap": 40, | ||
| }, | ||
| "series": [ | ||
| { | ||
| "name": "voltage_amplitude", | ||
| "type": "line", | ||
| "data": voltage_data, | ||
| "emphasis": {"focus": "series"}, | ||
| "smooth": True, | ||
| "seriesLayoutBy": "row", | ||
| }, | ||
| { | ||
| "name": "thermocouple_amplitude", | ||
| "type": "line", | ||
| "data": thermocouple_data, | ||
| "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) | ||
  
    
      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
    
  
  
    
              Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      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
    
  
  
    
              
  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.