Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Digital Input examples #573

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/digital_in/acq_dig_port_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example for reading digital signals.

This example demonstrates how to input a finite digital pattern
using the DAQ device's internal clock.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, LineGrouping, READ_ALL_AVAILABLE


with nidaqmx.Task() as task:
task.di_channels.add_di_chan("Dev1/port0", line_grouping=LineGrouping.CHAN_FOR_ALL_LINES)
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)

data = task.read(READ_ALL_AVAILABLE)
print("Acquired data: [" + ", ".join(f"{value:#x}" for value in data) + "]")
28 changes: 28 additions & 0 deletions examples/digital_in/cont_acq_dig_lines_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Example for reading digital signals.

This example demonstrates how to acquire a continuous digital
waveform using the DAQ device's internal clock.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, LineGrouping


with nidaqmx.Task() as task:
task.di_channels.add_di_chan("Dev1/port0/line0:3", line_grouping=LineGrouping.CHAN_PER_LINE)
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.CONTINUOUS)
task.start()
print("Acquiring samples continuously. Press Ctrl+C to stop.")

try:
total_read = 0
while True:
data = task.read(number_of_samples_per_channel=1000)
read = len(data)
total_read += read
print(f"Acquired data: {read} samples. Total {total_read}.", end="\r")
except KeyboardInterrupt:
pass
finally:
task.stop()
print(f"\nAcquired {total_read} total samples.")
30 changes: 0 additions & 30 deletions examples/digital_in/di_sw_timed.py

This file was deleted.

15 changes: 15 additions & 0 deletions examples/digital_in/read_dig_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example for reading digital signals.

This example demonstrates how to read values from one or more
digital input channels.
"""

import nidaqmx
from nidaqmx.constants import LineGrouping


with nidaqmx.Task() as task:
task.di_channels.add_di_chan("Dev1/port0/line0:3", line_grouping=LineGrouping.CHAN_PER_LINE)

data = task.read()
print(f"Acquired data: {data}")
15 changes: 15 additions & 0 deletions examples/digital_in/read_dig_port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example for reading a digital signal.

This example demonstrates how to read values from a digital
input port.
"""

import nidaqmx
from nidaqmx.constants import LineGrouping


with nidaqmx.Task() as task:
task.di_channels.add_di_chan("Dev1/port0", line_grouping=LineGrouping.CHAN_FOR_ALL_LINES)

data = task.read()
print(f"Acquired data: {data:#x}")
Loading