Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

High processor usage with C# and DAQmx

Hi Tyler,

The code I use is posted above in the 2nd 2 posts for this thread.  If you would like a zip of the project, please can you tell where I can upload one to?

Regarding sampling rates:

Yes, if I drop the sampling rate, then the problem disappears, but I have to drop it to down to about 20KS/s (down from 300KS/s) before processor usage drops down to under 10%.  If I run at 24K, then I see about 25% processor usage and at 25000 I see over 50% and it stays at over 50% for all rates from 25K to 300K.

As mentioned above, I have re-written the C# code to call the C API interface using P/Invoke and get much better processor usage (i.e. 5-6% for every sampling rate I've tried up to and including 300K).

Thanks

Russell
0 Kudos
Message 11 of 21
(2,395 Views)
Russell,

You should be able to post your zip file in the Attachment Line of a forum post reply.  That was my intent when I asked you to post the code.  It would be easier for me to track down this issue with your actual code.

Thanks,

Tyler
0 Kudos
Message 12 of 21
(2,369 Views)
Here is the zip of the projects.  Sorry, hadn't noticed the 'attachment' option at the bottom of the page (was just off be web browser's viewable area).

It would be good to get to the bottom of this, as we are stuck using P/Invoke to call the C interface from C# at the moment.

Cheers

Russell
0 Kudos
Message 13 of 21
(2,364 Views)
Is there any update on this problem. I think I'm seeing a similar problem.
0 Kudos
Message 14 of 21
(2,331 Views)
Not that I've heard.  I've also passed the issue on to NI support engineers in the UK who have said that a similar issue is being looked in to by NI in the US so hopefully someone will find something out.  If I here anything through NI UK, then I'll post back here.

Cheers

Russell
0 Kudos
Message 15 of 21
(2,327 Views)

Hi Russell-

After some investigation we found that this appears to be a problem with debug mode builds in C#.NET Express 2005 with the NI-DAQmx .NET API.  By switching to a release mode build we were able to workaround the issue.  Could you please give this a try and let us know if you're not able to see better results?  We are currently looking further into the cause of the high CPU utilization, but for the timebeing this workaround should work well.

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 16 of 21
(2,255 Views)
Hi Tom,

I've just tried a release build, but see no difference in performance between release and debug builds of the test project I posted so doesn't look like this will solve the issue for us.

Thanks

Russell
0 Kudos
Message 17 of 21
(2,246 Views)

Hi Russell-

Can you please verify if the behavior persists with an NI-DAQmx shipping example for finite analog acquisition?  "C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DAQmx\Analog In\Measure Voltage\AcqVoltageSamples_IntClk\Cs" would be a good choice.

If so, please let me know exactly the build settings you are using and which configuration steps you are following and I will try again to replicate the problem on my end.

Thanks again-

Tom W
National Instruments
0 Kudos
Message 18 of 21
(2,229 Views)
I loaded the project in to VC# express 2005 and it converted the .sln (it was a vs2003 project file).  I ran both debug and release settings and see the same problem of high processor usage but only when the acquisition rate is increased.

I changed the Samples/Channel to 100000 and the acquisition rate to 20000 and it runs at ~1% processor usage as expected.  If I up the acquisition rate to 30000 then it usage 40-50% processor usage in both release and debug builds.

Thanks

Russell
0 Kudos
Message 19 of 21
(2,224 Views)
Hi Russel

Instead of hitting f5 (or the green run arrow), try running the app by hitting Ctrl+F5 (or go to Debug >> Start Without debugging)

Let me know if you see the same problem. Hitting f5 still attaches the debugger, even if you build a release version.

Bilal Durrani
NI
0 Kudos
Message 20 of 21
(2,187 Views)