Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to terminate a continuous non-regenerative analog output

Hi all,

 

I am able to create an continuous analog output which is set as "Do-not-regen". I can write buffer on the fly and set "Next write is last" when reaching end of the waveform. Thanks to Jorr-El's helpful suggestion on a separate thread: http://forums.ni.com/t5/Multifunction-DAQ/Access-analog-output-buffer-on-fly/m-p/3343628 

 

The question I have is how may I stop this continuous task? The way I write the buffer is in the registered EventN callback function, but by the time it writes the end of the waveform, it is not the time when the task finishes or outputs the end of the waveform. I cannot register Done event since the task is continuous, so I don't know what would be the best way to terminate task when it finishes the whole waveform. I am using X-series DAQ and any help would be appreciated.

0 Kudos
Message 1 of 6
(2,852 Views)

skuo1008, 

Can you help us understand why you are using a Register Event Callback Function? These are typically used for ActiveX or .NET calls. 

Also, can you give us some more context on what you are trying to do in your application? What functionality or logic would you like to stop the waveform. Assuming you are using DAQmx, you should take a look at the example for Continout Output from the example finder under Hardware Input/Output and DAQmx (in Help>>Find Examples)

0 Kudos
Message 2 of 6
(2,811 Views)

I am using DAQmx ANSI C, not .NET. According to the DAQmx software events (http://www.ni.com/tutorial/5384/en/ ), I can register callback function to "Every N Samples Transferred From Buffer Event", and write additional analog output buffers in the callback function. Also, in http://zone.ni.com/reference/en-XX/help/370469AG-01/daqmxprop/daqmxwrite/, I can specify "Next Write Is Last" to prevent underflow errors after writing the last sample as long as I set the RegenMode to "Do Not Allow Regeneration".

 

The reason why I prefer continuous AO task is because I'd like to keep the flexibility to change the waveform on the fly but I cannot do that once the buffer is full if I set the task to be finite. Everything works fine if I leave it as open-ended and be terminated by stop function, but I am asking if there is a way to make the task to be self-terminated. If user can specify "Next Write Is Last", shouldn't the task be able to invoke something like "Done Event"?

 

0 Kudos
Message 3 of 6
(2,806 Views)

skuo1008, 

It is a bit hard to imagine what you are doing without a visual, can you post the VI so we can take a look and provide more pointed direction?

In general, you can set up a signal such as a boolean that can activate a case structure set to run the "Stop Task" function after your "Next Write is Last" function is run, is this the functionality you are looking for?

0 Kudos
Message 4 of 6
(2,780 Views)

I don't have VI to share since I was coding in ANSI C. I may try to post some code later.

 

Basically yes, I did run the "Stop Task" function after the "Next Write is Last" function is run, however, the actually output is truncated since timing of StopTask is before finishing writing end of waveform.

 
 

 

0 Kudos
Message 5 of 6
(2,768 Views)

Crude idea: with a non-regenerative task, what if you stop writing data to the buffer after finishing off the desired last waveform cycle?  The task will throw an error when it runs out of data to D/A convert, but you could choose to expect and ignore it, right?

 

Cleaner idea: when you know you want to stop generating your waveform, first write the last samples to the AO buffer.  Follow that up with writing values that bring the AO to 0.0 volts.  You may want to ramp gently from where you left off to 0, you may be able to do a step function, I can't tell from here.  Once you get down to 0, continue writing 0 values until they fill the entire AO buffer.  Once you start D/A converting those 0 values, you can stop the task any time.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 6
(2,755 Views)