Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Duplication of output of DAQmxWriteAnalogF64 across two channels

Hello all,

 

Language/Package: Python/PyDAQMx

 

I am trying to write a 2D array of analog data to my NI USB-6251 DAQ device.

I want to simlutaneously write 2 channels of data to my device.

However, I am passing the same row of data to two channels (i.e. row1 data to both channel 1 and channel 2 output) instead of row1 data to channel 1 output, row2 data to channel 2 output.

I created a .vi in labview that works off of NI Write 2D Analog channel but am trying to port to scripting language (shown in labview analog .png)

 

Desired Ouput in signal express: Capture.png

 

Acquired Output: Capture2.png

 

Relevant portion of Script is below:

 

# DAQmx Configure Code
DAQmxCreateTask("",byref(taskHandle))
DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,"")
DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,"")
DAQmxCfgSampClkTiming(taskHandle,"",100000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,100000)

 

try:
for numIter in range (0, data_iter):
rng = numIter*100000
data = arr2d[:, rng:rng+100000]
DAQmxWriteAnalogF64(taskHandle, samplePerChan, 0, -1, DAQmx_Val_GroupByScanNumber, data, None, None)
if numIter == 0:
DAQmxStartTask(taskHandle)
numIter = numIter + 1;
except DAQError as err:
print "DAQmx Error: %s"%err
finally:
if taskHandle:
# DAQmx Stop Code
DAQmxStopTask(taskHandle)
DAQmxClearTask(taskHandle)

 

 

Any help would be greatly appreciated.

 

Cheers,

Jeremy

Download All
0 Kudos
Message 1 of 6
(6,669 Views)

Hi jyhuang,

 

I see that you are using Python/PyDAQmx, which from my understanding tries to create a one to one match with Python and the ANSI  C functions provided with the DAQmx driver. We have a very nice Continuous Analog Output example in the ANSI C shipping examples with DAQmx. You can navigate to the example by clicking Start >> All Programs >> National Instruments >> NI-DAQmx >> Text-Based Code Support >> ANSI C Examples >> Analog Out >> Generate Voltage >> Cont Gen Volt Wfm – Int Clk. One of the lines you will want to replace would be the line below so that you add both channels to the virtual channel:

 

DAQmxCreateAOVoltageChan(taskHandle," Dev1/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,"")

 

Let me know if this example helps or if you need further guidance on your application.

Sam Burhans
Senior Product Manager
National Instruments
0 Kudos
Message 2 of 6
(6,619 Views)

Hello Sam,

 

I tried your solutions but when i am recording using Signal Express I still see that both AO0 and Ao1 mirrors the data from one channel.

Are there any other possible solutions that exist?

Can you give me an example in C of what i kind of want to do? (Multiple channel output, not just single channel output which the example demonstrates).

 

Cheers,

Jeremy

0 Kudos
Message 3 of 6
(6,616 Views)

Hi jyhuang,

 

I apologize I thought based upon the title of your thread and the information that you posted that you wanted to duplicate data output on AO0 and AO1.

 

After looking through the examples I do not believe we have an example for exactly what you are doing. We do have a couple options to try. For the first option you could create two totally separate tasks and just share a start trigger and a sample clock. Sharing these two pieces of information will synchronize the tasks. Then you could just provide a one dimensional array of values for each individual channel.

 

I have not found the exact functionality of the Analog 2D DBL NChan NSamp in the NI DAQmx C Reference Help. The DAQmxWriteAnalogF64 does not seem to specifically state that a two dimensional array can be used.


However, what do you see if you create a task with both channels in the virtual channel, use a two dimensional array in for the float64[] parameter, and use DAQmx_Val_GroupByChannel for the dataLayout parameter?

Sam Burhans
Senior Product Manager
National Instruments
0 Kudos
Message 4 of 6
(6,593 Views)

Hello Sam,

 

How exactly would i share a clk and a trigger?

Jeremy

0 Kudos
Message 5 of 6
(6,572 Views)

Hi jyhuang,

 

I would recommend looking at the SyncAI-AO.c example located here:

 

Start >> All Programs >> National Instruments >> NI-DAQmx >> Text Base Code Support >> NI-DAQmx ANSI C Examples >> Synchronization >> Multifunction >> Synch AI-AO. Although this example uses AI and AO if you change the task type you can quickly make this example work for your application.

 

Also make sure when you are setting up your sample clock timing that the rates are the same for both tasks. If the tasks are set at different rates they will be simultaneously running instead of synchronously running.

Sam Burhans
Senior Product Manager
National Instruments
Message 6 of 6
(6,553 Views)