代码拉取完成,页面将自动刷新
import numpy as np
import nidaqmx
import matplotlib.pyplot as plt
from nidaqmx.constants import AcquisitionType, TaskMode
""" Creating Sine wave for Analog output generation"""
Fs = 8000 # sampling frequency
f = 5 # frequency of signal
sample = 8000 # time domain array size
x = np.arange(sample) # time domain array
y = np.sin(2 * np.pi * f * x / Fs) # sine wave
""" Done """
""" Configuration for both analog input and output"""
with nidaqmx.Task() as master_task, nidaqmx.Task() as slave_task:
master_task.ai_channels.add_ai_voltage_chan("Dev3/ai2") # analog input port is reserved
slave_task.ao_channels.add_ao_voltage_chan("Dev3/ao0") # analog output port is reserved
master_task.timing.cfg_samp_clk_timing(
8000, sample_mode=AcquisitionType.CONTINUOUS) # analog input port is configured for continuous 8000 s/s )
slave_task.timing.cfg_samp_clk_timing(
8000, sample_mode=AcquisitionType.CONTINUOUS) # analog output port is configured for continous 8000 s/S
""" Done """
""" Start generating AO and reading AI"""
slave_task.write(y) # analog output buffer is filled with sine wave
slave_task.control(TaskMode.TASK_COMMIT) # analog output port is committed
master_task.control(TaskMode.TASK_COMMIT) # analog input port is committed
print('Acqusition is started')
slave_task.start()
master_task.start()
""" Done """
while True:
master_data = master_task.read(
number_of_samples_per_channel=8000) # analog input sample per read value is 8000, so min. period can be 1sec
plt.plot(x / Fs, master_data)
plt.pause(0.01)
plt.gcf().clear()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。