ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with performing a basic loopback test with NI-6008

Solved!
Go to solution

I have recently started using DAQmx in C# .NET 4.0 with NI-6008 USB DAQ. I tried out a loopback test by connecting an analog output to an analog input and tried readign the signal sent from the output to input but was not successful in sending the signal ( or maybe a problem with the code). The readign from analog input reads a random value rather than the value entered by user for the output. I connected ao0 and ai3 on the DAQ. here is the code.

 

private void button1_Click(object sender, EventArgs e)

{           

Task analogOutTask = newTask();

 AOChannel myAOChannel = analogOutTask.AOChannels.CreateVoltageChannel("Dev1/ao0", "myAOChannel", 0, 5, AOVoltageUnits.Volts);

 AnalogSingleChannelWriter writer = newAnalogSingleChannelWriter(analogOutTask.Stream);

 double analogDataOut;

 analogDataOut = Convert.ToDouble(AnalogOut.Text);

 writer.WriteSingleSample(true, analogDataOut);

  }

       

private void button2_Click(object sender, EventArgs e)

 {

           Task analogInTask = newTask();

           AIChannel myAIChannel = analogInTask.AIChannels.CreateVoltageChannel("Dev1/ai3", "myAIChannel", AITerminalConfiguration.Differential, 0, 5, AIVoltageUnits.Volts);

           AnalogSingleChannelReader reader = newAnalogSingleChannelReader(analogInTask.Stream);

           double analogDataIn = reader.ReadSingleSample();

           AnalogIn.Text = analogDataIn.ToString();

}

0 Kudos
Message 1 of 6
(5,711 Views)

try adding

 

//Verify the Task
analogInTask.Control(TaskAction.Verify);

//before
//double analogDataIn = reader.ReadSingleSample();

 

 

Curt

0 Kudos
Message 2 of 6
(5,707 Views)

Code and form view

0 Kudos
Message 3 of 6
(5,703 Views)

As seen in the image above, even after adding the code to verify task. Analog input still shows a random value.

0 Kudos
Message 4 of 6
(5,702 Views)
Solution
Accepted by topic author ranjith_poladi

Hi,

 

I built an app using your code (with task.verify) and it worked just fine.

Have you tried different input/output channels?

 

InOut.JPG

 

Curt

 

 

0 Kudos
Message 5 of 6
(5,700 Views)

 

Hi Curt,

 

The problem was with my wiring. I didn't connect the ai3 '-' to the output ground.

 

I got the right result after doing that.

 

Thanks for your help.

0 Kudos
Message 6 of 6
(5,696 Views)