Quantcast
Channel: Measurement Studio for VC++ topics
Viewing all articles
Browse latest Browse all 654

Read analog output's last value after DAQmxStopTask

$
0
0

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.

 

 


Viewing all articles
Browse latest Browse all 654

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>