05-19-2022 08:38 AM
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:
Could someone help me with this?
Thanks!
05-19-2022 08:54 AM
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
05-19-2022 11:52 AM
I see seems I fixed it now.