nidaqmx co_通道无法写入samp

2024-09-26 18:15:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用Ni-Daq产生脉冲。 nidaqmx提供的示例如下:

    import nidaqmx
from nidaqmx.types import CtrTime


with nidaqmx.Task() as task:
    task.co_channels.add_co_pulse_chan_time("Dev1/ctr0")

    sample = CtrTime(high_time=0.001, low_time=0.002)

    print('1 Channel 1 Sample Write: ')
    print(task.write(sample))

但是在我运行这个脚本之后,它会生成一些错误,如下所示:

raise DaqError(error_buffer.value.decode("utf-8"), error_code) DaqError: The task is not buffered or has no channels. If the task is not buffered, use the scalar version of this function. If the task has no channels, add one to the task. Task Name: _unnamedTask<0>

Status Code: -201395

是什么原因造成的?怎么解决?在

非常感谢!在


Tags: thesampleimportaddtasktimeiserror
1条回答
网友
1楼 · 发布于 2024-09-26 18:15:04

nidaqmx的Python示例针对NI的X系列设备(63xx型号)进行了调整。62xx型号是M系列设备,它们的计数器对您如何编程更加挑剔。简而言之:脉冲规范必须在信道创建时给出,而不能在以后给出。X系列设备没有此限制。在

配置脉冲形状

而不是

task.co_channels.add_co_pulse_chan_time("Dev1/ctr0")

试试看

^{pr2}$

而且因为您以这种方式指定了脉冲,所以您不再需要write()到通道。当你想启动脉冲序列时,只要使用

task.start()

配置脉冲序列的长度

当你产生一个脉冲串,你可以告诉司机发射有限数量的脉冲或一个连续的方波。在

start()任务之前,请使用cfg_implicit_timing()。这个片段产生1200个脉冲:

# https://github.com/ni/nidaqmx-python/blob/master/nidaqmx/_task_modules/timing.py#L2878
pulse_count = 1200;
task.cfg_implicit_timing(
    sample_mode=AcquisitionType.FINITE,
    samps_per_chan=pulse_count)

相关问题 更多 >

    热门问题