Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Slowdown over time calling WriteMultiSample with daqmx on a Cdaq

I am using daqmx through C#.  I have one task for analog output and another one for digital output.  When I send data to them if I change the number of samples sent then it takes longer to send than the time before and that effect is cumulative.  That means that after I have been running for a long time then it can end up taking several seconds.  This code below replicates the issue (I can attach the full code example if anyone needs):

            // 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();
            }

If the two sets of signals are the same length (digitalSignals and smallerDigitalSignals) 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). 

Is this a known issue?  Or is there something I should be doing to prevent this?  It looks like some sort of memory leak to me.

Thanks in advance for any help

0 Kudos
Message 1 of 19
(3,014 Views)

You told us that you dont see that behavior on the 6343 (USB or PCIe?).

In which other device have you tried this?

0 Kudos
Message 2 of 19
(2,976 Views)

It is the 6343 USB. 

Those are the only two devices I currently have access to I'm afraid so I can't verify it further.

0 Kudos
Message 3 of 19
(2,972 Views)

Only for a recap, you have two devices (6343 USB) but only in one, you have the delay? is this correct

I dont understand the part of " I also see no delay if I run this on a different daq" it is not clear to me. 

 

In case you dont have it WriteMultiSamplePort Method

0 Kudos
Message 4 of 19
(2,951 Views)

Yes that is correct, when I run this code on the 6343 USB I see no delay build up over time, but when I run it on the Cdaq this delay builds up over time (and as far as I've run there seems to be no limit to the degree to which it can build up).

Apologies for the lack of clarity.

0 Kudos
Message 5 of 19
(2,949 Views)

Thanks,

 

Pardon me! I understood you had two  USB 6343.

Which cDAQ are you using? (module and chassis)

 

The USB 6343 is an X series, with a USB device we  have high latency and low bandwidth  

0 Kudos
Message 6 of 19
(2,932 Views)

Apologies if I wasn't clear. 

The chassis I'm using is the 9178 and the modules are 9264 (for the analog output) and the 9401 (for the digital output).

Thanks

0 Kudos
Message 7 of 19
(2,916 Views)

Hi

thanks for that information.

Well,  you have different modules with different characteristics, did you double check the datasheet of the modules, sample rates, characteristics?

 

the NI-9201 has a Maximum signal switching frequency, per channel

This is the manual for the X series this is a multifunction device.

 

 

0 Kudos
Message 8 of 19
(2,909 Views)

I have checked the datasheet but I'm not sure what I would be looking for exactly perhaps you could offer some advice. 

The modules are running at the correct rate (and I am running well below their maximum) and I am not queueing a particularly large amount of data, but queueing data takes longer each time I do it with a different number of signals.  I have found that if I delete both of the tasks involved and re-create them then the timing resets back to what it was before it started to build up.

To me this looks like a software issue where some buffer internal to the daqmx library is not being cleared correctly, but it is very difficult for me to tell.  

0 Kudos
Message 9 of 19
(2,900 Views)

Another question did you write your code from scratch? or did you use one of the codes that are shipped with DAQmx   I think the best approach always is to start with an example and modified it 

Are you using Visual Studio?

let me double check everything

0 Kudos
Message 10 of 19
(2,891 Views)