Skip to content

Commit 803b5a0

Browse files
committed
Merge remote-tracking branch 'origin/main' into users/jdixon/reuse-analyze-project-action
2 parents 3c69c1b + 2e45f1b commit 803b5a0

File tree

12 files changed

+763
-647
lines changed

12 files changed

+763
-647
lines changed

.github/workflows/check_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
- name: Check out repo
1313
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1414
- name: Set up Python
15-
uses: ni/python-actions/setup-python@c944450739cc16d6df3138d2b57d42427c532235
15+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
1616
id: setup-python
1717
- name: Set up Poetry
18-
uses: ni/python-actions/setup-poetry@c944450739cc16d6df3138d2b57d42427c532235
18+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
1919
- name: Check for lock changes
2020
run: poetry check --lock
2121
- name: Cache virtualenv (with docs)

.github/workflows/check_nipanel.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ jobs:
1616
- name: Check out repo
1717
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1818
- name: Set up Python
19-
uses: ni/python-actions/setup-python@c944450739cc16d6df3138d2b57d42427c532235
19+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
20+
id: setup-python
2021
with:
2122
python-version: ${{ matrix.python-version }}
2223
- name: Set up Poetry
23-
uses: ni/python-actions/setup-poetry@c944450739cc16d6df3138d2b57d42427c532235
24+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
2425
- name: Analyze Python Project
25-
uses: ni/python-actions/analyze-project@c944450739cc16d6df3138d2b57d42427c532235
26+
uses: ni/python-actions/analyze-project@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
2627
with:
2728
install-args: "--with examples,docs"
2829
- name: Bandit security checks
29-
run: poetry run bandit -c pyproject.toml -r src/nipanel
30+
run: poetry run bandit -c pyproject.toml -r src/nipanel

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ jobs:
4545
- name: Check out repo
4646
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4747
- name: Set up Python
48-
uses: ni/python-actions/setup-python@c944450739cc16d6df3138d2b57d42427c532235
48+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
4949
- name: Set up Poetry
50-
uses: ni/python-actions/setup-poetry@c944450739cc16d6df3138d2b57d42427c532235
50+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
5151
- name: Check project version
5252
if: github.event_name == 'release'
53-
uses: ni/python-actions/check-project-version@c944450739cc16d6df3138d2b57d42427c532235
53+
uses: ni/python-actions/check-project-version@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
5454
- name: Build distribution packages
5555
run: poetry build
5656
- name: Upload build artifacts
@@ -91,8 +91,8 @@ jobs:
9191
- name: Check out repo
9292
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9393
- name: Set up Python
94-
uses: ni/python-actions/setup-python@c944450739cc16d6df3138d2b57d42427c532235
94+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
9595
- name: Set up Poetry
96-
uses: ni/python-actions/setup-poetry@c944450739cc16d6df3138d2b57d42427c532235
96+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
9797
- name: Update project version
98-
uses: ni/python-actions/update-project-version@c944450739cc16d6df3138d2b57d42427c532235
98+
uses: ni/python-actions/update-project-version@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0

