1

I have an NI DAQ: cDAQ9185-1E7661EMod1, and I'm trying to read it's data from port ctr1 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!

  • Using NIMax check the configuration to see if you are reading correct channel. Either the card is not started or you are reading wrong channel. I do not think you will get a better answer from this site. Probably better to talk to a NI specialist. I use similar cards at work but do not write the software. – jdweng Jul 16 '20 at 18:15
  • Thank you for the fast response. I did check those things you mentioned before, so I will try to ask this question in the NI forums, that's a good suggestion, thanks. –  Jul 20 '20 at 09:46
  • What RIO card and A/D are you using? Are there any LEDs on card? Are you using an external Power Supply or just internal? Make sure the service is started. The service can be set to start when PC is started or manually. Check Event Viewer for Errors. – jdweng Jul 20 '20 at 10:03
  • If I'm not mistaking with the terms, the RIO card is: CDAQ9185, I have an NI 9361 8-ch counter input C series modle (which i'm having issues with), and NI 9205 with DSUB 32-ch +/-10v 16 analog input. I don't have the answers for the other questions at the moment, since the device is in a remote place, I will be able to check those in a few days, as well as checking the errors. But I can tell from Thursday when I was working with it, that the output was good when I used NI's example code. Therefore I doubt that the problem has something to do with power supply or the device being started. –  Jul 20 '20 at 12:49
  • The RIO card is only used if you have a Analog A/D converter card. The 9185 is the PIC chassis. Normally when you buy a system from NI they supply a configuration file and install the modules into the PIC. So all you have to do is turn on. Everything is pretested at the factory. The configuration file is in the root folder (I forget the extension name) and is the newest file(s) in the c:\folder. Did you get a disk with the system? Your c# program has to use same slots as the factory setup. You can open NI-Max to see the slots. They are also in the config files in the root folder. – jdweng Jul 20 '20 at 13:20

0 Answers0