09-05-2013 03:59 PM
I am trying to read a voltage using an analog input on a NI USB-6008 in C#. I have tried using a Differential and it worked, however, I am constrained and would prefer to use Single-End to read the voltage. However, when I create an instance of an AnalogSingleChannelReader with a Terminal Coniguration of any type other than Differential, it still operates like a Differential. Any ideas as to why this isn't working? And yes, I do know that the Terminal Configuration currently is configured for a Differential in the code.
public class AnalogInput
{
#region Import Dlls
[DllImport("NationalInstruments.Common.dll")]
static extern void Import1();
[DllImport("NationalInstruments.Common.Native.dll")]
static extern void Import2();
[DllImport("NationalInstruments.DAQmx.dll")]
static extern void Import3();
#endregion
#region Private Fields
Task oTask = new Task();
string ChannelString = "";
#endregion
#region Constructor
public AnalogInput(AnalogInputChannels Channel)
{
ParseInputChannel(Channel);
oTask.AIChannels.CreateVoltageChannel(ChannelString, "Channel", AITerminalConfiguration.Differential, 0, 10, AIVoltageUnits.Volts);
}
#endregion
#region Public Methods
public double Read()
{
AnalogSingleChannelReader oReader = new AnalogSingleChannelReader(oTask.Stream);
double Data = oReader.ReadSingleSample();
return Data;
}
#endregion
#region Private Methods
void ParseInputChannel(AnalogInputChannels Channel)
{
switch (Channel)
{
case AnalogInputChannels.In0:
ChannelString = "Dev1/ai0";
break;
case AnalogInputChannels.In1:
ChannelString = "Dev1/ai1";
break;
case AnalogInputChannels.In2:
ChannelString = "Dev1/ai2";
break;
case AnalogInputChannels.In3:
ChannelString = "Dev1/ai3";
break;
case AnalogInputChannels.In4:
ChannelString = "Dev1/ai4";
break;
case AnalogInputChannels.In5:
ChannelString = "Dev1/ai5";
break;
case AnalogInputChannels.In6:
ChannelString = "Dev1/ai6";
break;
case AnalogInputChannels.In7:
ChannelString = "Dev1/ai7";
break;
}
}
#endregion
}
Solved! Go to Solution.
09-06-2013 05:30 PM
Hello,
How are you calling the other terminal configurations? Here is a help file for DAQmx terminal configuration types in C#:
http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/40de8e46/
-Erik S
09-07-2013 10:22 AM
Sorry about the clarity, I am calling these in the Constructor:
oTask.AIChannels.CreateVoltageChannel(ChannelString, "Channel", AITerminalConfiguration.Differential, 0, 10, AIVoltageUnits.Volts); oTask.AIChannels.CreateVoltageChannel(ChannelString, "Channel", AITerminalConfiguration.Nrse, 0, 10, AIVoltageUnits.Volts); oTask.AIChannels.CreateVoltageChannel(ChannelString, "Channel", AITerminalConfiguration.Pseudodifferential, 0, 10, AIVoltageUnits.Volts); oTask.AIChannels.CreateVoltageChannel(ChannelString, "Channel", AITerminalConfiguration.Rse, 0, 10, AIVoltageUnits.Volts);
I have looked through the help file for the AITerminalConfiguration enumerator before, but thanks for the link. Unfortunately I have tried each of the configurations, and they all seem to act the same way: as a Differential. My overall goal is to match the schematic in my first post.
Also, I am planning on using this class (code in first post) to read the input repeatedly on the interval of a timer. Would there be any performance benefits to using a different method? And if so, what method?
Thank you
09-07-2013 09:14 PM
Update: I am able to read the correct voltage via Referenced Single End. However, with the voltage source is removed (3V) and it is tied to ground with a 1Mohm resistor, it floats around 1.2 V. Without the voltage source or resistor tieing it to ground, it floats at 1.4 V. Any idea why it is not steady at 0 V?
09-09-2013 02:07 PM
Hello,
The USB 6008 can only read differential or RSE, so that would explain why the other configurations would not work. I am happy to hear that the RSE configuration is working properly now. The floating voltage of 1.4 V is expected when there is no source connected to the device due to the circuitry of the 6008. Here is a KB that discusses this behavior in more detail:
http://digital.ni.com/public.nsf/allkb/C7E181E51E4299FC862570A700604141?OpenDocument
-Erik S
09-09-2013 03:01 PM
This is exactly what I was looking for, thank you.