- 
                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 3 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
        
          
          
            37 changes: 37 additions & 0 deletions
          
          37 
        
  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,37 @@ | ||
| """This is the logic that will read/set values to panel.""" | ||
| 
     | 
||
| import pathlib | ||
| import time | ||
| 
     | 
||
| import nidaqmx | ||
| 
     | 
||
| import nipanel | ||
| 
     | 
||
| script_path = pathlib.Path(__file__) | ||
| panel_script_path = str(script_path.with_name("nidaqmx_continuous_analog_input_panel.py")) | ||
| 
     | 
||
| panel = nipanel.StreamlitPanel( | ||
| panel_id="nidaqmx_continuous_analog_input_panel", | ||
| streamlit_script_path=panel_script_path, | ||
| ) | ||
| 
     | 
||
| data_arr = [] | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| with nidaqmx.Task() as task: | ||
| task.ai_channels.add_ai_voltage_chan("Mod1/ai2") | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| task.ai_channels.add_ai_thrmcpl_chan("Mod1/ai3") | ||
| try: | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| total_read = 0 | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| while True: | ||
| data = task.read(number_of_samples_per_channel=3) | ||
| read = len(data) | ||
| total_read += read | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| data_arr.append(data) | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| time.sleep(1) | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| panel.set_value("amplitude", data_arr[-1][-1]) | ||
| panel.set_value("Volts", data_arr[-1][0]) | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| except KeyboardInterrupt: | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| pass | ||
| finally: | ||
| task.stop() | ||
| print(f"\nAcquired {total_read} total samples.") | ||
        
          
          
            148 changes: 148 additions & 0 deletions
          
          148 
        
  examples/nidaqmx_continuous_analog_input/nidaqmx_continuous_analog_input_panel.py
  
  
      
      
   
        
      
      
    
                              
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
            
  
    
      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,148 @@ | ||
| """This is the panel that will use the logic.""" | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| import streamlit as st | ||
| import streamlit.components.v1 as components | ||
| from streamlit_echarts import st_echarts | ||
| 
     | 
||
| import nipanel | ||
| 
     | 
||
| panel = nipanel.StreamlitPanelValueAccessor(panel_id="nidaqmx_continuous_analog_input_panel") | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| add_refresh_component = components.declare_component( | ||
| "panelRefreshComponent", | ||
| url=f"http://localhost:42001/panels/refresh/{panel.panel_id}", | ||
| ) | ||
| add_refresh_component() | ||
| 
     | 
||
| 
     | 
||
| st.title("Analog Input - Voltage and Thermocouple in a Single Task") | ||
| voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"]) | ||
| 
     | 
||
| st.markdown( | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| """ | ||
| <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("amplitude") | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| list_of_voltage_amp = panel.get_value("Volts") | ||
| 
     | 
||
| if "therm_history" not in st.session_state: | ||
| st.session_state.therm_history = [] | ||
| if "volts_history" not in st.session_state: | ||
| st.session_state.volts_history = [] | ||
| 
     | 
||
| for therm_amp in list_of_therm_amp: | ||
| st.session_state.therm_history.append(therm_amp) | ||
| for voltage_amp in list_of_voltage_amp: | ||
| st.session_state.volts_history.append(voltage_amp) | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| therm_amp_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["thermocouple_amplitude"]}, | ||
| "xAxis": { | ||
| "type": "category", | ||
| "data": list(range(len(st.session_state.therm_history))), | ||
| "name": "Time", | ||
| }, | ||
| "yAxis": {"type": "value", "name": "Thermocouple Amplitude"}, | ||
| "series": [ | ||
| { | ||
| "name": "thermocouple_amplitude", | ||
| "type": "line", | ||
| "data": st.session_state.therm_history, | ||
| "color": "red", | ||
| }, | ||
| ], | ||
| } | ||
| st_echarts(options=therm_amp_graph, height="400px") | ||
| 
     | 
||
| voltage_amp_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["voltage_amplitude"]}, | ||
| "xAxis": { | ||
| "type": "category", | ||
| "data": list(range(len(st.session_state.volts_history))), | ||
| "name": "Time", | ||
| }, | ||
| "yAxis": {"type": "value", "name": "Voltage Amplitude"}, | ||
| "series": [ | ||
| { | ||
| "name": "voltage_amplitude", | ||
| "type": "line", | ||
| "data": st.session_state.volts_history, | ||
| }, | ||
| ], | ||
| } | ||
| st_echarts(options=voltage_amp_graph, height="400px") | ||
| 
     | 
||
| st.header("Voltage & Thermocouple") | ||
| voltage_therm_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["voltage_amplitude", "thermocouple_amplitude"]}, | ||
| "xAxis": { | ||
| "type": "category", | ||
| "data": list(range(len(st.session_state.volts_history))), | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| "name": "Time", | ||
| }, | ||
| "yAxis": {"type": "value", "name": "Voltage and Thermocouple Amplitude"}, | ||
| "series": [ | ||
| { | ||
| "name": "voltage_amplitude", | ||
| "type": "line", | ||
| "data": st.session_state.volts_history, | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| "emphasis": {"focus": "series"}, | ||
| "smooth": True, | ||
| "seriesLayoutBy": "row", | ||
| }, | ||
| { | ||
| "name": "thermocouple_amplitude", | ||
| "type": "line", | ||
| "data": st.session_state.therm_history, | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| "color": "red", | ||
| "emphasis": {"focus": "series"}, | ||
| "smooth": True, | ||
| "seriesLayoutBy": "row", | ||
| }, | ||
| ], | ||
| } | ||
| st_echarts(options=voltage_therm_graph, height="400px") | ||
| 
     | 
||
| with voltage_tab: | ||
| left_volt_tab, center_volt_tab, right_volt_tab = st.columns(3) | ||
| with left_volt_tab: | ||
| st.selectbox(options=["Mod1/ai2"], 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") | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| with thermocouple_tab: | ||
| left, middle, right = st.columns(3) | ||
| with left: | ||
| st.selectbox(options=["Mod1/ai3"], 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.
        
    
  
  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.