PyDAQmx 将采集模式设置为按需

PyDAQmx Setting Acquisition Mode to On Demand

我正在尝试在 PyDAQmx 中编写一个程序来计算数字边沿并每隔 n 个边沿输出一个 TTL 信号。我无法将 PyDAQmx 中的采集模式设置为“1 个样本(按需)”,这是我在使用 LabVIEW 时设置的。我正在使用 NI USB6210 DAQ 设备。

这是我第一次使用 NIDAQ/PyDAQMX/etc 进行编码,因此我基于 PyDAQmx 页面上的一个示例,该页面展示了如何将 C 程序翻译成 Python,相关的代码片段如下所示这个:

read = int32()
data = numpy.zeros((1000,), dtype=numpy.uint32)
try:
    DAQmxCreateTask("",byref(taskHandle))
    DAQmxCreateCICountEdgesChan(taskHandle,"Dev6/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp)
    #Somehow set acquisition mode here
    DAQmxStartTask(taskHandle)

while True:

    DAQmxReadCounterScalarU32 (taskHandle, 1000, None, read)
    print "Acquired %d samples"%read.value  
    print "result is %s " %result

我的预期是这是计数器输入任务的默认计时模式,您可以通过 DAQmx C API 的 Sample Timing Type 参数询问驱动程序来确认:

DAQmxCreateTask("",byref(taskHandle))
DAQmxCreateCICountEdgesChan(taskHandle,"Dev6/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp)

timingType = int32()
DAQmxGetSampTimingType(taskHandle, byref(timingType))
print(timingType)

如果 timingType 的值为 10390,那么您有按需采样。

一般来说,如果没有 function that does what you want (in this case, there isn't a DAQmxCfgOnDemandTiming() function), you can assume that is the default configuration. In addition, the DAQmx functions don't expose all of the device's settings, however, and so for very specialized behavior, you must get and set the properties 你明确要求。