05-16-2024 01:09 PM
Hi all,
I am trying to run a code here in which the code on tab number 3 should keep on running repeatedly. What it does is it copies an image from the path I give, renames it and then stores it at given location. A MATLAB exe which I have created runs in background which has NO Connection to LabVIEW to predict if the data in an image is positive or negative. But when I keep this code on tab 3 in a loop, all the buttons stop responding and the program just hangs. I can't do anything except force closing LabVIEW from task manager. Outer loop is because I want program to run continuously until I press Stop button which shuts down the system of the client. But this button does not work after I click OK button on tab 3. After clicking OK button entire program hangs, only the text fields of results work. How do I get around this? Attaching the screenshot of the code as the file size for VI is around 70 MB for version 19. If you see in the screenshot, if I keep that inside code in a loop it hangs obviously because loops can't stop executing
05-16-2024 01:51 PM
You know, of course, that once you enter the While Loop, the Stop button will be useless (if it was False when you enter the While Loop, it's "false" value will be remembered until the loop stops "some other way".
The "usual" way to get the Stop button to stop an Event Structure is to create a "Value Change" Event, put the Stop button "inside" that case, wire its value out the lower-right corner of the Event Loop to where the Stop Indicator normally is for a While Loop, and you're done.
Run your program. If Stop was initially False, when you push it, it will go to "True", trigger a Value-Change, enter the Event Loop where its "True" value will be read, and will stop the While Loop holding the Event Structure.
Once you see that, do one more experiment and (for 50 points extra, explain why) --
Run the program again, but before running it, push the Stop button (which should go to "True". Run the program. Did it Stop? If not, push the Stop button again. Did it Stop? If not, push the Stop button again. Now explain what's going on here ...
Bob Schor
05-16-2024 03:10 PM
You might not know this yet, but images are pretty useless because we cannot see most of the code. To get specific help, attach your VI instead. (we cannot see what's in the other event cases, the mechanical action settings, or even how the visible event is configured)
As Bob already pointed out, your code is highly flawed due to a complete misunderstanding of dataflow principles. You might want to start with the learning resources listed at the top of the forum.
The word "continuously" is very vague and can mean many things. If you want to something to run continuously, you don't want an event structure at all. (I would even recommend to not use an event structure until you learn the basics), just spin the loop at a reasonable rate while also polling the other controls and react accordingly.
05-17-2024 09:13 AM
Thanks for answering my query Alten and Bob. Attaching the 2019 VI version. It had a custom background before which increased size of CI to 80MB. So I removed it. Now if you see here, the code on tab 3 should run continuously. As soon as the image is replaced with another, the result should be reflected. That is the reason to put the while loop. The outer while loop is there to keep the entire program running. Without the outer loop, when I click login button on tab 1, the program stops running. Running program continuously without outer loop is also creating problem that inner tab 3 while loop is still running to make program actively scan for those txt file changes and reflect results immediately.
05-17-2024 10:16 AM
@shreyaskarnad wrote:
Thanks for answering my query Alten and Bob. Attaching the 2019 VI version. It had a custom background before which increased size of CI to 80MB. So I removed it. Now if you see here, the code on tab 3 should run continuously. As soon as the image is replaced with another, the result should be reflected. That is the reason to put the while loop. The outer while loop is there to keep the entire program running. Without the outer loop, when I click login button on tab 1, the program stops running. Running program continuously without outer loop is also creating problem that inner tab 3 while loop is still running to make program actively scan for those txt file changes and reflect results immediately.
Your (invisible) tab is on the front panel. There is no code on front panel objects. Front panel objects do not run code.
The controls on tab "Page 3" have terminals in case [2] of your event structure. The code there makes no sense. When "OK Button 2" is clicked, case [2] will run. The loop inside that case is an infinite loop, so case [2] will never finish and no other cases will ever run. You've also got your outer loop as an infinite loop, which you shouldn't do.
A state machine architecture would be appropriate here.
05-17-2024 10:42 AM
@paul_a_cardinale wrote:
A state machine architecture would be appropriate here.
Here's a good tutorial to get you started: Application Design Patterns: State Machines - NI
05-18-2024 03:33 AM
Just a blunt question. Is there any way by which the code in the event of OK button value change can run repeatedly without usage of the loop? So that the buttons can still be pressed? Because I can run entire program repeatedly by pressing the run continuously, so the outer loop is eliminated. But the inner loop is simply blocking the use of all the buttons which is frustrating!
05-18-2024 10:13 AM
Hey everyone, so finally I tackled the issue. In the case structure, defer user inputs was ticked. I unticked it and now the program works like a charm. I also removed the inner for loop and added a feedback node which made it faster. Thank you so much all!
05-18-2024 10:22 AM
@shreyaskarnad wrote:
Just a blunt question. Is there any way by which the code in the event of OK button value change can run repeatedly without usage of the loop? So that the buttons can still be pressed? Because I can run entire program repeatedly by pressing the run continuously, so the outer loop is eliminated. But the inner loop is simply blocking the use of all the buttons which is frustrating!
When an event structure executes:
At that point, the event structure is finished running.
The only way that an event structure, or any other object on the block diagram, can run more than once, is to be in a loop.
05-18-2024 10:58 AM
@shreyaskarnad wrote:
Hey everyone, so finally I tackled the issue. In the case structure, defer user inputs was ticked. I unticked it and now the program works like a charm. I also removed the inner for loop and added a feedback node which made it faster. Thank you so much all!
You are not making any sense.
I strongly believe that whatever you did is not reasonable and you are just digging yourself into a deeper hole, but unless you show us the fix, we cannot help.