08-06-2015 06:59 PM
Hi, I am attempting to start analog output based off a digital trigger (either PFIO, or a PXI line) I can do this easy in LabVIEW. However with the C API (through Python wrappers), the problem isthat when I call DAQmxBaseWriteAnalogF64, the write will always timeout as the acquisition has not been triggered. However, I cannot call this after the trigger occurs, as obviously that will be too late.
I cannot find any C API examples where analog output is triggered off a digital trigger. I can find them for analog input, but that is fundamentally different as you can performan read anytime after the trigger occurs.
Python code as follows (the functions are equivalent ot C API, though you do not need ot pass the task handle as it maintained as part of the Task object)
# create analog output task analog_output = Task() analog_output.CreateAOVoltageChan("Dev1/ao0","",-10.0,10.0, DAQmx_Val_Volts, None) analog_output.CfgSampClkTiming("",outputRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples) analog_output.CfgDigEdgeStartTrig("/Dev1/PFI0", DAQmx_Val_Rising) analog_output.StartTask() analog_output.WriteAnalogF64(numSampsPerChan=numSamples, autoStart=False,timeout=1.0, dataLayout=DAQmx_Val_GroupByChannel, writeArray=data, reserved=None, sampsPerChanWritten=byref(samplesWritten))
print("Analog output: Wrote %d samples" % samplesWritten.value)
# create digital trigger
dig_out = Task()
dig_out.CreateDOChan("Dev1/port0", "", DAQmx_Val_ChanForAllLines)
# create digital trigger function highSamples = 1000 numpts = 3 * highSamples doData = np.zeros((numpts,), dtype=np.uint32) doData[highSamples:2*highSamples] = 2**32 - 1 # send digital trigger doSamplesWritten = c_int32() dig_out.WriteDigitalU32(numSampsPerChan=numpts, autoStart=True, timeout=1.0, dataLayout=DAQmx_Val_GroupByChannel, writeArray=doData, reserved=None, sampsPerChanWritten=byref(doSamplesWritten)) print("Digital output: Wrote %d samples" % doSamplesWritten.value)
Solved! Go to Solution.
08-07-2015 03:32 PM
Hi PatrickR,
You can review some of the text based NI DAQmx (ANSI C) code examples on generating an analog output using a digital start trigger. If you included/checked text-based support dusing your NI DAQmx driver installation, you can navigate to Windows Start>All Programs>National Instruments>NI DAQ>Teaxt-Based Code Support>ANSI C Examples>Analog Out>Generate Voltage>Mult Volt Updates-Int Clk-Dig Start. If you have any questions/concerns regarding the NI hardware.
08-07-2015 03:42 PM
Thanks, yeah I eventually found the examples which were in C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog Out\Generate Voltage\Mult Volt Updates-Int Clk-Dig Start
My mistake was that the AnalogWrite() had to occur before StartTask() was called. This fixed the issue
08-07-2015 03:47 PM
Good Job 😃