import nidaqmx
from nidaqmx.constants import AcquisitionType, VoltageUnits, TerminalConfiguration
in_channels = 1
out_channels = 1
# Define your input and output channels
input_channels = ["PXI1Slot2/ai{_i}".format(_i=i) for i in range(in_channels)]
output_channels = ["PXI1Slot4/ao{_i}".format(_i=i) for i in range(out_channels)]
# Create tasks
with nidaqmx.Task() as input_task, nidaqmx.Task() as output_task:
# Configure the input task for hardware-timed voltage measurement
input_task.ai_channels.add_ai_voltage_chan(",".join(input_channels))
# input_task.timing.cfg_samp_clk_timing(
# rate=1000, # Set your desired sampling rate (samples per second)
# sample_mode=AcquisitionType.FINITE,
# samps_per_chan=10, # Set the total number of samples to read
# )
# Configure the output task for hardware-timed voltage generation
output_task.ao_channels.add_ao_voltage_chan(",".join(output_channels))
output_task.timing.cfg_samp_clk_timing(
rate=10000, # Set your desired sampling rate (samples per second)
sample_mode=AcquisitionType.CONTINUOUS,
samps_per_chan=1000, # Set the total number of samples to read
)
# Start the tasks
# input_task.start()
# output_task.start()
step = 0
try:
while True:
# Read data from the input task
input_data = input_task.read()
# Modify the output based on your logic
if step % 2 == 0:
output_task.write(5)
else:
output_task.write(0)
step += 1
except KeyboardInterrupt:
# Handle user interruption (e.g., Ctrl+C) by stopping and closing tasks
input_task.stop()
output_task.stop()
DaqWriteError: Non-buffered hardware-timed operations are not supported for this device and Channel Type. Set the Buffer Size to greater than 0, do not configure Sample Clock timing, or set Sample Timing Type to On Demand. Task Name: _unnamedTask<5> Status Code: -201025