Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling two analog output simultaneously from the same clock trigger source C#

Hello,

 

I follow the C# example of NI called ContGenVoltageWfm_ExtClk.2012 and modified it for my purpose. Basically I create a ramp voltage increases at each external clock input. 

As a trigger input I couple an external pulse source to PFI0 pin and AO0 is the ramp output. So each time PFI0 receives a rising edge AO0 increases. It works so far and here below is my code:

 

                // Create the task and channel
                myTask = new Task();

                myTask.AOChannels.CreateVoltageChannel("Dev2/ao0", "", Convert.ToDouble(minimumNumeric.Value), Convert.ToDouble(maximumNumeric.Value), AOVoltageUnits.Volts);

                // Verify the task before doing the waveform calculations
                myTask.Control(TaskAction.Verify);

                // Calculate some waveform parameters and generate data
                FunctionGenerator fGen = new FunctionGenerator(myTask.Timing, frequencyNumeric.Value.ToString(), samplesPerBufferNumeric.Value.ToString(), cyclesPerBufferNumeric.Value.ToString(), signalTypeComboBox.Text, amplitudeNumeric.Value.ToString());

                // Configure the sample clock with the calculated rate and 
                // specified clock source
                myTask.Timing.ConfigureSampleClock("/Dev2/PFI0", fGen.ResultingSampleClockRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 1024);

                // Set up the Task Done event
                myTask.Done += new TaskDoneEventHandler(myTask_Done);

                // Write data to buffer
                AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(myTask.Stream);

                writer.WriteMultiSample(false, fGen.Data);               
              
                // Start writing data
                myTask.Start();

 

But I also want to control AO1 simultaneously with AO0 to generate differential output. So I want PFI0 to trigger both AO0 and AO1. Here below what I tried so far:

 

                // Create the task and channel
                myTask = new Task();

                myTask.AOChannels.CreateVoltageChannel("Dev2/ao0", "", Convert.ToDouble(minimumNumeric.Value), Convert.ToDouble(maximumNumeric.Value), AOVoltageUnits.Volts);
                myTask.AOChannels.CreateVoltageChannel("Dev2/ao1", "", Convert.ToDouble(minimumNumeric.Value), Convert.ToDouble(maximumNumeric.Value), AOVoltageUnits.Volts);

                // Verify the task before doing the waveform calculations
                myTask.Control(TaskAction.Verify);

                // Calculate some waveform parameters and generate data
                FunctionGenerator fGen = new FunctionGenerator(myTask.Timing, frequencyNumeric.Value.ToString(), samplesPerBufferNumeric.Value.ToString(), cyclesPerBufferNumeric.Value.ToString(), signalTypeComboBox.Text, amplitudeNumeric.Value.ToString());

                // Configure the sample clock with the calculated rate and 
                // specified clock source
                myTask.Timing.ConfigureSampleClock("/Dev2/PFI0", fGen.ResultingSampleClockRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 1024);

                // Set up the Task Done event
                myTask.Done += new TaskDoneEventHandler(myTask_Done);

                // Write data to buffer
                AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(myTask.Stream);

                writer.WriteMultiSample(false, fGen.Data);               
              
                // Start writing data
                myTask.Start();

 

But I get the following error:

 

name444_0-1652967412366.png

 

Could someone help me with this?

 

Thanks!

 

 

 

0 Kudos
Message 1 of 3
(691 Views)

The error msg spells it out pretty thoroughly.  Your "writer" needs to be multi-channel and then you (probably) need to write a 2D array to the task.  In LabVIEW, rows are channels and columns are samples so you'd define an output array with 2 rows by N columns.  I suspect (but can't verify) that the same arrangement would hold true in C#.

 

 

-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 2 of 3
(683 Views)

I see seems I fixed it now.

0 Kudos
Message 3 of 3
(657 Views)