Skip to content

Commit 65e0005

Browse files
author
Dilmi Wickramanayake
committed
Analog input graph
1 parent b7abc39 commit 65e0005

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
"""This example demonstrates how to open/update a Streamlit application using nipanel package."""
1+
"""This is the logic that will read/set values to panel."""
22

3-
import nipanel
4-
import nidaqmx
53
import pathlib
64
import time
75

6+
import nidaqmx
7+
8+
import nipanel
9+
810
script_path = pathlib.Path(__file__)
911
panel_script_path = str(script_path.with_name("nidaqmx_continuous_analog_input_panel.py"))
1012

@@ -23,16 +25,13 @@
2325
data = task.read(number_of_samples_per_channel=3)
2426
read = len(data)
2527
total_read += read
26-
28+
2729
data_arr.append(data)
2830
time.sleep(1)
29-
panel.set_value("amplitude",data_arr[-1][-1])
30-
panel.set_value("Volts",data_arr[-1][0])
31+
panel.set_value("amplitude", data_arr[-1][-1])
32+
panel.set_value("Volts", data_arr[-1][0])
3133
except KeyboardInterrupt:
32-
pass
34+
pass
3335
finally:
34-
task.stop()
35-
print(f"\nAcquired {total_read} total samples.")
36-
37-
38-
36+
task.stop()
37+
print(f"\nAcquired {total_read} total samples.")
Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
"""Streamlit application script for displaying values using nipanel package."""
2-
import nipanel
1+
"""This is the panel that will use the logic."""
2+
33
import streamlit as st
44
import streamlit.components.v1 as components
55
from streamlit_echarts import st_echarts
66

7+
import nipanel
8+
79
panel = nipanel.StreamlitPanelValueAccessor(panel_id="nidaqmx_continuous_analog_input_panel")
810

911
add_refresh_component = components.declare_component(
10-
"panelRefreshComponent",
11-
url=f"http://localhost:42001/panels/refresh/{panel.panel_id}",)
12+
"panelRefreshComponent",
13+
url=f"http://localhost:42001/panels/refresh/{panel.panel_id}",
14+
)
1215
add_refresh_component()
1316

1417

@@ -23,7 +26,7 @@
2326
}
2427
</style>
2528
""",
26-
unsafe_allow_html=True
29+
unsafe_allow_html=True,
2730
)
2831

2932

@@ -45,22 +48,17 @@
4548
"legend": {"data": ["thermocouple_amplitude"]},
4649
"xAxis": {
4750
"type": "category",
48-
"data":list(range(len(st.session_state.therm_history))),
49-
"name": "Time"
50-
},
51-
"yAxis": {
52-
"type": "value",
53-
"name": "Thermocouple Amplitude"
51+
"data": list(range(len(st.session_state.therm_history))),
52+
"name": "Time",
5453
},
54+
"yAxis": {"type": "value", "name": "Thermocouple Amplitude"},
5555
"series": [
5656
{
5757
"name": "thermocouple_amplitude",
5858
"type": "line",
5959
"data": st.session_state.therm_history,
60-
"color": "red"
60+
"color": "red",
6161
},
62-
63-
6462
],
6563
}
6664
st_echarts(options=therm_amp_graph, height="400px")
@@ -71,19 +69,15 @@
7169
"xAxis": {
7270
"type": "category",
7371
"data": list(range(len(st.session_state.volts_history))),
74-
"name": "Time"
75-
},
76-
"yAxis": {
77-
"type": "value",
78-
"name": "Voltage Amplitude"
72+
"name": "Time",
7973
},
74+
"yAxis": {"type": "value", "name": "Voltage Amplitude"},
8075
"series": [
8176
{
8277
"name": "voltage_amplitude",
8378
"type": "line",
8479
"data": st.session_state.volts_history,
8580
},
86-
8781
],
8882
}
8983
st_echarts(options=voltage_amp_graph, height="400px")
@@ -95,18 +89,15 @@
9589
"xAxis": {
9690
"type": "category",
9791
"data": list(range(len(st.session_state.volts_history))),
98-
"name": "Time"
99-
},
100-
"yAxis": {
101-
"type": "value",
102-
"name": "Voltage and Thermocouple Amplitude"
92+
"name": "Time",
10393
},
94+
"yAxis": {"type": "value", "name": "Voltage and Thermocouple Amplitude"},
10495
"series": [
10596
{
10697
"name": "voltage_amplitude",
10798
"type": "line",
10899
"data": st.session_state.volts_history,
109-
"emphasis": {"focus":"series"},
100+
"emphasis": {"focus": "series"},
110101
"smooth": True,
111102
"seriesLayoutBy": "row",
112103
},
@@ -115,7 +106,7 @@
115106
"type": "line",
116107
"data": st.session_state.therm_history,
117108
"color": "red",
118-
"emphasis": {"focus":"series"},
109+
"emphasis": {"focus": "series"},
119110
"smooth": True,
120111
"seriesLayoutBy": "row",
121112
},
@@ -129,14 +120,14 @@
129120
st.selectbox(options=["Mod1/ai2"], label="Physical Channels", disabled=True)
130121
st.selectbox(options=["Off"], label="Logging Modes", disabled=False)
131122
with center_volt_tab:
132-
st.selectbox(options=["-5"],label="Min Value")
133-
st.selectbox(options=["5"],label="Max Value")
123+
st.selectbox(options=["-5"], label="Min Value")
124+
st.selectbox(options=["5"], label="Max Value")
134125
st.selectbox(options=["1000"], label="Samples per Loops", disabled=False)
135126
with right_volt_tab:
136127
st.selectbox(options=["default"], label="Terminal Configurations")
137128
st.selectbox(options=["OnboardClock"], label="Sample Clock Sources", disabled=False)
138129

139-
130+
140131
thermocouple_tab.header("Thermocouple")
141132
with thermocouple_tab:
142133
left, middle, right = st.columns(3)
@@ -145,24 +136,13 @@
145136
st.selectbox(options=["0"], label="Min", disabled=False)
146137
st.selectbox(options=["100"], label="Max", disabled=False)
147138
st.selectbox(options=["Off"], label="Logging Mode", disabled=False)
148-
139+
149140
with middle:
150-
st.selectbox(options=["Deg C"], label = "Units", disabled=False)
141+
st.selectbox(options=["Deg C"], label="Units", disabled=False)
151142
st.selectbox(options=["J"], label="Thermocouple Type", disabled=False)
152143
st.selectbox(options=["Constant Value"], label="CJC Source", disabled=False)
153144
st.selectbox(options=["1000"], label="Samples per Loop", disabled=False)
154145
with right:
155-
st.selectbox(options=["25"],label="CJC Value", disabled=False)
146+
st.selectbox(options=["25"], label="CJC Value", disabled=False)
156147
st.selectbox(options=["OnboardClock"], label="Sample Clock Source", disabled=False)
157148
st.selectbox(options=[" "], label="Actual Sample Rate", disabled=True)
158-
159-
160-
161-
162-
163-
164-
165-
166-
167-
168-

0 commit comments

Comments
 (0)