- 
                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 7 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
                              
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            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,16 @@ | ||
| Prerequisites | ||
| =============== | ||
| In order to use the **nidaqmx** package, you must have at least one DAQ | ||
| device installed on your system. Both physical and simulated devices are supported. The | ||
| examples below use an X Series DAQ device of PCIe-6320 You can use **NI MAX** or **NI Hardware Configuration Utility** to | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| verify and configure your devices. | ||
| 
     | 
||
| Finding and configuring device name in **NI MAX**: | ||
| 
     | 
||
|  | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| Finding and configuring device name in NI Hardware Configuration Utility: | ||
| 
     | 
||
|  | ||
| 
     | 
||
| Snippet is from: https://github.com/ni/nidaqmx-python/blob/master/README.rst Getting Started Section | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
        
          
          
            38 changes: 38 additions & 0 deletions
          
          38 
        
  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,38 @@ | ||
| """Streamlit application script for displaying values from nidaqmx_continuous_analog_input.py""" | ||
| 
     | 
||
| 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( | ||
| panel_id="nidaqmx_continuous_analog_input_panel", | ||
| streamlit_script_path=panel_script_path, | ||
| 
     | 
||
| ) | ||
| 
     | 
||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 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: | ||
| total_read = 0 | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| while True: | ||
| print(f"\nPress Ctrl + C to stop") | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 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: | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| pass | ||
| finally: | ||
| task.stop() | ||
        
          
          
            90 changes: 90 additions & 0 deletions
          
          90 
        
  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,90 @@ | ||
| """Streamlit application script for displaying values using nipanel package.""" | ||
| 
     | 
||
| import streamlit as st | ||
| from streamlit_echarts import st_echarts | ||
| 
     | 
||
| import nipanel | ||
| 
     | 
||
| panel = nipanel.initialize_panel() | ||
| 
     | 
||
| 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("thermocouple_data", [0.0]) | ||
| list_of_voltage_amp = panel.get_value("voltage_data", [0.0]) | ||
| 
     | 
||
| st.header("Voltage & Thermocouple") | ||
| voltage_therm_graph = { | ||
| "tooltip": {"trigger": "axis"}, | ||
| "legend": {"data": ["voltage_amplitude", "thermocouple_amplitude"]}, | ||
| "xAxis": { | ||
| "type": "category", | ||
| "data": list(range(len(list_of_voltage_amp))), | ||
| "name": "Time", | ||
| }, | ||
| "yAxis": {"type": "value", "name": "Voltage and Thermocouple Amplitude"}, | ||
| "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") | ||
| 
     | 
||
| 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) | ||
                
      
                  DilmiWickramanayake marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| 
     | 
||
| 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=["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.