.github/workflows/run_unit_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
- name: Check out repo
2020
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2121
- name: Set up Python
22-
uses: ni/python-actions/setup-python@c944450739cc16d6df3138d2b57d42427c532235
22+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
2323
id: setup-python
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626
- name: Set up Poetry
27-
uses: ni/python-actions/setup-poetry@c944450739cc16d6df3138d2b57d42427c532235
27+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # 0.7.0
2828
- name: Cache virtualenv
2929
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
3030
with:
@@ -39,4 +39,4 @@ jobs:
3939
with:
4040
name: test_results_unit_${{ matrix.os }}_py${{ matrix.python-version }}
4141
path: ./test_results/*.xml
42-
if: always()
42+
if: always()
Lines changed: 114 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Data acquisition script that continuously acquires analog input data."""
22

3+
import os
34
import time
45
from pathlib import Path
56

6-
import nidaqmx
7-
import nidaqmx.system
8-
from nidaqmx.constants import (
7+
os.environ["NIDAQMX_ENABLE_WAVEFORM_SUPPORT"] = "1"
8+
import nidaqmx # noqa: E402 # Must import after setting os environment variable
9+
import nidaqmx.system # noqa: E402
10+
from nidaqmx.constants import ( # noqa: E402
911
AcquisitionType,
1012
CurrentShuntResistorLocation,
1113
CurrentUnits,
@@ -15,10 +17,11 @@
1517
Slope,
1618
StrainGageBridgeType,
1719
TerminalConfiguration,
20+
UsageTypeAI,
1821
)
19-
from nidaqmx.errors import DaqError
22+
from nidaqmx.errors import DaqError # noqa: E402
2023

21-
import nipanel
24+
import nipanel # noqa: E402
2225

2326
panel_script_path = Path(__file__).with_name("nidaqmx_analog_input_filtering_panel.py")
2427
panel = nipanel.create_streamlit_panel(panel_script_path)
@@ -29,7 +32,8 @@
2932
available_channel_names = []
3033
for dev in system.devices:
3134
for chan in dev.ai_physical_chans:
32-
available_channel_names.append(chan.name)
35+
if UsageTypeAI.VOLTAGE in chan.ai_meas_types:
36+
available_channel_names.append(chan.name)
3337
panel.set_value("available_channel_names", available_channel_names)
3438

3539
available_trigger_sources = [""]
@@ -38,117 +42,121 @@
3842
for term in dev.terminals:
3943
available_trigger_sources.append(term)
4044
panel.set_value("available_trigger_sources", available_trigger_sources)
45+
4146
try:
42-
panel.set_value("daq_error", "")
4347
print(f"Panel URL: {panel.panel_url}")
4448
print(f"Waiting for the 'Run' button to be pressed...")
4549
print(f"(Press Ctrl + C to quit)")
4650
while True:
47-
panel.set_value("run_button", False)
48-
while not panel.get_value("run_button", False):
51+
while not panel.get_value("is_running", False):
4952
time.sleep(0.1)
50-
# How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/
51-
with nidaqmx.Task() as task:
52-
53-
chan_type = panel.get_value("chan_type", "1")
54-
55-
if chan_type == "2":
56-
chan = task.ai_channels.add_ai_current_chan(
57-
panel.get_value("physical_channel", ""),
58-
max_val=panel.get_value("max_value_current", 0.01),
59-
min_val=panel.get_value("min_value_current", -0.01),
60-
ext_shunt_resistor_val=panel.get_value("shunt_resistor_value", 249.0),
61-
shunt_resistor_loc=panel.get_value(
62-
"shunt_location", CurrentShuntResistorLocation.EXTERNAL
63-
),
64-
units=panel.get_value("units", CurrentUnits.AMPS),
65-
)
6653

67-
elif chan_type == "3":
68-
chan = task.ai_channels.add_ai_strain_gage_chan(
69-
panel.get_value("physical_channel", ""),
70-
nominal_gage_resistance=panel.get_value("gage_resistance", 350.0),
71-
voltage_excit_source=ExcitationSource.EXTERNAL, # Only mode that works
72-
max_val=panel.get_value("max_value_strain", 0.001),
73-
min_val=panel.get_value("min_value_strain", -0.001),
74-
poisson_ratio=panel.get_value("poisson_ratio", 0.3),
75-
lead_wire_resistance=panel.get_value("wire_resistance", 0.0),
76-
initial_bridge_voltage=panel.get_value("initial_voltage", 0.0),
77-
gage_factor=panel.get_value("gage_factor", 2.0),
78-
voltage_excit_val=panel.get_value("voltage_excitation_value", 0.0),
79-
strain_config=panel.get_value(
80-
"strain_configuration", StrainGageBridgeType.FULL_BRIDGE_I
81-
),
82-
)
83-
else:
84-
chan = task.ai_channels.add_ai_voltage_chan(
85-
panel.get_value("physical_channel", ""),
86-
terminal_config=panel.get_value(
87-
"terminal_configuration", TerminalConfiguration.DEFAULT
88-
),
89-
max_val=panel.get_value("max_value_voltage", 5.0),
90-
min_val=panel.get_value("min_value_voltage", -5.0),
91-
)
92-
task.timing.cfg_samp_clk_timing(
93-
source=panel.get_value("source", ""), # "" - means Onboard Clock (default value)
94-
rate=panel.get_value("rate", 1000.0),
95-
sample_mode=AcquisitionType.CONTINUOUS,
96-
samps_per_chan=panel.get_value("total_samples", 100),
97-
)
98-
panel.set_value("sample_rate", task.timing.samp_clk_rate)
99-
# Not all hardware supports all filter types.
100-
# Refer to your device documentation for more information.
101-
if panel.get_value("filter", "Filter") == "Filter":
102-
chan.ai_filter_enable = True
103-
chan.ai_filter_freq = panel.get_value("filter_freq", 0.0)
104-
chan.ai_filter_response = panel.get_value("filter_response", FilterResponse.COMB)
105-
chan.ai_filter_order = panel.get_value("filter_order", 1)
106-
panel.set_value("actual_filter_freq", chan.ai_filter_freq)
107-
panel.set_value("actual_filter_response", chan.ai_filter_response)
108-
panel.set_value("actual_filter_order", chan.ai_filter_order)
109-
else:
110-
panel.set_value("actual_filter_freq", 0.0)
111-
panel.set_value("actual_filter_response", FilterResponse.COMB)
112-
panel.set_value("actual_filter_order", 0)
113-
# Not all hardware supports all filter types.
114-
# Refer to your device documentation for more information.
115-
trigger_type = panel.get_value("trigger_type")
116-
if trigger_type == "5":
117-
task.triggers.start_trigger.cfg_anlg_edge_start_trig(
118-
trigger_source=panel.get_value("analog_source", ""),
119-
trigger_slope=panel.get_value("slope", Slope.FALLING),
120-
trigger_level=panel.get_value("level", 0.0),
121-
)
54+
print(f"Running...")
55+
try:
56+
# How to use nidaqmx: https://nidaqmx-python.readthedocs.io/en/stable/
57+
panel.set_value("daq_error", "")
58+
with nidaqmx.Task() as task:
12259

123-
if trigger_type == "2":
124-
task.triggers.start_trigger.cfg_dig_edge_start_trig(
125-
trigger_source=panel.get_value("digital_source", ""),
126-
trigger_edge=panel.get_value("edge", Edge.FALLING),
127-
)
128-
task.triggers.start_trigger.anlg_edge_hyst = hysteresis = panel.get_value(
129-
"hysteresis", 0.0
130-
)
60+
chan_type = panel.get_value("chan_type", "1")
13161

132-
try:
133-
task.start()
134-
panel.set_value("is_running", True)
62+
if chan_type == "2":
63+
chan = task.ai_channels.add_ai_current_chan(
64+
panel.get_value("physical_channel", ""),
65+
max_val=panel.get_value("max_value_current", 0.01),
66+
min_val=panel.get_value("min_value_current", -0.01),
67+
ext_shunt_resistor_val=panel.get_value("shunt_resistor_value", 249.0),
68+
shunt_resistor_loc=panel.get_value(
69+
"shunt_location", CurrentShuntResistorLocation.EXTERNAL
70+
),
71+
units=panel.get_value("units", CurrentUnits.AMPS),
72+
)
13573

136-
panel.set_value("stop_button", False)
137-
while not panel.get_value("stop_button", False):
138-
data = task.read(
139-
number_of_samples_per_channel=100 # pyright: ignore[reportArgumentType]
74+
elif chan_type == "3":
75+
chan = task.ai_channels.add_ai_strain_gage_chan(
76+
panel.get_value("physical_channel", ""),
77+
nominal_gage_resistance=panel.get_value("gage_resistance", 350.0),
78+
voltage_excit_source=ExcitationSource.EXTERNAL, # Only mode that works
79+
max_val=panel.get_value("max_value_strain", 0.001),
80+
min_val=panel.get_value("min_value_strain", -0.001),
81+
poisson_ratio=panel.get_value("poisson_ratio", 0.3),
82+
lead_wire_resistance=panel.get_value("wire_resistance", 0.0),
83+
initial_bridge_voltage=panel.get_value("initial_voltage", 0.0),
84+
gage_factor=panel.get_value("gage_factor", 2.0),
85+
voltage_excit_val=panel.get_value("voltage_excitation_value", 0.0),
86+
strain_config=panel.get_value(
87+
"strain_configuration", StrainGageBridgeType.FULL_BRIDGE_I
88+
),
89+
)
90+
else:
91+
chan = task.ai_channels.add_ai_voltage_chan(
92+
panel.get_value("physical_channel", ""),
93+
terminal_config=panel.get_value(
94+
"terminal_configuration", TerminalConfiguration.DEFAULT
95+
),
96+
max_val=panel.get_value("max_value_voltage", 5.0),
97+
min_val=panel.get_value("min_value_voltage", -5.0),
14098
)
141-
panel.set_value("acquired_data", data)
142-
except KeyboardInterrupt:
143-
pass
144-
finally:
145-
task.stop()
146-
panel.set_value("is_running", False)
147-
148-
except DaqError as e:
149-
daq_error = str(e)
150-
print(daq_error)
151-
panel.set_value("daq_error", daq_error)
99+
task.timing.cfg_samp_clk_timing(
100+
source=panel.get_value(
101+
"source", ""
102+
), # "" - means Onboard Clock (default value)
103+
rate=panel.get_value("rate", 1000.0),
104+
sample_mode=AcquisitionType.CONTINUOUS,
105+
samps_per_chan=panel.get_value("total_samples", 100),
106+
)
107+
panel.set_value("sample_rate", task.timing.samp_clk_rate)
108+
# Not all hardware supports all filter types.
109+
# Refer to your device documentation for more information.
110+
if panel.get_value("filter", "Filter") == "Filter":
111+
chan.ai_filter_enable = True
112+
chan.ai_filter_freq = panel.get_value("filter_freq", 0.0)
113+
chan.ai_filter_response = panel.get_value(
114+
"filter_response", FilterResponse.COMB
115+
)
116+
chan.ai_filter_order = panel.get_value("filter_order", 1)
117+
panel.set_value("actual_filter_freq", chan.ai_filter_freq)
118+
panel.set_value("actual_filter_response", chan.ai_filter_response)
119+
panel.set_value("actual_filter_order", chan.ai_filter_order)
120+
else:
121+
panel.set_value("actual_filter_freq", 0.0)
122+
panel.set_value("actual_filter_response", FilterResponse.COMB)
123+
panel.set_value("actual_filter_order", 0)
124+
# Not all hardware supports all filter types.
125+
# Refer to your device documentation for more information.
126+
trigger_type = panel.get_value("trigger_type")
127+
if trigger_type == "5":
128+
task.triggers.start_trigger.cfg_anlg_edge_start_trig(
129+
trigger_source=panel.get_value("analog_source", ""),
130+
trigger_slope=panel.get_value("slope", Slope.FALLING),
131+
trigger_level=panel.get_value("level", 0.0),
132+
)
133+
134+
if trigger_type == "2":
135+
task.triggers.start_trigger.cfg_dig_edge_start_trig(
136+
trigger_source=panel.get_value("digital_source", ""),
137+
trigger_edge=panel.get_value("edge", Edge.FALLING),
138+
)
139+
task.triggers.start_trigger.anlg_edge_hyst = hysteresis = panel.get_value(
140+
"hysteresis", 0.0
141+
)
142+
143+
try:
144+
task.start()
145+
while panel.get_value("is_running", False):
146+
waveform = task.read_waveform(number_of_samples_per_channel=100)
147+
panel.set_value("waveform", waveform)
148+
except KeyboardInterrupt:
149+
pass
150+
finally:
151+
task.stop()
152+
panel.set_value("is_running", False)
153+
print(f"Stopped")
154+
155+
except DaqError as e:
156+
daq_error = str(e)
157+
panel.set_value("daq_error", daq_error)
158+
panel.set_value("is_running", False)
159+
print(f"ERRORED")
152160

153161
except KeyboardInterrupt:
154162
pass

0 commit comments

Comments
 (0)