Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NI DAQ MAX Receiving false results from Task.CIChannels.CreateAngularEncoderChannel()

I have an NI DAQ: cDAQ9185, with two slots: NI 9361, and NI 9205. I'm trying to read data from port ctr1 of NI 9361 as a counter channel: AngularEncoderChannel. I'm using NI's C# api.

All I receive back is a stream of 0, 0.36, 0.72 in bulks (a few thousand times 0, then a few thousands more 0.36 and so on), while I'm expecting values of about 2000, constantly changing.

The physical wiring are fine. I ran the code from the angular encoder example, and it works good. I changed all my Task configurations to be as similar as possible to the example, but it still does not work.

My Code:

protected ConcurrentQueue<Sample[]> _exportingQueue;
public double SampleRate { get; set; }
public NITask.Task Task { get; protected set; }
public long SampleCounter { get; set; }
private string _cPort = "cDAQ9185-1E7661EMod1/ctr1";
private NITask.CounterMultiChannelReader _reader;

public void InitializeTask()
            {
                Task = new NITask.Task(); 
NITask.CICountEdgesActiveEdge.Rising, 0, NITask.CICountEdgesCountDirection.Up);
Task.CIChannels.CreateAngularEncoderChannel(_cPort, "", NITask.CIEncoderDecodingType.X1, false, 0, NITask.CIEncoderZIndexPhase.AHighBHigh, 24, 0.0, NITask.CIAngularEncoderUnits.Degrees);

                Task.Timing.ConfigureSampleClock("", SampleRate, NITask.SampleClockActiveEdge.Rising,
                    NITask.SampleQuantityMode.ContinuousSamples, 1000);
    
                // Create a variable of type CountReader which will read the task's Stream property.
                _reader = new NITask.CounterSingleChannelReader(Task.Stream);
            }

        protected override void ReadData()
        {
            double readerData = _reader.ReadSingleSampleDouble();
            Sample[] singleSample = new Sample[1];
            singleSample[0] = new Sample(readerData, SampleCounter);
            _exportingQueue.Enqueue(singleSample);

            SampleCounter++;
        }

The Sample object, and the _exporterQueue are not critical for the actual function of this program. I'm keeping them here just in case they're surprisingly related nonetheless. Sample is an object with a {double Data, and int SampleCounter}, and the _exportingQueue is a queue which stores the samples and dequeues them through another thread. Also I have an alias for the Task object of NI as NITask, just because I'm working with threads, so that the two Task objects won't clash.

 

I hope the question is clear enough.

 

Thank you very much!

0 Kudos
Message 1 of 1
(1,306 Views)