From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop finite output before all of the samples have been output by hardware?

Hello friends,

 

Let's consider a hypothetical situation where I have an application and in it I configure my analog output in finite sample quantity mode such that it is going to output 10000 samples out of analog output channel 0. The configuration could look something like the following...

private Task _task;
private AnalogSingleChannelWriter _writer;
private double[] _sampleArrayToOutput = new[] { /*10000 arbitrary values go here*/ }; _task = new Task("AnalogOutputTask"); _task.AOChannels.CreateVoltageChannel("Dev4/ao0", "ao0", -10, 10, AOVoltageUnits.Volts); _task.Timing.ConfigureSampleClock("", SamplingInfo.SampleRate, SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples, 10000); _task.Control(TaskAction.Verify); _writer = new AnalogMultiChannelWriter(_task.Stream);

Then the code to start the analog output could look something like the following...

_writer.WriteWaveform(false, _sampleArrayToOutput);
_task.Start();

Let's assume that it takes 2 seconds to complete the output of all 10000 samples. And let's say that 1 second after calling _task.Start() I want the hardware to immediately stop outputting samples out of analog output 0, even though it has not finished outputting all 10000 samples.

 

How can I achieve this?

0 Kudos
Message 1 of 3
(2,074 Views)

Maybe a better question is the following. If I were to call _task.Stop() at the "1 second mark" in the example situation described above, will I see any more samples show up on the analog output connection? Or will I see no additional samples and the output will be left at whatever it's most recently written sample voltage was?

0 Kudos
Message 2 of 3
(2,061 Views)

Why can't you just set the number of samples to 5000 instead of 10000? Keep the rate the same so that the program stops after 1 second instead of 2 seconds. As for your question about whether or not the samples would continue to output after stopping them, it might depend on your sample clock source. I'd try it out and see what your results are!

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 3 of 3
(2,038 Views)