rjb3
rjb3

Reputation: 39

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. I've been using a wrapper I found and have been able to get AI but am struggling with AO. There is a base class NITask which handles task generation etc. The class i'm calling is below. 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

Upvotes: 1

Views: 2127

Answers (1)

Joe Friedrichsen
Joe Friedrichsen

Reputation: 1986

Your question covers two problems:

  1. Why does DAQmxBaseCfgSampClkTiming return an error?
  2. Without using that function, why isn't any output generated?

1. Hardware vs Software Timing

rjb3 wrote:

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]:

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. GND is the ground-reference signal for the analog output channels.

"Software-timed" means a sample is written on demand by the program whenever DAQmxBaseWriteAnalogF64 is called. 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]. 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. 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.

2. No Output When Software Timed

rjb3 wrote:

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:

  1. Try using the installed genVoltage.c C example and confirm that you can see voltage on the ao channel.
    • Examples are installed here: /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.
    • 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.
  2. Try porting genVoltage.c using the python bindings. At first glance, I would try:
    • Use DAQmxBaseStartTask before DAQmxBaseWriteAnalogF64
    • Or set the autostart parameter in your call to DAQmxBaseWriteAnalogF64 to true.

References

[1] NI USB-6008/6009 User Guide And Specifications :: Analog Output (page 16)
http://digital.ni.com/manuals.nsf/websearch/CE26701AA052E1F0862579AD0053BE19

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

Upvotes: 1

Related Questions