Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Single End Analog Input

Solved!
Go to solution

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
    }

 

 

Single-End.png

0 Kudos
Message 1 of 6
(6,215 Views)

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

 

 

0 Kudos
Message 2 of 6
(6,192 Views)

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

0 Kudos
Message 3 of 6
(6,181 Views)

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?

0 Kudos
Message 4 of 6
(6,175 Views)
Solution
Accepted by topic author mrm8863

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

Message 5 of 6
(6,156 Views)

This is exactly what I was looking for, thank you.

0 Kudos
Message 6 of 6
(6,151 Views)