Skip to content

Commit fe3719e

Browse files
HSKhor-NIbkeryan
andauthored
[26Q2]: Add Calculated Power Channel Python Example (#915)
* Add Calculated Power Channel Python Example * Fix formatting * Fix typo and add documentation for supported device * examples: Fix comment formatting --------- Co-authored-by: Brad Keryan <[email protected]>
1 parent 68fe403 commit fe3719e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Example of analog input calculated power acquisition.
2+
3+
This example demonstrates how to acquire a finite amount
4+
of calculated power data using the DAQ device's internal clock.
5+
6+
Supported Devices:
7+
8+
- PXIe-4311 (DAQmx 26.3.0 or later)
9+
"""
10+
11+
import nidaqmx
12+
from nidaqmx.constants import READ_ALL_AVAILABLE, AcquisitionType
13+
14+
with nidaqmx.Task() as task:
15+
task.ai_channels.add_ai_calculated_power_chan(
16+
voltage_physical_channel="Dev1/ai0",
17+
current_physical_channel="Dev1/ai1",
18+
voltage_min_val=0.0,
19+
voltage_max_val=5.0,
20+
current_min_val=0.0,
21+
current_max_val=0.02,
22+
ext_shunt_resistor_val=249.0,
23+
)
24+
25+
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)
26+
27+
data = task.read(READ_ALL_AVAILABLE)
28+
print("Acquired data: [" + ", ".join(f"{value:f}" for value in data) + "]")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Example of analog input calculated power acquisition.
2+
3+
This example demonstrates how to acquire a continuous amount of
4+
calculated power data using the DAQ device's internal clock.
5+
6+
Supported Devices:
7+
8+
- PXIe-4311 (DAQmx 26.3.0 or later)
9+
"""
10+
11+
import nidaqmx
12+
from nidaqmx.constants import AcquisitionType
13+
14+
with nidaqmx.Task() as task:
15+
task.ai_channels.add_ai_calculated_power_chan(
16+
voltage_physical_channel="Dev1/ai0",
17+
current_physical_channel="Dev1/ai1",
18+
voltage_min_val=0.0,
19+
voltage_max_val=5.0,
20+
current_min_val=0.0,
21+
current_max_val=0.02,
22+
ext_shunt_resistor_val=249.0,
23+
)
24+
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.CONTINUOUS)
25+
task.start()
26+
print("Running task. Press Ctrl+C to stop.")
27+
28+
try:
29+
total_read = 0
30+
while True:
31+
data = task.read(number_of_samples_per_channel=1000)
32+
read = len(data)
33+
total_read += read
34+
print(f"Acquired data: {read} samples. Total {total_read}.", end="\r")
35+
except KeyboardInterrupt:
36+
pass
37+
finally:
38+
task.stop()
39+
print(f"\nAcquired {total_read} total samples.")

0 commit comments

Comments
 (0)