03-14-2018 04:51 PM
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
03-16-2018 09:58 AM
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
03-16-2018 11:22 AM
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?
03-16-2018 05:03 PM
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?
03-16-2018 05:18 PM
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.
03-19-2018 03:56 PM
03-19-2018 04:43 PM
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
03-30-2018 02:24 PM
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
04-19-2018 10:19 AM
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