简体   繁体   English

使用NIDAQmx触发输出任务

[英]Triggering an output task with NIDAQmx

I'm having trouble carrying out what I think should be a pretty straightforward task on a NIDAQ usb6002: I have a low frequency sine wave that I'm measuring at an analog input channel, and when it crosses zero I would like to light an LED for 1 second. 我在NIDAQ usb6002上执行我认为应该是一件非常简单的任务时遇到了麻烦:我有一个低频正弦波,正在模拟输入通道上进行测量,当它过零时,我想点亮一个LED 1秒钟。 I'm trying to use the nidaqmx Python API, but haven't been able to clear up some of my basic questions with the documentation. 我正在尝试使用nidaqmx Python API,但无法通过文档解决一些基本问题。 https://nidaqmx-python.readthedocs.io/en/latest/ https://nidaqmx-python.readthedocs.io/en/latest/

If anyone can offer any thoughts about the code or the basic logic of my setup, that would be hugely helpful. 如果有人可以对我的代码或设置的基本逻辑提出任何想法,那将非常有帮助。

Here's what I have tried so far. 到目前为止,这是我尝试过的。 I start with some imports and the definition of my channels: 我从一些导入和渠道定义开始:

import matplotlib.pyplot as plt
from math import *
import nidaqmx
from nidaqmx import *
from nidaqmx.constants import *
import time

V_PIN = "Dev1/ai6"
LED_PIN = "Dev1/ao0"

I understand how tasks and things work generally- I can read and plot a signal of a given sampling rate and number of samples using task.ai_channels methods without any trouble. 我了解任务和事物的一般工作原理-我可以使用task.ai_channels方法读取并绘制给定采样率和样本数量的信号,而不会遇到任何麻烦。 But here's my best guess at how to carry out "detect zero and trigger output": 但是,这是我对如何执行“检测零并触发输出”的最佳猜测:

writeLED = nidaqmx.Task('LED')
writeLED.ao_channels.add_ao_voltage_chan(LED_PIN)
writeLED.timing.cfg_samp_clk_timing(1)
writeLED.triggers.start_trigger.cfg_anlg_edge_start_trig(V_PIN,trigger_level = 0)
writeLED.write([5], auto_start=True)

This gives me the error below at the cfg_anlg_edge line 这使我在cfg_anlg_edge行出现以下错误

DaqError: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Property: DAQmx_StartTrig_Type
Requested Value: DAQmx_Val_AnlgEdge
Possible Values: DAQmx_Val_DigEdge, DAQmx_Val_None

I don't know why an analog input channel wouldn't be supported here. 我不知道为什么这里不支持模拟输入通道。 Page 245 of this document makes it sound like it should be: https://media.readthedocs.org/pdf/nidaqmx-python/latest/nidaqmx-python.pdf 该文档的第245页听起来像是这样: https : //media.readthedocs.org/pdf/nidaqmx-python/latest/nidaqmx-python.pdf

I'm sure there are other problems with the code, too. 我确定代码也有其他问题。 For example, it seems like the sample clock manipulations are quite a bit more complicated than what I've written above, but I haven't been able to find anything that explains how it would work in this situation. 例如,采样时钟的操作似乎比我上面写的要复杂得多,但是我找不到能够解释这种情况下如何工作的任何东西。

Thanks in advance for any help! 在此先感谢您的帮助!

With NI, it's "RTFMs" 使用NI,它就是“ RTFM”

When programming NI devices, you usually need two manuals. 对NI设备进行编程时,通常需要本手册。

  1. NI-DAQmx Help (for the programming part) NI-DAQmx帮助 (用于编程部分)
  2. the device specification (for the device part) 设备规格 (用于设备部分)

You need both because the NI-DAQmx API supports every DAQ device NI makes, but not every device has the same capabilities. 两者都需要,因为NI-DAQmx API支持NI制造的每个 DAQ设备,但并非每个设备都具有相同的功能。 "Capabilities" includes more than how many channels of each kind, but also the timing and triggering subsystems as well as internal signal routing. “功能”不仅包括每种类型的通道数量,还包括计时触发子系统以及内部信号路由。 A DAQmx application that runs with one device is not guaranteed to run with another because the application might use the API in a way the second device cannot support. 不能保证与一台设备一起运行的DAQmx应用程序与另一台设备一起运行,因为该应用程序可能以第二台设备无法支持的方式使用API​​。

Finally, on the documentation front, any given NI DAQ device typically belongs to family of related devices and these families also have a manual called User Guide . 最后,在文档方面,任何给定的NI DAQ设备通常都属于相关设备系列,并且这些系列具有一个称为“ 用户指南”的手册 These User Guides act as a bridge between the API and device spec, helping you understand how the device responds to commands. 这些用户指南充当API与设备规范之间的桥梁,可帮助您了解设备如何响应命令。 For the 6002, the family is "Low-Cost DAQ USB Device" . 对于6002,该系列是“低成本DAQ USB设备”

Analog trigger for analog output on NI 6002 用于NI 6002上模拟输出的模拟触发

Your determination is correct that 您的决定是正确的

writeLED.triggers.start_trigger.cfg_anlg_edge_start_trig(V_PIN,trigger_level = 0)

is possible, just not for the USB 6002. This line is asking the analog output subsystem to use an analog edge trigger, but the analog output subsystem for the 6002 only has these trigger capabilities: 可能的,只是为USB 6002这条线被要求模拟输出子系统使用模拟边沿触发,但对于6002模拟输出子系统只有这些触发功能:

  • software 软件
  • PFI 0 PFI 0
  • PFI 1 PFI 1

For this device, you're only option is the software trigger because the PFI lines are digital triggers and their trigger level is specified to be between 0.8 V and 2.3 V. 对于此设备,您唯一的选择是software触发器,因为PFI线是数字触发器,并且其触发电平指定为0.8 V至2.3V。

Change your Python program to detect a zero-crossing from the analog input stream and, when it does, make it call stop() and then start() on the AO task. 更改您的Python程序,以检测模拟输入流中的过零,并且在发生这种情况时,使其对AO任务调用stop() ,然后调用start()

The reason for the stop-start sequence is retriggering : you want to light the LED for each zero crossing, but a task cannot be restarted unless it has either been stopped (by the API or by completing its task) or configured for retriggering. 停止开始序列的原因是重新触发 :您要为每个零交叉点点亮LED,但是除非已将其停止(通过API或通过完成其任务)或配置为重新触发,否则无法重新启动任务。 Because the 6002 is in the low-cost family, this hardware feature isn't available, so you must use the API to stop the AO task or wait for the AO generation to complete before restarting the pulse for the LED 由于6002在低成本系列中,因此该硬件功能不可用,因此在重新启动LED脉冲之前,必须使用API​​停止AO任务或等待AO生成完成。

6002 AO Specification 6002 AO规格

6002规范的剪辑,显示了模拟输出子系统的功能

Software triggering is not real-time, you will have non-deterministic delay before the led turns on. 软件触发不是实时的,在打开LED之前您将有不确定的延迟。 This depends on your program, interfaces, usb latencies, pc performances... 这取决于您的程序,界面,USB等待时间,PC性能...

Otherwise, you can use a comparator (like lm393) to trigger a digital input (PFI0 or PFI1). 否则,您可以使用比较器(如lm393)来触发数字输入(PFI0或PFI1)。

Though it's just an LED, it is probably not critical if the delay varies within milliseconds. 尽管这只是一个LED,但延迟在几毫秒内变化可能并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM