pythonnidaqmx

PyDAQmx Setting Acquisition Mode to On Demand


I am trying to write a program in PyDAQmx that counts digital edges and outputs a TTL signal every nth edge. I am having trouble setting the Acquisition Mode in PyDAQmx to be "1 Sample (On Demand)" which is what I set while using LabVIEW. I am using a NI USB6210 DAQ Device.

This is my first time coding with NIDAQ/PyDAQMX/etc so I based this on an example on the PyDAQmx page that shows how to translate a C program into Python, the relevant piece of code looks like this:

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

Solution

  • My expectation is that this is the default timing mode for counter input tasks, and you can confirm that by asking the driver via the DAQmx C API's Sample Timing Type parameter:

    DAQmxCreateTask("",byref(taskHandle))
    DAQmxCreateCICountEdgesChan(taskHandle,"Dev6/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp)
    
    timingType = int32()
    DAQmxGetSampTimingType(taskHandle, byref(timingType))
    print(timingType)
    

    If timingType has the value 10390, then you have on-demand sampling.

    In general, if there isn't a 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 you require explicitly.