Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Real time analog output in a C# application

Hi everyone,

 

I'm developing an application in VS2008 with C# that requires a real time writing through the analog output of a NI-USB-6281. I have an Input task that gets the data from several analog inputs and I want to put that data processed in an analog output.

 

The input task works perfectly, but I don't get the output task to work.

 

I work with data streams which length is the samplesPerChannel of the input and output tasks. Both task are executed in different threads and they work with the same sampling frequency. I give some extra time to the input task to process data and I've checked that the computer is faster processing the data than the 6281 getting the samples (with the configured sampling frequency). I've seen that the first stream is correctly written in the DAQ output, but later just get a continuous voltage in the output. In this example I show the part of code that doesn't work:

 

 

***************************************

void mainFunction()

{

     OutputTask = new Task();

     OutputTask.AOChannels.CreateVoltageChannel("Dev2/ao0", "Output Channel", -1.0,1.0, AOVoltageUnits.Volts);
     OutputTask.Control(TaskAction.Verify);
     OutputTask.Timing.ConfigureSampleClock("", 8000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 1000);

     analogOutWriter = new AnalogMultiChannelWriter(OutputTask.Stream);

     analogOutWriter.SynchronizeCallbacks = true;


     analogCallback = new AsyncCallback(CallbackFunction);

 

     double[,] OutputData = new OutputData[1,1000];

 

     OutputData = getNewOutput();

 

     analogOutWriter.BeginWriteMultiSample(true, OutputData, analogCallback , null);

}

 

 

void CallbackFunction(IAsyncResult ar)

{

     //Here I've tried to put analogOutWriter.endWrite(ar) or OutputTask.WaitUntilDone() but it didn't work

 

     double[,] OutputData = new OutputData[1,1000];

     OutputData = getNewOutput();

 

     analogOutWriter.BeginWriteMultiSample(true, OutputData, analogCallback , null);

}

 

***************************************

 

I need to know how to send the DAQ a new stream and to check if the former one has been correctly written, all without stopping the output of the DAQ.

 

Thank you for your help.

 

0 Kudos
Message 1 of 1
(4,337 Views)