Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous analog output: how to solve correctly? [C#, with appendix]

I want to have a continuous analog output signal. The signal does not consist of any repeating sequences. Therefore I can't use waveform functions and must set DoNotAllowRegeneration.

 

The big problem is:

When and how do I have to send new values to the buffer?

 

As there are no "official" examples for continuous analog output in C#, I tried different things.

My solution is in the appendix (for Visual Studio 2008).

 

 

1. issue:

I check the available output buffer space with myTask.Stream.OutputBufferSpaceAvailable.

But this value will always be 0 if I haven't set the size of the output buffer manually with myTask.Stream.ConfigureOutputBuffer(buffersize).

The odd thing is, that usually the output buffer size should be set automatically by DAQmx according to the help (see http://digital.ni.com/public.nsf/allkb/E1E67695E76BA75B86256DB1004E9B07).

Is myTask.Stream.OutputBufferSpaceAvailable supposed to be 0 if I don't set the buffer size manually?

 

Information:

When I configure the sample clock with myTask.Timing.ConfigureSampleClock the help says for the parameter samplesPerChannel:

If sample mode is continuous, NI-DAQmx uses it to determine buffer size.

As this seems not to work (?) it doesn't matter which value I set for this parameter (I've tried ...).

 

 

2. issue:

In my opinion writer.BeginWriteMultiSample does internally set a "sleep/wait time" if the buffer is full. It will write the data when there's space in the buffer available. Therefore it wouldn't be necessary to check if there's any buffer space available, would it be?

But a disadvantage is that I can't immediately stop outputting when I always try to write data to the buffer without setting any sleep times (with Thread.Sleep).

 

Is there any other solution than using Thread.Sleep?

Actually I don't like these sleep times 😉

 

 

3. issue:

I found out that I may use writer.WriteMultiSample only before starting the task. After starting the task I only may use writer.BeginWriteMultiSamples to add new data.

Is this correct?

 

 

4. issue: 

How can I set the output to zero before/after stopping the task?

writer.WriteSingleSample(true,0) does not work.

0 Kudos
Message 1 of 3
(5,552 Views)

Hi, did you try this example?

 

C:\Dokumente und Einstellungen\All Users\Dokumente\National Instruments\NI-DAQ\Examples\DotNET3.5\Analog Out\Generate Voltage\ContGenVoltageWfm_IntClk\CS

 

 

There are basically two ways of Analog Output with DAQmx. Regenerated AO and Non-Regenerated AO which distinct from each other by the value

of the "myTask.Stream.WriteRegenerationMode" - property. 

If you choose to do non-regenerated AO (set WriteRegenerationMode to FALSE), you have to provide data fast enough to keep the Output buffer filled by

calling the WriteMultiSample- method frequently.

 

regards

 

Marco 

0 Kudos
Message 2 of 3
(5,519 Views)

Thanks for your reply!

 

Yes, I've seen the examples.

But the examples for continuous output are all with waveforms. That means, these examples use "AllowRegeneration".

 

I need the mode "DoNotAllowRegeneration" (as my data is always changing). I know I have to provide data fast enough. Actually it works the way I do it (see example in attachment of first post).

I just came across the four issues in the first post. For these issues I could not find any answer. I got the solution by trying out.

But I would like to know WHY is it that way 🙂

 

And for the 4th issue:

In the examples the last written value stays active (e.g. 5V). But I want to have 0V after stopping it.

0 Kudos
Message 3 of 3
(5,516 Views)