LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple analog output task

Solved!
Go to solution

Hello,

 

I am new to LabWindows and now I have a question.

 

I would like to generate the same signal on two analog output channels (SCB-68A). My Code ist this:

 

/*********************************************/
            // DAQmx Configure Code
            /*********************************************/
       
            // Channel 1
            DAQmxCreateTask("",&taskHandleCH1);
            DAQmxCreateAOVoltageChan(taskHandleCH1,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL);
            DAQmxCfgSampClkTiming(taskHandleCH1,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
            
            // Channel 2
            DAQmxCreateTask("",&taskHandleCH2);
            DAQmxCreateAOVoltageChan (taskHandleCH2, "Dev1/ao1", "", -10.0, 10.0, DAQmx_Val_Volts, NULL);
            DAQmxCfgSampClkTiming(taskHandleCH2,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);

            /*********************************************/
            // DAQmx Write Code
            /*********************************************/
            // Channel 1
            DAQmxWriteAnalogF64 (taskHandleCH1, totalPulseSizeCH1, 0, 10.0, DAQmx_Val_GroupByChannel,
                                 PulsePatternCH1, NULL, NULL);
            //Channel 2
            DAQmxWriteAnalogF64 (taskHandleCH2, totalPulseSizeCH2, 0, 10.0, DAQmx_Val_GroupByChannel,
                                 PulsePatternCH2, NULL, NULL);*/

            /*********************************************/
            // DAQmx Start Code
            /*********************************************/
            DAQmxStartTask(taskHandleCH1);
            DAQmxStartTask(taskHandleCH2);

 

But the program didn't run. I got the failure:

NON-FATAL RUN-TIME ERROR:   "Test.c", line 175, col 13, thread id 0x00001328:   Function DAQmxWriteAnalogF64: (return value == -50103 [0xffff3c49]). The specified resource is reserved. The operation could not be completed as specified. Task Name: _unnamedTask<1>  Status Code: -50103

 

I think the failure is "DAQmx_Val_GroupByChannel", I mean that the two writing commands use the DAQmx_Val_GroupByChannel at the same time so I can not use the second writing command because the first one use it alreay. But I do not know if it is correct.

 

Can sombody help me please to solve the problem?

 

Best regards

 

0 Kudos
Message 1 of 13
(5,260 Views)

The most probable cause is that your daq board cannot handle two AO tasks simultaneously due to limitations in the hardware (that's why the error: the first task acquires some hardware resource that cannot be shared, so the second one cannot be accomplished).

 

It seems that your AO generation is handled in parallel and in sync between channels: if this is the case, you could add both AO channels to a single DAQmx task, create a single buffer for the output pattern that lines up samples for channel 2 after thos for channel 1 and use one single DAQmxWriteAnalogF64 with this new buffer in input and the same paramaeters as you are already using. The unique Start will start generation on both channels.

 

I have modified one of sample projects that ships with DAQmx to output a wave on 2 channels: I have no hardware to test with but it gives no error on a simulated device. You can test it on your actual board.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 13
(5,251 Views)

Hello,

 

first of all thank your for your answer.

 

I had the same idea with the buffer and it worked. But for me it was coincidence to come to this solution. Now I have a question.

 

I had the signal pattern in an array. For the first channel I use this signal pattern. When I would like to use the same signal pattern on the second channel, I had to double my buffer and fill the space with the same signal pattern as bevor because otherwise I got the failure that the storage was to short. (So in the array I have two identical signal pattern, first the pattern from channel 1 and then the pattern von for channel 2) I do not unterstand how the programm splits the array and divids the array to the channel an sees with part is channel 1 and with part channel 2.

 

The other question is, I used two identical signal pattern but for the test later I need to use two signals that have for example a phase shift. Is there another opportunity to generate that or musst I do that on the same way and ajust my signal pattern?

 

Sorry for the long question, I hope someone can answer that. Thank you for the example it helps a lot.

 

Best Regards

0 Kudos
Message 3 of 13
(5,247 Views)
Solution
Accepted by topic author Fasching_K

It is correct to double the buffer and fill it with the proper pattern. DAQmx reads the buffer and splits the patterns between the channes according to Data Layout parameter in DAQmxWriteAnalogF64 (). If this parameter is set to Group by Channel, samples for one channel are stored consecutively, followed by samples for the next channel and so on, as you did till now; if Group by Scan Number, samples are stored interleaved, that is (considering N channels and M samples per channel): Channel1Sample1, Channel2Sample1....ChannelNSample1, Channel1Sample2....ChannelNSample2..... Channel1SampleM.... ChannelNSampleM.

 

If you want to have differen patterns on the channels, simply fill the buffer with different data arrays.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 13
(5,240 Views)

Hello,

 

thank you again for your answer.

 

At last I would like to ask how I can intrepret "Samples Per Channel"? I saw and read about it but I did not completly unterstand what it means. For signal it is a important variable.

 

Best Regards

 

 

0 Kudos
Message 5 of 13
(5,238 Views)

There's nothing mysterious about that value: it's the number of samples that will be output to the analog channel. This number and the rate of generation define how long the generation will last if one-time output only. You must provide a buffer that is at least NumberOfSamples * NumberOf Channels wide



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 13
(5,224 Views)

Ah okay thank you.

 

I must ask something again to the command DAQmxWriteAnalogF64 (). I can not unterstand how the command can select the pattern for each channel. In the array there are some double variables but how does the command now where the first pattern ends and the second pattern starts?

 

Best Regards

0 Kudos
Message 7 of 13
(5,204 Views)

It depends on Data layout parameter: see my previous answer



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 13
(5,199 Views)

Ok thank you. I didn't understand the context but I think now I have it. The "Samples per Channel" gives the number how many values must be taken from the array for each channel. 

0 Kudos
Message 9 of 13
(5,194 Views)
Solution
Accepted by topic author Fasching_K

Correct. Smiley Happy

Samples per channel and Number of channels tells you how to dimension the buffer.

Data layout tells you how to fill in the buffer.

The system interprets those parameters the same.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 10 of 13
(5,188 Views)