LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running a code segment continuously

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

shreyaskarnad_1-1715882921303.png

 

0 Kudos
Message 1 of 12
(526 Views)

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

0 Kudos
Message 2 of 12
(511 Views)

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.

0 Kudos
Message 3 of 12
(486 Views)

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.

0 Kudos
Message 4 of 12
(445 Views)

@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.

0 Kudos
Message 5 of 12
(431 Views)

@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

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 6 of 12
(424 Views)

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!

0 Kudos
Message 7 of 12
(403 Views)

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!

0 Kudos
Message 8 of 12
(385 Views)

@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:

  1. It waits for an event.
  2. When the event happens, the case for that event runs (one time).

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.

 

  • In general, there should never be a loop inside an event case.
  • The Run Continuously button is intended for debugging purposes.  It should not be used as part of normal operation.
  • Learn how to code the various software design patterns.
  • For this application, I recommend a state machine.
0 Kudos
Message 9 of 12
(382 Views)

@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.

 

  • Can you explain where you found an option for "defer user inputs" for case structures? You have several inner case structures and they don't do anything critical..
  • A feedback node has nothing to do with speed. There are infinite ways to place and wire a feedback node, so we still have no idea what you did.
  • A typical program should run at a defined speed, independent of hardware. "faster is better" only applies to math algorithms. How do you measure "speed"? Even e.g. a PID control should run at a define speed and not full bore.
  • Shutting down the computer to end the program is not useful during program development.

 

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.

0 Kudos
Message 10 of 12
(374 Views)