Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Read analog output's last value after DAQmxStopTask

Hello everyone.


I'm a physics engineer graduating and I've been trying to develop a software to output an analog signal that will be amplified and applied to a piezoelectric element to perform subnanometric movements.

 

I have a cDAQ-9174 with a NI9263 x4AnalgOutput module in it  (as well as a NI9215 x4AnalgInput) and am using NIDAQmx lib to implement the software in Qt C++ for Windows.

 

The issue I'm having is trying to figure out a way to keep track of last value outputed to one of the channels so I don't damage the piezoelectric crystals by abruply changing the voltage applied everytime I stop and start a task. So I need to figure out where the output was when the task stopped.

 

To ilustrate the issue I've written some code to try to Output a sine wave, Stop it and then Find out what was the value the task stopped in:

 

 

#include <NIDAQmx.h>

double T = 2; // Period of the sine wave
double Nout = 10000; // Size of output vector double fsOut = Nout/T; // Output writing frequency double A = 6; // Output Signal Amplitude
int32 written; NIerrBuff[0]={'\0'}; // For error handling.
double* out = new double[Nout]; TaskHandle taskOut=0; errorChk(DAQmxCreateTask("",&taskOut)); errorChk(DAQmxCreateAOVoltageChan(taskOut,"cDAQ1Mod1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL)); // NI9263 - channel ao0 errorChk(DAQmxCfgSampClkTiming(taskOut,"",fsOut,DAQmx_Val_Rising,DAQmx_Val_ContSamps,Nout)); //Output continuously for(int i=0 ; i<Nout ; i++) // Prepare output vector with sine wave out[i] = A*cos(2*PI*(double)i/(T*fsOut)); errorChk(DAQmxWriteAnalogF64(taskOut,Nout,0,10.0,DAQmx_Val_GroupByChannel,out,&written,NULL)); // Send output vector do device errorChk(DAQmxStartTask(taskOut)); // Start Output task
waitms(3330); // Wait some time in milliseconds errorChk(DAQmxStopTask(taskOut)); //Read last value after stopping.. How???


erroChk(DAQmxClearTask(taskOut));

delete[] out;

The last thing I'd like to do in the code above would be find out what is the current value beeing outputed after stop. As I'm writing an array continuously that can be interrupted at any time, so I have no way of tracking what value the output stopped at programmatically with some global variable.


I've successfully checked that after 'StopTask' the output stops and stays where it was untill some new output task starts.

So, to be gentle with the piezocrystals I need to create a new output vector that starts at the current value of output.

 

I believe there should be some way to read back the last value, but of several things I've tried none worked.

 

Thank you in advance.

 

 

0 Kudos
Message 1 of 6
(5,348 Views)

Hi BKnight,

 

If you are using LabWindows/CVI to write the C code, then you can follow the instructions in the KnowledgeBase article below to read the value of an AO channel, using internal channels.

 

Is It Possible to Read the Value of Analog or Digital Output Channels?

http://digital.ni.com/public.nsf/allkb/CB86B3B174763C3E86256FFD007A2511

 

If not, you can use the DAQmxCreateAIVoltageChan() function with the naming convention described in the article above for LabWindows/CVI for the internal channel “Dev1/_aoX_vs_aognd”.

Regards,

Jake H
Applications Engineer
0 Kudos
Message 2 of 6
(5,327 Views)

Hello and thank you for the reply

So I've tried to create an DAQmxCreateAIVoltageChan() like you mentioned, but still have issues.

It made sense to create another task for this input channel, as in one task there can't be two tasks of diferente types, input and output. Otherwise I get error -200559, for having two diferent types of channels in the same task.


So the initialization code looks like this:

    TaskHandle taskOut=0;
TaskHandle taskOutRead=0; // task dedicated to reading output value errorChk(DAQmxCreateTask("Output",&taskOut)); errorChk(DAQmxCreateTask("OutRead",&taskOutRead)); errorChk(DAQmxCreateAOVoltageChan(taskOut,"cDAQ2Mod1/ao0","OutputChannel",-10.0,10.0,DAQmx_Val_Volts,NULL)); errorChk(DAQmxCreateAIVoltageChan(taskOutRead,"cDAQ2Mod1/_ao0_vs_aognd","OutReadChannel",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));


Is this what you meant?
With this configuration I get a -200170 error for the last line of code, saying the "Physical channel specified does not exist on this device".
Am I doing something wrong? Or  cDAQ-9174 modules' don't support "..._ao0_vs_aognd" ?

 

Thank you once again,

Arthur Vieira

 

 

0 Kudos
Message 3 of 6
(5,310 Views)

Unfortunately, as you have seen, it appears that the ao_vs_aognd option is not available on your device. It does not look like there is going to be an inherint way to do what you are looking to do. Is is possible to have some sort of global variable, or count on your output array so you know what you last output value should be? Otherwise you may have to look into another module (whether its a module that does support ao_vs_aognd, though from my research it looks like it may not be compatible on any C-series modules for the cDAQ, or an analog input module to actually get a true reading. 

Message 4 of 6
(5,269 Views)

Well. That's unfortunate. Thumb down on this cDAQ modules then. 
A global variable is not efective if I write a big array and have the task be stopped by the user at any moment at some unpredictable output.
What I will do is let the task finnish and then take control from there with a global variable. But it does take some of the potential way from my program, because I could have a task running continuously and be stopped only with user input.

Thanks for the response!

Arthur

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

Found the solution.
(Btw, changed my name on the forum. I'm BKnight)

The device specified has a write property called 'DAQmxGetWriteTotalSampPerChanGenerated' that gives you the current position of the write pointer in the buffer after you Stop the task. Then you can use it in your original outputArray to figure out at what voltage it stopped.

Hope this helps anyone with the same issue.

Arthur

0 Kudos
Message 6 of 6
(4,795 Views)