NI Home > Community > NI Discussion Forums

Multifunction DAQ

Reply
Member
GMag
Posts: 2
0 Kudos

Analog writing 200524

Hi,

I am trying to change my code from Traditional NI DAQ to DAQmx and I am fairly new to DAQmx. In my software I have to generate analog output waveforms in two channels X and Y. I was able to successfully transfer it until that point. Later when I close the program I need to give zero volts to both these channels, previously I used AO_VWrite to do that. However whein I use DAQmxWriteAnalogScalarF64 I get the error  - 200524 saying that the number of channels and the data points are not equal. Appreciate any help even in C. I am posting a sample code with the relevant lines.

Dim data(500) As Double
Dim dataZero(2) As Double


For i = 0 To 500
        data(i) = amplitude * Sin(i*const) ' create data for waveforms
Next i  

For i = 0 To 2
       dataZero(0) = 0# ' create two zero values
Next i

 DAQmxErrChk DAQmxCreateAOVoltageChan(taskHandle, "Dev1/ao0:1", "aoChannel", -10#, 10#, DAQmx_Val_VoltageUnits2_Volts, "") 'Create two channels ao0:1


DAQmxErrChk DAQmxWriteAnalogF64(taskHandle, 250, True, 10#, DAQmx_Val_GroupByScanNumber, data(0), sampsPerChanWritten, ByVal 0&)' until this point no problem
DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, True, 10#, dataZero(0), ByVal 0&) '  Error 200524

With two channels if I pass two data points I dont understand why I get the error. Appreciate any help.


Thank you
Active Participant
Posts: 224
0 Kudos

Re: Analog writing 200524

Hi GMag,

The DAQmxWriteAnalogScalerF64 writes a single floating point sample to a task that contains one channel. This is why you are getting the error because your task contains two channels. In your case, I would append a value of zero to the end of your data() array so that you get the same functionality.
PBear
NI RF
Member
GMag
Posts: 2
0 Kudos

Re: Analog writing 200524

Hi patrick,

Thank you for the advice. I have tried using it with one channel. Actually in my current software the waveforms should keep running continuously and only when the user prompts to stop, it should send zero values to the channels. I have done it in a way that looks cumbersome but works fine. The way I did is

First I stopped the task with two channels, cleared it. (2 functions)
Then I created two tasks, configured analog output CreateAOCurrentChan such that one channel is associated with each task (4 )
Then wrote DAQmxWriteAnalogScalarF64 for each task with zero values (2)
Closed these two tasks and cleard them. (4)

I have to create the task with two channels again if I want to start the waveforms

It was much simpler in Traditional Nidaq where you can use just one function AO_VWrite for each channel instead of using almost 12 functions for this. Do you think there is an efficient way of doing this. 

Thank you
GMag
Active Participant
Posts: 224
0 Kudos

Re: Analog writing 200524

Hi GMag,

When the user prompts to stop, you could stop the task, write some zeros to the buffer, and then start the task again. Stopping the task will move the pointer to the front of the buffer so when you re-start the task, the DAQ card outputs the zeros and not the remaining samples in the buffer. I've taken the liberty of modifying the shipping example Cont Gen Volt Wfm-Int Clk to give an example of this.
PBear
NI RF