03-29-2022 10:32 AM
Hello All,
My name is gil and I have a problem.
I have customer specifications that force me to use event case and a while loop uner the same parent while loop
The codes must work in such a way: the while loop is connected after the event case so after the event case has reached the "Timeout" event, the next loop will statr working until it is stopped and then again to the event structure.
- as can be seen in file1.
The reason behind this is that the coustomre has already built events that both update the GUI and communicate with the hardware.
I have tested this configuration seperatly and It works rather well.
When implementing this code in the version. all of the controls become unresponsive and I cannot do anything.
I have placed a probe on the index of while that runs after the the event case, And I can see the number of itteration is growing, i.e. the program is running.
I cannot attached the original code due to proprietary issues. but I have attached a code the mimics the logic.
Can anyone please tell me why the system become unresponsive?
Thanks!
Gil,
03-29-2022 10:44 AM
Apply LabVIEW dataflow basics here: "A node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution."
A structure is a node. If the while loop that comes after the event structure has not finished, how is the event structure supposed to service any events?
03-29-2022 10:45 AM - edited 03-29-2022 11:07 AM
Make sense! Think dataflow!
The outer loop cannot go to the next iteration until everything in it has completed, so if you press stop2, stop will still be false, thus reentering the inner loop. You need to press stop, then stop 2 to complete the code.
I assume that you have other events, such as value change for some of the booleans. Most likely these events are set to "lock the panel until the event completes", but the event can never complete while the code is inside the inner loop and pressing "stop 2" will not be seen if that happens.
@gilmaor1 wrote:
I have customer specifications that force me to use event case and a while loop uner the same parent while loop
Your customer is clueless. If he thinks he is so smart, why does he ask you to do the coding? I see serious architectural problems in the current design. I would just refuse to work for that customer unless he agrees on a better architecture.
03-29-2022 11:13 AM
Are you really *sure* that your customer insists on that kind of code structure? It's a bad one, for exactly the reasons you're experiencing. The inner While loop prevents normal responsive GUI event processing.
A much more typical approach would make that loop run in parallel to the event handling loop. And it would then add some kind of messaging scheme where the event loop "commands" the parallel loop to do things at the appropriate time. You can still have the timeout case *initiate* action in the parallel loop, but this way you don't get stuck waiting for the action to complete. (Of course, you still need to consider and manage the possibility of queuing up a whole series of actions for the parallel loop while it's still busy working on the first one...)
-Kevin P
03-29-2022 11:29 AM
@altenbach wrote:
Make sense! Think dataflow!
The outer loop cannot go to the next iteration until everything in it has completed, so if you press stop2, stop will still be false, thus reentering the inner loop. You need to press stop, then stop 2 to complete the code.
I assume that you have other events, such as value change for some of the booleans. Most likely these events are set to "lock the panel until the event completes", but the event can never complete while the code is inside the inner loop and pressing "stop 2" will not be seen if that happens.
@gilmaor1 wrote:
I have customer specifications that force me to use event case and a while loop uner the same parent while loop
Your customer is clueless. If he thinks he is so smart, why does he ask you to do the coding? I see serious architectural problems in the current design. I would just refuse to work for that customer unless he agrees on a better architecture.
Not to sound too harsh but the OP needs some serious training before they should be contracting their LabVIEW services out.
03-29-2022 01:07 PM
@Mark_Yedinak wrote:
Not to sound too harsh but the OP needs some serious training before they should be contracting their LabVIEW services out.
Agreed!
(I did not want to focus too strongly on terminology ("customer" etc.). Could be a K-12 student that got some poor code from the teacher, an undergraduate forced to extend code from a previous undergraduate, etc. 😄 )
03-29-2022 01:20 PM - edited 03-29-2022 01:22 PM
Why not create an action engine? A while loop that contains a case structure with a queue of values wired in. Create a nothing value in the case via your queue and in that case place an event structure that handles the necessary Booleans. Not knowing the root of your programming needs, I think this would benefit you in cleaning up your diagram and controlling rampant cpu usage. Below is a snippet of an action engine from an old project of mine. Hopefully this can help.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-30-2022 03:37 AM
Thanks for the advices.
For the time being I have circumvent the problem by removing the by uncheking the lock panel option. now I have to find the problematic event.
Gil,
03-30-2022 09:45 AM
@gilmaor1 wrote:
For the time being I have circumvent the problem by removing the by uncheking the lock panel option. now I have to find the problematic event.
Gil,
You don't have a problematic event, but a problematic architecture!
03-30-2022 10:06 AM
I Know.
What did, Is to remove all inner loop. and create case structure, where I control the their indexes.. and thus I creating "Loops" and loops within loops.
Thanks!