Skip to content

Commit 281e49b

Browse files
author
Dilmi Wickramanayake
committed
Merge branch 'users/DilmiWickramanayake/Analog_Input' of https://github.com/ni/nipanel-python into users/DilmiWickramanayake/Analog_Input
2 parents 3fa3dd7 + 2898155 commit 281e49b

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

examples/nidaqmx/nidaqmx_continuous_analog_input.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
"""Data acquisition script that continuously acquires analog input data."""
22

3-
import pathlib
3+
from pathlib import Path
44

55
import nidaqmx
66
from nidaqmx.constants import AcquisitionType
77

88
import nipanel
99

10-
script_path = pathlib.Path(__file__)
11-
panel_script_path = str(script_path.with_name("nidaqmx_continuous_analog_input_panel.py"))
12-
13-
panel = nipanel.StreamlitPanel(
14-
panel_id="nidaqmx_continuous_analog_input_panel",
15-
streamlit_script_path=panel_script_path,
16-
)
17-
print(f"Panel URL: {panel.panel_url}")
10+
panel_script_path = Path(__file__).with_name("nidaqmx_continuous_analog_input_panel.py")
11+
panel = nipanel.create_panel(panel_script_path)
1812

1913
with nidaqmx.Task() as task:
2014
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
2115
task.ai_channels.add_ai_thrmcpl_chan("Dev1/ai1")
2216
task.timing.cfg_samp_clk_timing(
2317
rate=1000.0, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=3000
2418
)
19+
panel.set_value("sample_rate", task._timing.samp_clk_rate)
2520
task.start()
2621
try:
2722
print(f"\nPress Ctrl + C to stop")

examples/nidaqmx/nidaqmx_continuous_analog_input_panel.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
"""Streamlit visualization script that displays the data acquired by nidaqmx_continuous_analog_input.py"""
1+
"""Streamlit visualization script that displays the data acquired by nidaqmx_continuous_analog_input.py."""
22

33
import streamlit as st
44
from streamlit_echarts import st_echarts
55

66
import nipanel
77

8-
panel = nipanel.initialize_panel()
8+
panel = nipanel.get_panel_accessor()
99

1010
st.title("Analog Input - Voltage and Thermocouple in a Single Task")
1111
voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"])
@@ -24,19 +24,25 @@
2424
thermocouple_data = panel.get_value("thermocouple_data", [0.0])
2525
voltage_data = panel.get_value("voltage_data", [0.0])
2626

27+
sample_rate = panel.get_value("sample_rate")
2728
st.header("Voltage & Thermocouple")
2829
voltage_therm_graph = {
2930
"tooltip": {"trigger": "axis"},
3031
"legend": {"data": ["Voltage (V)", "Temperature (C)"]},
3132
"xAxis": {
3233
"type": "category",
33-
"data": list(range(len(voltage_data))),
34+
"data": [x / sample_rate for x in range(len(voltage_data))],
3435
"name": "Time",
3536
"nameLocation": "center",
36-
"nameGap": 40
37+
"nameGap": 40,
38+
},
39+
"yAxis": {
40+
"type": "value",
41+
"name": "Measurement",
42+
"nameRotate": 90,
43+
"nameLocation": "center",
44+
"nameGap": 40,
3745
},
38-
"yAxis": {"type": "value", "name": "Measurement", "nameRotate": 90,"nameLocation": "center", "nameGap": 40},
39-
4046
"series": [
4147
{
4248
"name": "voltage_amplitude",

0 commit comments

Comments
 (0)