Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Write 2D Array to analog output

Dear,

 

I want create a task with two analog output channels while using the same clcok. The data for each channel is 4M (4000*1000). The signals are different for two channels.

 

This was succsfully implemented in labview. Is there anyone knows how to achieve the same function in C langunge?

 

Thanks!

 

0 Kudos
Message 1 of 6
(6,289 Views)
DAQmxErrChk(DAQmxCreateTask("ScanVoltageTask",&ScanVoltageTaskHandle));
DAQmxErrChk(DAQmxCreateAOVoltageChan(ScanVoltageTaskHandle,"Dev1/ao0:1","ScanVoltageX", -5,5,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming (ScanVoltageTaskHandle, "/Dev1/PFI0",1000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,100000));
DAQmxErrChk(DAQmxWriteAnalogF64 (ScanVoltageTaskHandle, ScanVoltageNum*frameNumbers, false, DAQmx_Val_WaitInfinitely, DAQmx_Val_GroupByChannel,ScanArray,NULL,NULL));

 My question is about how to build the "ScanArray" ?

0 Kudos
Message 2 of 6
(6,288 Views)

Hi splendourchen,

 

I'm not quite sure what you're asking. Are looking for more information on how to generate a signal or writing the signal itself?Ana

The example finder in LabWindows/CVI has a great example that has both. If you go to Help > Find Examples and then expand Hardware Input and Output > DAQmx > Analog Generation > Voltage > ContGen-ExtClk.prj

 

This might be a good starting point to chekc how this can be done in C.

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

Hello, 

I understand his question, as I have the same doubt.

The issue is specificly with many channels in one task. As fas as I've checked, the examples provided never use several channels in one task.

 

The function DAQmxWriteAnalogF64() takes the argument ScanArray that splendourchen mentioned. The question is how to generate the vector ScanArray to contain the information of the two outputs.

 

For one channel ScanArray can be something like:

 

    
float64 ScanArray[int size]; for(i=0;i<size;i++) ScanArray[i]=A*sin(PI*(double)i/(Tl*fsOutX)); //Some function of i

and then DAQmxWriteAnalogF64() something like:

 

 

 

 

0 Kudos
Message 4 of 6
(5,131 Views)

Hi BKnight,

 

I just want to make sure I'm understanding your question correctly. Are you trying to take data from two outputs, put it in an array, and then use this array as an input to the function DAQmxWriteAnalogF64()? If not, could you please clarify a little more. You may want to take a look at this thread: http://forums.ni.com/t5/Multifunction-DAQ/Duplication-of-output-of-DAQmxWriteAnalogF64-across-two-ch... it doesn't address your issue exactly but you may be able to adapt the example there to your application.

 

Selene v.

Applications Engineer
National Instruments

Selene
0 Kudos
Message 5 of 6
(5,098 Views)

Hi BKnight and QueenSelene,

 

Forget to update my progress. I figured out that you can do like this.

 

float64 ScanArray[2*SampleSizePerChannel];

    for(i=0;i<size;i=i+2)
        ScanArray[i]=SampleCH1[i/2]; //Fill evens with CH1
ScanArray[i+1]=SampleCH2[i/2];//Fill odds with CH2
end
DAQmxErrChk(DAQmxWriteAnalogF64 (ScanVoltageTaskHandle, SampleSizePerChannel, false, DAQmx_Val_WaitInfinitely, DAQmx_Val_GroupByChannel,ScanArray,NULL,NULL));

  Tested and works well. Good luck!

 

Wei

Message 6 of 6
(5,093 Views)