Skip to content

Commit

Permalink
Add Digital Input examples
Browse files Browse the repository at this point in the history
  • Loading branch information
WayneDroid committed May 6, 2024
1 parent db57411 commit ebcc616
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 30 deletions.
28 changes: 28 additions & 0 deletions examples/digital_in/cont_wfm_acq_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Example for reading digital signal.
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, READ_ALL_AVAILABLE


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(READ_ALL_AVAILABLE)
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_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example for reading digital signal.
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_port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example for reading 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}")
16 changes: 16 additions & 0 deletions examples/digital_in/wfm_acq_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example for reading digital signal.
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:f}" for value in data) + "]")

0 comments on commit ebcc616

Please sign in to comment.