LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed Loop stops respoding

Solved!
Go to solution

If i shouldn't use event structures, timed loops or for/while loops to do DB communication, what do you suggest? The database communication is currently made with a state machine, i'm just sending instructions to it with event structures (in this case).

0 Kudos
Message 11 of 16
(802 Views)

You can do those things inside of loops. What you don't want to do is jam everything into your time critical loops. Also, code within an event structure should never take more than 10s of milliseconds to execute. If you have long running code in your event structe than it becomes unresponsive. Specifically this if for event structures that are handling UI stuff. If the event structure is purely handling user events generated by your code, it may be OK if the action within an event case takes a little longer to process.

 

What everyone is proposing is that you limit your time critical loops to only handle the time critical aspects of your application. If you have to log data in the DB, your timed loop should post that data to a queue or notifier or some other type of interprocess communication so that a separate task with get that data and act on it. This way your time critical code can operate at the spped/frequency it must while slower tasks like logging to a file or a DB do not impact your performance. those operations are handled in DIFFERENT loops/state machines.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 12 of 16
(792 Views)

Thank you all for your help.

 

It was indeed the while loop searching for the FracID = 8 that was the problem. When i changed something in the event loop, it affected the ProtocolDetails variable in such a way, that if ProtocolDetails didn't update before the loop started comparing, all the FracID values were 0 and thus the loop went to infinity, stalling the program.

 

I want to thank you again for all the great tips you've given me. I'll try to do better in the future 🙂

0 Kudos
Message 13 of 16
(769 Views)

@AeroSoul wrote:

It was indeed the while loop searching for the FracID = 8 that was the problem. When i changed something in the event loop, it affected the ProtocolDetails variable in such a way, that if ProtocolDetails didn't update before the loop started comparing, all the FracID values were 0 and thus the loop went to infinity, stalling the program.

 

I want to thank you again for all the great tips you've given me. I'll try to do better in the future 🙂


Your loop will also never stop if the input array is empty. Maybe that's what was the case. For an experienced programmer, that loop immediately raises a lot of red flags.

 

Fortunately, there are much simpler AND safer alternatives. For example if you would autoindex on a FOR loop with conditional terminal, the loop is guaranteed to terminate once you run out of array elements. The boolean will tell you if a match was found or not, so you can substitute a sentinel value (e.g. -1) if that's the case. (Of course if it is a plain array, i.e. elements are not clusters, a simple "search array" would do the same).

 

 

altenbach_0-1612199264169.png

 

 

0 Kudos
Message 14 of 16
(746 Views)

@AeroSoul wrote:

But it was this large before and it worked fine. Also event structure still works fine, but the timed loop fails, even if i wait for the event to end. Or if i don't even trigger an event when entering the VI.


Taped on my cubicle wall is a set of translations.  One of them is “But it works.”  =  “I know it’s crap, but I don’t care.”

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 15 of 16
(729 Views)

The problem with that is that while FracID 8 signifies "END" fraction... it's not the last one, it goes up to 12 (previous coder hastily patched up lack of fractions when new protocols came out).

EDIT:

What i ended up doing was that same while loop with a condition to terminate after 13 loops (i guess i could do for loop, now that i think about it, i misread your code...) and moved the loop to event handling instead of having it in timed loop, so it only executed once when protocol changed.

 

@paul_cardinale

Maybe i should put up those translations as well... 😄

0 Kudos
Message 16 of 16
(717 Views)