07-10-2012 04:57 PM
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();
}
Solved! Go to Solution.
07-11-2012 07:42 AM
try adding
//Verify the Task analogInTask.Control(TaskAction.Verify); //before //double analogDataIn = reader.ReadSingleSample();
Curt
07-11-2012 09:04 AM
07-11-2012 09:05 AM
As seen in the image above, even after adding the code to verify task. Analog input still shows a random value.
07-11-2012 09:59 AM
Hi,
I built an app using your code (with task.verify) and it worked just fine.
Have you tried different input/output channels?
Curt
07-11-2012 10:34 AM
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.