简体   繁体   English

在Mac OSX上使用python和NIDAQmx从USB6009进行模拟输出

[英]Analog output from USB6009 using python and NIDAQmx base on Mac OSX

All, I'm attempting to use Python and DAQmx Base to record analog input and generate analog output from my USB 6009 device. 所有,我都尝试使用Python和DAQmx Base记录模拟输入并从USB 6009设备生成模拟输出。 I've been using a wrapper I found and have been able to get AI but am struggling with AO. 我一直在使用找到的包装器,能够获得AI,但在与AO方面遇到了困难。 There is a base class NITask which handles task generation etc. The class i'm calling is below. 有一个处理任务生成等的NITask基类。我正在调用的类如下。 The function throws an error when I try to configure the clock. 当我尝试配置时钟时,该函数引发错误。 When I do not there is no error but nor is there voltage generated on the output. 当我没有错误时,输出端也不会产生电压。 Any help would be appreciated. 任何帮助,将不胜感激。

Thanks! 谢谢!

class AOTask(NITask):
    def __init__(self, min=0.0, max=5.0,
                 channels=["Dev1/ao0"],
                 timeout=10.0):
        NITask.__init__(self)

        self.min = min
        self.max = max
        self.channels = channels
        self.timeout = timeout
        self.clockSource ="OnboardClock"
        sampleRate=100
        self.sampleRate = 100
        self.timeout = timeout
        self.samplesPerChan = 1000
        self.numChan = chanNumber(channels)

        if self.numChan is None:
            raise ValueError("Channel specification is invalid")

        chan = ", ".join(self.channels)


        self.CHK(self.nidaq.DAQmxBaseCreateTask("",ctypes.byref(self.taskHandle)))
        self.CHK(self.nidaq.DAQmxBaseCreateAOVoltageChan(self.taskHandle, "Dev1/ao0", "", float64(self.min), float64(self.max), DAQmx_Val_Volts, None))
        self.CHK(self.nidaq.DAQmxBaseCfgSampClkTiming(self.taskHandle, "", float64(self.sampleRate), DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, uInt64(self.samplesPerChan)))

    """Data needs to be of type ndarray"""
    def write(self, data):
        nWritten = int32()
      #  data = numpy.float64(3.25)
        data = data.astype(numpy.float64)
        self.CHK(self.nidaq.DAQmxBaseWriteAnalogF64(self.taskHandle,
            int32(1000), 0,float64(-1),DAQmx_Val_GroupByChannel,
            data.ctypes.data,None,None))
      #  if nWritten.value != self.numChan:
      #  print "Expected to write %d samples!" % self.numChan

Your question covers two problems: 您的问题涉及两个问题:

  1. Why does DAQmxBaseCfgSampClkTiming return an error? 为什么DAQmxBaseCfgSampClkTiming返回错误?
  2. Without using that function, why isn't any output generated? 如果不使用该功能,为什么不生成任何输出?

1. Hardware vs Software Timing 1.硬件与软件时序

rjb3 wrote: rjb3写道:

The function throws an error when I try to configure the clock. 当我尝试配置时钟时,该函数引发错误。 When I do not there is no error but nor is there voltage generated on the output. 当我没有错误时,输出端也不会产生电压。

Your program receives the error because the USB 600x devices do not support hardware-timed analog output [1]: 您的程序收到错误,因为USB 600x设备不支持硬件定时的模拟输出[1]:

The NI USB-6008/6009 has two independent analog output channels that can generate outputs from 0 to 5 V. All updates of analog output channels are software-timed. NI USB-6008 / 6009具有两个独立的模拟输出通道,可产生0至5 V的输出。模拟输出通道的所有更新均由软件定时。 GND is the ground-reference signal for the analog output channels. GND是模拟输出通道的接地参考信号。

"Software-timed" means a sample is written on demand by the program whenever DAQmxBaseWriteAnalogF64 is called. “软件定时”表示每次DAQmxBaseWriteAnalogF64时,程序都会根据需要编写示例。 If an array of samples is written, then that array is written one at a time. 如果写入样本数组,则一次写入该数组。 You can learn more about how NI defines timing from the DAQmx help [2]. 您可以从DAQmx帮助[2]中了解有关NI如何定义时序的更多信息。 While that document is for DAQmx, the same concepts apply to DAQmx Base since the behavior is defined by the devices and not their drivers. 虽然该文档适用于DAQmx,但相同的概念也适用于DAQmx Base,因为行为是由设备而不是由其驱动程序定义的。 The differences are in how much of the hardware's capabilities are implemented by the driver -- DAQmx implements everything, while DAQmx Base is a small select subset. 不同之处在于驱动程序实现了多少硬件功能-DAQmx实现了所有功能,而DAQmx Base是一个小的选择子集。

2. No Output When Software Timed 2.软件定时无输出

rjb3 wrote: rjb3写道:

When I do not there is no error but nor is there voltage generated on the output. 当我没有错误时,输出端也不会产生电压。

I am not familiar with the Python bindings for the DAQmx Base API, but I can recommend two things: 我对DAQmx Base API的Python绑定不熟悉,但是我可以建议两件事:

  1. Try using the installed genVoltage.c C example and confirm that you can see voltage on the ao channel. 尝试使用已安装的genVoltage.c C示例,并确认可以看到ao通道上的电压。
    • Examples are installed here: /Applications/National Instruments/NI-DAQmx Base/examples 示例安装在这里: /Applications/National Instruments/NI-DAQmx Base/examples
    • If you see output, you've confirmed that the device and driver are working correctly, and that the bug is likely in the python file. 如果看到输出,则表明设备和驱动程序运行正常,并且该错误很可能在python文件中。
    • If you don't see output, then the device or driver has a problem, and the best place to get help troubleshooting is the NI discussion forums at http://forums.ni.com . 如果看不到输出,则说明设备或驱动程序有问题,获取帮助进行故障排除的最佳位置是http://forums.ni.com上的NI论坛。
  2. Try porting genVoltage.c using the python bindings. 尝试使用python绑定移植genVoltage.c At first glance, I would try: 乍一看,我会尝试:
    • Use DAQmxBaseStartTask before DAQmxBaseWriteAnalogF64 DAQmxBaseStartTask之前使用DAQmxBaseWriteAnalogF64
    • Or set the autostart parameter in your call to DAQmxBaseWriteAnalogF64 to true. 在对DAQmxBaseWriteAnalogF64的调用中将autostart参数设置为true。

References 参考

[1] NI USB-6008/6009 User Guide And Specifications :: Analog Output (page 16) [1] NI USB-6008 / 6009用户指南和规格::模拟输出 (第16页)
http://digital.ni.com/manuals.nsf/websearch/CE26701AA052E1F0862579AD0053BE19 http://digital.ni.com/manuals.nsf/websearch/CE26701AA052E1F0862579AD0053BE19

[2] Timing, Hardware Versus Software [2] 时序,硬件与软件
http://zone.ni.com/reference/en-XX/help/370466V-01/TOC11.htm http://zone.ni.com/reference/en-XX/help/370466V-01/TOC11.htm

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

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