Skip to content

Commit

Permalink
Add DO examples (#575)
Browse files Browse the repository at this point in the history
* Add DO examples

* fixed style errors

* renamed files and reworked

* removed comments

* removed spinwait

* call task start explicitly
  • Loading branch information
WayneDroid authored May 9, 2024
1 parent 41b7aa5 commit ff11da3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
20 changes: 20 additions & 0 deletions examples/digital_out/cont_gen_dig_port_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Example for generating digital signals.
This example demonstrates how to output a continuous digital
pattern using the DAQ device's clock.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, LineGrouping

with nidaqmx.Task() as task:
data = [1, 2, 4, 8, 16, 32, 64, 128]

task.do_channels.add_do_chan("Dev1/port0", line_grouping=LineGrouping.CHAN_FOR_ALL_LINES)
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.CONTINUOUS)
task.write(data)
task.start()

input("Generating voltage continuously. Press Enter to stop.\n")

task.stop()
21 changes: 0 additions & 21 deletions examples/digital_out/do_sw_timed.py

This file was deleted.

22 changes: 22 additions & 0 deletions examples/digital_out/gen_dig_line_int_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Example for generating digital signals.
This example demonstrates how to output a finite digital
waveform using the DAQ device's internal clock.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, LineGrouping

with nidaqmx.Task() as task:
data: bool = [bool(i % 2) for i in range(1000)]

task.do_channels.add_do_chan("Dev1/port0/line0", line_grouping=LineGrouping.CHAN_PER_LINE)
task.timing.cfg_samp_clk_timing(
1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=len(data)
)

number_of_samples_written = task.write(data)
task.start()
print(f"Generating {number_of_samples_written} voltage samples.")
task.wait_until_done()
task.stop()
16 changes: 16 additions & 0 deletions examples/digital_out/write_dig_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example for generating digital signals.
This example demonstrates how to write values to a digital
output channel.
"""

import nidaqmx
from nidaqmx.constants import LineGrouping

with nidaqmx.Task() as task:
data = [True, False, True, False]

task.do_channels.add_do_chan("Dev1/port0/line0:3", line_grouping=LineGrouping.CHAN_PER_LINE)
task.start()
task.write(data)
task.stop()
16 changes: 16 additions & 0 deletions examples/digital_out/write_dig_port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example for generating digital signals.
This example demonstrates how to write values to a digital
output port.
"""

import nidaqmx
from nidaqmx.constants import LineGrouping

with nidaqmx.Task() as task:
data = 0xFFFFFFFF

task.do_channels.add_do_chan("Dev1/port0", line_grouping=LineGrouping.CHAN_FOR_ALL_LINES)
task.start()
task.write(data)
task.stop()

0 comments on commit ff11da3

Please sign in to comment.