Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Queueing data slowing down over time

I have written a controller in .Net using the daqmx libraries.  I have tested this on a number of daqs and it works fine except on the cDaq where I see a small cumulative slow down when queueing data (specifically using the commands 'WriteMultiSamplePort' and 'WriteMultiSample').  I am changing the timing of the tasks between some runs and each time I do the commands to queue output data take about ~1ms longer to complete.  This isn't a problem at first, but ideally my controller will be running for a long time with many different timings.

Since I only see this issue on the cDaq I am wondering if this is a known problem with this hardware and if anyone has any advice about how to deal with it.

I'd really appreciate any advice anyone can provide

Adam

0 Kudos
Message 1 of 9
(3,205 Views)

This behavior could occur because of the way the asynchronous I/O API was designed in the .NET DAQmx API. First, a little background on asynchronous I/O with DAQmx in .NET.

 

Try to use reader.SynchronizingObject = this; // "this" is a reference to the Windows Form 

 

 

0 Kudos
Message 2 of 9
(3,155 Views)

Thanks so much for your response Karias.  I'm a little confused by it however, it seems as though SynchronizingObject is now obsolete and the documentation recommends using SynchronizeCallbacks, which is set as true by default (so I believe it should be synchronizing things).  Would you still recommend I use this property?

 

0 Kudos
Message 3 of 9
(3,152 Views)

You are welcome!

I did some further research. Yes, please use SynchronizeCallbacks. I also read you should be using Thread Safe for .NET class. are you using said thread?

 

0 Kudos
Message 4 of 9
(3,140 Views)

Excellent thank you.  

Could you explain what you mean by using thread safe?  Currently I am running only in a single thread so there is no danger of conflict (If you have link to reading material that would be helpful).

If you'd like I can link my example code.

 

0 Kudos
Message 5 of 9
(3,138 Views)

Hey!

Here I leave some useful information about timing Parameters. Also please check this about further information on SynchronizeCallbacks Property. Please attach your code. This will give more context on this issue. 

Thanks!

 

0 Kudos
Message 6 of 9
(3,110 Views)

Thanks a lot for the links.

The main part of the code which is relevant is below.  It runs using two tasks, one with a single analog output channel (analogOutputTask) and one with a single digital channel (digitalOutputTask).  Both of these are running on their internal clocks and I am just changing the number of samples per run in the timing to account for the different signals queued.

 

            // performing runs
            for (int runCounter = 0; runCounter < numberOfRuns; runCounter++)
            {
                //setup first timing 
                timer.Reset();
                analogOutputTask.Timing.SamplesPerChannel = analogSignals.Length;
                digitalOutputTask.Timing.SamplesPerChannel = digitalSignals.Length;
                timer.Start();
                digitalWriter.WriteMultiSamplePort(false, digitalSignals);
                analogWriter.WriteMultiSample(false, analogSignals);
                timer.Stop();
                bigQueueTimings[runCounter] = timer.ElapsedMilliseconds;
                Console.WriteLine(bigQueueTimings[runCounter].ToString());

                // run out those signals
                digitalOutputTask.Start();
                analogOutputTask.Start();
                while(!analogOutputTask.IsDone || !digitalOutputTask.IsDone)
                {
                    System.Threading.Thread.Sleep(2);
                }
                digitalOutputTask.Stop();
                analogOutputTask.Stop();

                //setup second timing
                timer.Reset();
                analogOutputTask.Timing.SamplesPerChannel = smallerAnalogSignals.Length;
                digitalOutputTask.Timing.SamplesPerChannel = smallerDigitalSignals.Length;
                timer.Start();
                digitalWriter.WriteMultiSamplePort(false, smallerDigitalSignals);
                analogWriter.WriteMultiSample(false, smallerAnalogSignals);
                timer.Stop();
                smallQueueTimings[runCounter] = timer.ElapsedMilliseconds;
                Console.WriteLine(smallQueueTimings[runCounter].ToString());

                // run out those signals
                digitalOutputTask.Start();
                analogOutputTask.Start();
                while (!analogOutputTask.IsDone || !digitalOutputTask.IsDone)
                {
                    System.Threading.Thread.Sleep(2);
                }
                digitalOutputTask.Stop();
                analogOutputTask.Stop();
            }

 

The signals are equivalent for both tasks (i.e. digitalSignals and analogSignals are the same length).  If the two sets of signals are the same length for each task (i.e. digitalSignals and smallerDigitalSignals are the same length for the digital task) then there is no cumulative delay, but if they are different lengths then it takes about 3ms longer to queue every time I call WriteMultiSamplePort and WriteMultiSample.  I also see no delay if I run this on a different daq (a 6343) or only running on a single module of the Cdaq (i.e. only analog output or only digital output). 

Hopefully this helps.

Many thanks

0 Kudos
Message 7 of 9
(3,104 Views)

Hi,

I just wanted to check in and see if you'd had a chance to look at or run the code example I provided.

Thanks

0 Kudos
Message 8 of 9
(3,012 Views)

Hi,

I just wanted to check back in and see if you'd had a chance to look into the code at all.

Thanks a lot,

Adam

0 Kudos
Message 9 of 9
(2,925 Views)