LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can I make vi run faster?

Solved!
Go to solution

@altenbach wrote:

OTOH, a huge diagram acts like a parachute. 😄


Can make you feel safe, but requires skill to operate properly and probably better avoided in all but emergencies?


GCentral
0 Kudos
Message 11 of 37
(1,127 Views)

@cbutcher wrote:

@paul_cardinale wrote:


I though Galileo debunked that idea,


Somebody's never dropped a feather and a brick outside of a vacuum...


That's why when making a "one liner", you should always leave lots of empty space between everything, covering at least 6 screen: to change the surface/mass ratio.

0 Kudos
Message 12 of 37
(1,118 Views)

hi ,

thank You everyone .

my probleme is when i add Event Structure to the While Loop  to  stop the execution  when i close the front panel window . the program is  running to slow . i want to know why ? and how i solve the probleme ? 

i didn't face the probleme when i use only a button to stop the While Loop .

Database table :

Capture.PNG

 

 if you like my code (Kudos are Welcome ).

0 Kudos
Message 13 of 37
(1,114 Views)

The event structure will wait until it receives an event. So the other code will run and then nothing will happen until an event occurs that the event structure handles.

 

Put the "search" code inside an event for that button's Value changed event together with the ID index-search code. And that DB code that gets the IDs, do you really need that in the loop or just once before the loop? If you need to update it, then either do it in the event timeout or using a button and event for it. And now you will have no code left outside the event structure and everything will work.

Certified LabVIEW Architect
Message 14 of 37
(1,107 Views)

The event structure will stall the while loop until an event happens.

 

A quick and dirty fix would be to add a time out to the event structure (a number to the Event Timeout, default is -1, never time out). That will probably cause other problems, as the event executes first thing, and then does noting until the next cycle...

 

You're mixing techniques here (pooling here, events there), and that works really poorly.

 

The loop on the left polls the string. This will, BTW, bring one CPU to it's knees. At least put a wait in there. Even better, use the event structure for it!

 

So, the event structure will also wait for a value change on the string, then do the "changed string" stuff. E.g. execute the DB queries. The other events can stay as they are.

0 Kudos
Message 15 of 37
(1,105 Views)

A few questions/comments:

 

1. Does the code to populate the ID strings need to run every time or just when you start the program?

2. There are no guarantees that the ID strings will be populated before you read them for your search. This could lead to unpredictable results.

3. Your search loop can be replaced with Search 1D Array from the array pallette.

4. As has already been noted you should put a timeout on the event structure. Alternately you could put the other code in a separate loop. I have attached a vi showing what that might look like. I assumed that the code to populate the ID strings only needs to run once.

5. I added a small wait inside the case structure. The CPU will run wide open most of the time without the wait. 

6. I would also consider using a queued message handler approach so that the Search button could be an event instead of polled.

 

Message 16 of 37
(1,094 Views)

7. Don't call your VI "Untitled n.vi" (n being a number).

0 Kudos
Message 17 of 37
(1,087 Views)

wiebe@CARYA wrote:

7. Don't call your VI "Untitled n.vi" (n being a number).


Agreed. 🙂

0 Kudos
Message 18 of 37
(1,082 Views)

@johntrich1971 wrote:

wiebe@CARYA wrote:

7. Don't call your VI "Untitled n.vi" (n being a number).


Agreed. 🙂


It won't make the VI run faster, but might very well speed up development.

Message 19 of 37
(1,076 Views)

So, this has nothing to with speed after all, just with temporary deadlocks due to poor programming.

 

OK, you need one while loop and one event structure with two or three event cases:

 

  • Home button: value change
  • Panel close?
  • Search button: value changed

How often does the database change? (1) Either it does not change, then you need to read the IDs only once or (2) I can change, then the index of the IDs may no longer correspond tot he entries you read later inside the case structure. The database seems quite small. Couldn't you real all fields (ID, Name, brand, etc) once before the loop and place into a 2D string array and the ID in the selector (I would prefer a ring instead of a combobox!) Do an event for the ring value change and use the value directly to index into the string array.

 

Do you really need to find all IDs with every iteration of the loop?

Message 20 of 37
(1,051 Views)