LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code running extremely slow

I am working on a code that takes inputs from the NI DAQ. It runs extremely slow when taking in approximately 30 inputs, but works fine when taking in 3 inputs. I was wondering if this was a problem with the efficiency of the code or the hardware I am running it on (Core i5, 2GB Ram and WinXP).

Any insights will be appreciated.

 

Sincerely,

Sagar Bansal 

0 Kudos
Message 1 of 5
(2,672 Views)

From just looking at the size of the VI, I know to expect an enormous piece of code...

You have a massive amount of copy-pasted code which would benefit from a for loop.

You are creating and destroying new connections to each DAQ channel each iteration.

I cannot find a wait function, so your code is running maxed out, and hogging all system resources.

 

Create a single DAQ task, and add channels before the main loop so that the main loop is just reading data.

Add a wait VI.

_____________________________
- Cheers, Ed
Message 2 of 5
(2,665 Views)

Problem 1:  A lot of duplicated code.  Duplicated code should be placed in a subVI and the subVI reused.  It may even be possible to combine similar operations into For Loops where you loop over an array to repetitively do the same things to different pieces of data.

 

Problem 2:  A lot of Express VI's.  Express VI's make it easier to start a program, but they have some additional overhead that doesn't exist if you used lower level functions.

 

Problem 3:  A lot of File writing in the loop.  Writing data to a file is slower than execution of a program in CPU.  With the multiple file writes going on, they are all going to compete for the same resources thus compounding the problem.  You should use a producer/consumer archtitecture to pass the data to another loop that does the file writing by way of a queue.  That will allow the producer loop to run faster.  However, if the producer loop runs faster than the consumer can use the data, you will eventually run into problems.

 

Problem 4:  You are creating a new DAQ task on every iteration of your loop.  You never close a task.  And you are doing this for multiple channels.  Tasks should be created before the loop, used in a loop, and closed out after the loop is finished.  Creating tasks takes time,  and by creating them without closing them repetitively, you are eventually going to run out of resources and crash the computer.  The numerous tasks should all be combined into a single task.

 

Problem 5:  What is the purpose of the Collector Express VI's that are set to collect a single sample?

 

More ...  ?

Message 3 of 5
(2,664 Views)

Thank you all for your inputs. I will modify my code accordingly and post it

0 Kudos
Message 4 of 5
(2,625 Views)

I am rewriting the code using the DAQ assistant. Would be awesome if anyone of you could take a look at it to see if I am doing it correctly.

 

Sagar

0 Kudos
Message 5 of 5
(2,616 Views)