Skip to content

Commit 80970c4

Browse files
author
Dilmi Wickramanayake
committed
removed function and simplified code
1 parent 282c530 commit 80970c4

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
"""Streamlit visualization script to display data acquired by nidaqmx_analog_output_voltage.py."""
2+
3+
import extra_streamlit_components as stx # type: ignore[import-untyped]
4+
import streamlit as st
5+
from nidaqmx.constants import Edge
6+
from streamlit_echarts import st_echarts
7+
8+
import nipanel
9+
from nipanel.controls import enum_selectbox
10+
11+
st.set_page_config(page_title="Voltage - Continuous Output", page_icon="📈", layout="wide")
12+
st.title("Voltage - Continuous Output")
13+
panel = nipanel.get_streamlit_panel_accessor()
14+
15+
left_col, right_col = st.columns(2)
16+
17+
st.markdown(
18+
"""
19+
<style>
20+
div.stNumberInput {
21+
max-width: 190px !important;
22+
}
23+
div.stTextInput {
24+
max-width: 190px !important;
25+
}
26+
27+
div[data-baseweb="select"] {
28+
width: 190px !important; /* Adjust the width as needed */
29+
}
30+
</style>
31+
<style>
32+
iframe[title="streamlit_echarts.st_echarts"]{ height: 400px; width:100%;}
33+
</style>
34+
""",
35+
unsafe_allow_html=True,
36+
)
37+
38+
39+
with left_col:
40+
with st.container(border=True):
41+
if panel.get_value("is_running", True):
42+
st.button("Stop", key="stop_button")
43+
elif not panel.get_value("is_running", True) and panel.get_value("daq_error", "") == "":
44+
run_button = st.button("Run", key="run_button")
45+
else:
46+
st.markdown(
47+
"""
48+
<style>
49+
button[data-testid="stBaseButton-secondary"] {
50+
display: none;
51+
}
52+
</style>
53+
""",
54+
unsafe_allow_html=True,
55+
)
56+
st.error(
57+
f"There was an error running the script. Fix the issue and re-run nidaqmx_analog_input_filtering.py \n\n {panel.get_value('daq_error', '')}"
58+
)
59+
60+
st.title("Channel Settings")
61+
physical_channel = st.selectbox(
62+
options=panel.get_value("available_channel_names", ["Mod2/ai0"]),
63+
index=0,
64+
label="Physical Channels",
65+
disabled=panel.get_value("is_running", False),
66+
)
67+
panel.set_value("physical_channel", physical_channel)
68+
69+
max_value_voltage = st.number_input(
70+
"Max Value",
71+
value=5.0,
72+
step=1.0,
73+
disabled=panel.get_value("is_running", False),
74+
key="max_value_voltage",
75+
)
76+
77+
min_value_voltage = st.number_input(
78+
"Min Value",
79+
value=-5.0,
80+
step=1.0,
81+
disabled=panel.get_value("is_running", False),
82+
key="min_value_voltage",
83+
)
84+
st.title("Timing and Buffer Settings")
85+
86+
source = st.selectbox(
87+
"Sample Clock Source",
88+
options=panel.get_value("available_trigger_sources", [""]),
89+
index=0,
90+
disabled=panel.get_value("is_running", False),
91+
)
92+
panel.set_value("source", source)
93+
st.number_input(
94+
"Sample Rate",
95+
value=1000.0,
96+
min_value=1.0,
97+
step=1.0,
98+
disabled=panel.get_value("is_running", False),
99+
key="rate",
100+
)
101+
st.number_input(
102+
"Number of Samples",
103+
value=1000,
104+
min_value=1,
105+
step=1,
106+
disabled=panel.get_value("is_running", False),
107+
key="total_samples",
108+
)
109+
st.number_input(
110+
"Actual Sample Rate",
111+
value=panel.get_value("actual_sample_rate", 1000.0),
112+
key="actual_sample_rate",
113+
step=1.0,
114+
disabled=True,
115+
)
116+
st.title("Waveform Settings")
117+
st.number_input(
118+
"Frequency",
119+
value=panel.get_value("frequency", 10.0),
120+
key="frequency",
121+
step=1.0,
122+
disabled=panel.get_value("is_running", False),
123+
)
124+
st.number_input(
125+
"Amplitude",
126+
value=panel.get_value("amplitude", 1.0),
127+
key="amplitude",
128+
step=1.0,
129+
disabled=panel.get_value("is_running", False),
130+
)
131+
st.selectbox(
132+
label="Wave Type",
133+
options=["Sine Wave", "Triangle Wave", "Square Wave"],
134+
key="wave_type",
135+
disabled=panel.get_value("is_running", False),
136+
)
137+
138+
with right_col:
139+
with st.container(border=True):
140+
st.title("Trigger Settings")
141+
trigger_type = stx.tab_bar(
142+
data=[
143+
stx.TabBarItemData(id=1, title="No Trigger", description=""),
144+
stx.TabBarItemData(id=2, title="Digital Start", description=""),
145+
stx.TabBarItemData(id=3, title="Digital Pause", description=""),
146+
stx.TabBarItemData(id=4, title="Digital Reference", description=""),
147+
stx.TabBarItemData(id=5, title="Analog Start", description=""),
148+
stx.TabBarItemData(id=6, title="Analog Pause", description=""),
149+
stx.TabBarItemData(id=7, title="Analog Reference", description=""),
150+
],
151+
default=1,
152+
)
153+
panel.set_value("trigger_type", trigger_type)
154+
155+
if trigger_type == "2":
156+
with st.container(border=True):
157+
source = st.selectbox(
158+
"Source:", options=panel.get_value("available_trigger_sources", [""])
159+
)
160+
panel.set_value("digital_source", source)
161+
enum_selectbox(
162+
panel,
163+
label="Edge",
164+
value=Edge.FALLING,
165+
disabled=panel.get_value("is_running", False),
166+
key="edge",
167+
)
168+
else:
169+
with st.container(border=True):
170+
st.write(
171+
"This trigger type is not supported in continuous sample timing. Refer to your device documentation for more information on which triggers are supported."
172+
)
173+
174+
with st.container(border=True):
175+
acquired_data = panel.get_value("data", [0.0])
176+
sample_rate = panel.get_value("sample_rate", 1000.0)
177+
acquired_data_graph = {
178+
"animation": False,
179+
"tooltip": {"trigger": "axis"},
180+
"legend": {"data": ["Voltage (V)"]},
181+
"xAxis": {
182+
"type": "category",
183+
"data": [x / sample_rate for x in range(len(acquired_data))],
184+
"name": "Time",
185+
"nameLocation": "center",
186+
"nameGap": 40,
187+
},
188+
"yAxis": {
189+
"type": "value",
190+
"name": "Amplitude",
191+
"nameRotate": 90,
192+
"nameLocation": "center",
193+
"nameGap": 40,
194+
},
195+
"series": [
196+
{
197+
"name": "voltage_amplitude",
198+
"type": "line",
199+
"data": acquired_data,
200+
"emphasis": {"focus": "series"},
201+
"smooth": True,
202+
"seriesLayoutBy": "row",
203+
},
204+
],
205+
}
206+
st_echarts(options=acquired_data_graph, height="400px", key="graph", width="100%")

0 commit comments

Comments
 (0)