12-06-2013 06:02 PM
Hello, I use the PCIe6363 and BNC2110 to generate the continued voltage waveform under the internal clock as my analog output.I have test the sample example "Cont Gen Volt Wfm-Int Clk" from the path C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog Out\Generate Voltage, it works well to generate the voltage waveform, but when I want to generate two analog outputs in the program such that the Dev1/ao0 and Dev1/ao1 under the internal clock at the same time, it returns error which is DAQmx Error: The specified resource is reserved, the operation could not be completed as specified.
In the program what I have done is just to copy the sample example and add another virtual channel, as follows:
// Configure the tasks
DAQmxErrChk (DAQmxCreateTask("",&TaskHandle0));
DAQmxErrChk (DAQmxCreateTask("",&TaskHandle1));
// Setting the two virtual channels
DAQmxErrChk(DAQmxCreateAOVoltageChan(TaskHandle0,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCreateAOVoltageChan(TaskHandle1,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(TaskHandle0,"",1000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk(DAQmxCfgSampClkTiming(TaskHandle1,"",1000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
// Write code
DAQmxErrChk(DAQmxWriteAnalogF64(TaskHandle0,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
DAQmxErrChk(DAQmxWriteAnalogF64(TaskHandle1,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
// Start Code
DAQmxErrChk (DAQmxStartTask(TaskHandle0));
DAQmxErrChk (DAQmxStartTask(TaskHandle1));
So I want to what is problem in the program or what I should do to generate two analog outs in the same time under the internal clock.
Thanks!!!
12-09-2013 03:37 PM
Hi johnd77,
You should try putting both analog output channels in the same task. Your code would read:
// Configure the tasks
DAQmxErrChk (DAQmxCreateTask("",&TaskHandle0));
// Setting the two virtual channels
DAQmxErrChk(DAQmxCreateAOVoltageChan(TaskHandle0,"Dev1/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(TaskHandle0,"",1000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
// Write code
DAQmxErrChk(DAQmxWriteAnalogF64(TaskHandle0,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
// Start Code
DAQmxErrChk (DAQmxStartTask(TaskHandle0));
Side note:
"Dev1/ao0:1" is the same as putting "Dev1/ao0, Dev1/ao1"
12-10-2013 07:42 PM
Hi Peter,
I have try you solution but the program cannot compile correctely. It goes to the debug mode and also returns the Unhandled exception at 0x6dd5cc19:0x00000005: Access violation reading location 0x02437000 at the DAQmxWriteAnalogF64(taskHandler0,1000,0,10,DAQmx_Val_GroupByChannel,data,NULL,NULL),
I think it should be some error like the bad ptr and do you have some idea about this problem when I set the "Dev1/ao0:1"in the one task handle.
12-11-2013 03:23 PM
Hi Johnd77,
Did you input your taskHandler0 correctly? It doesn't match up with what you had before which was "DAQmxErrChk(DAQmxWriteAnalogF64(TaskHandle0,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));" with "TaskHandle0" instead of "taskHandler0". Can you send me a screenshot of the exception? That error is a Windows error not a specific National Instruments error.
12-11-2013 04:49 PM
Hi Peter,
You are right that I make some mistake with the "taskHandler0" and "TaskHandler0",but when I correct this mistake and compile the program again, I get another mistake which is "Attempted writing analog data that is too large or too small" , Status Code:-200561.
I have no idea with this error because when I change the code and just use only one vitural channel like"Dev1/ao0"instead of"Dev1/ao0:1", the program works well.
I have attached the screen shot of the error and my main function here and I hope it will help you to figure out the problem.
12-12-2013 01:55 PM
Hi johnd77,
So this error is more to do with writing over the max limit. It is weird that you are getting a value that is -95.5 when you shouldn't get anything more than 9.95 with that equation. Can you try running a variation on the addressing and see if it works, such as "Dev1/ao0, Dev1/ao1". Here is our page on how to define the physical channels and they have a variety of ways you can do it:
http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/physchannames/
12-12-2013 02:57 PM
Hi Peter,
I have try different ways to variate the addressing method
"Dev1\ao0:1"
"Dev1\ao0:Dev1\ao1"
"Dev1\ao0,Dev1\ao1"
reverse order
"Dev1\ao1:0"
"Dev1\ao1:Dev1\ao0"
"Dev1\ao1,Dev1\ao0"
But those all fail with the same error:"Attempted writing analog data that is too large or too small" and when I dedug the program
it fails at the line:
DAQmxErrChk (DAQmxWriteAnalogF64(TaskHandle0,1000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
I also check the data array range (data max is 9.9499999 and the data min is -9.9499999 ).
I feel so confused about this problem!
12-12-2013 10:00 PM
Hi Peter,
I have figured out the problem by setting the data array to data[2000] and the sin wave form function is writeen as follows:
for(;i<2000;i++)
data[i] = 9.95*sin((double)i*2.0*PI/1000.0);
from above I can get two analog outputs (amplitude +/-9.95 and frequency 1Hz, sin waveform)in two virtural channels.
I have totally no idea with the reason why it works and do you know the trick inside?
But anyway it works now and I want to thank you very much for your time and help!
12-13-2013 10:27 AM
Hi Johnd77,
I honestly have no clue why you were getting the error you were and why 2000 points vs 1000 points worked! I went ahead and checked the values in Excel with the given inputs and you should not of been getting -95 for an entry. I am glad to hear your program works though!!
12-13-2013 10:55 AM
Hey Johnd77,
I was able to run the same code on my system with no issues. The only things I could think of was that I initialized my data array (This is always a good idea). Also, if 2000 is working for you, what I might suggest doing is to make it an array of 1001 and just initializing it correctly by declaring:
float64 data[1001] = {0};