LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem closing a while loop - Boolean switch stuck

Solved!
Go to solution

Hello everyone!

 

First of all, I wanted to apologize for my lack of knowledge, but I'm new to LabVIEW. Within a larger VI, there is an Event Structure that handles auxiliary tasks. In this specific case, I have a small state machine that communicates with a system that turns on a device. The event is triggered by a button set to “Latch when released” control mode. (Initially, I had used a toggle switch, thinking I could turn the process on and off with it, but I was unable to do so.) In this event, there is a while loop with a shift register that manages the stages of the process. Another Boolean button is supposed to trigger the “Stop” event, as shown in the figure, but on the front panel, it gets stuck and never completes the cycle. Could someone explain what’s happening? How can I fix this? 

 

Screenshot 2026-05-18 122308.png

Screenshot 2026-05-18 122326.png

Thanks a lot

0 Kudos
Message 1 of 12
(336 Views)

Run it in Highlight mode and Retain values and it

Yamaeda_0-1779101692863.png

 

should become apparent.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 12
(321 Views)

I'm sorry to disappoint you Yamaeda, but I can't figure it out.

 

I already used the Highlighted mode but I cannot argue why the switch on the Front panel results to be stuck!

 

What the event should do is something like "switch on the device, collect data until I don't press stop". So the fact that the loop keep entering the “read” section until the button is pressed—that works fine for me, but I cannot understand why you can't press the stop button from the Front Panel. Also, the loop contains the button's local variable, not the button itself...maybe that's the issue? Don't worry about the “Boolean” button being inside the Event Structure...I only put it there to take the photos... that one is outside.

0 Kudos
Message 3 of 12
(302 Views)
Solution
Accepted by topic author gcambie88

There's a setting in the Event for "Lock front panel", that prevents you from pressing a button while it's executing and also why the general tips is to not have long running executions in an event structure.

Yamaeda_0-1779106060811.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 12
(282 Views)

Your code is inside-out. Your should eliminate the inner loops and anchor your shift registers on the toplevel loop.

 

(Since your pictures are truncated, we cannot give further advice until you post your actual VI)

0 Kudos
Message 5 of 12
(258 Views)

This may sound like a silly question, but (among other things) it points out the importance to show us "LabVIEW Code" (which means files with the extension ".vi" and not "pictures of LabVIEW Code" (.png).

  • The Front Panel (boolean) Indicators that you show in your pictures ("Boolean" and "En_Dynamic"), how do they appear on the Front Panel?  Are any of them an "oval" button?  Are any of them a "rectangular" button?

Boolean Controls have an associated "Mechanical Action" that govern when and how they change from True to False and from False to True.  They don't seem to be used in the pictures of code that you showed -- can you tell us what you want to happen when you press either of the buttons?  Can you tell us what you intend to do (using the Front Panel) to stop the loop?

 

Bob Schor

0 Kudos
Message 6 of 12
(212 Views)

many thanks! I saw this solution in other places arounf here but never thought it could fit to me!

0 Kudos
Message 7 of 12
(198 Views)

Please find a colleague (or a Professor) with LabVIEW experience, show her (or him) your code, and ask how to properly use the Event Structure to "switch" your main Loop (which should be something like a State Machine) when a "Go" or "Stop" or "Change Scale" or other Front Panel "switch" control is toggled.  Notice Yamaeda mentioned not having "long-running code" in an Event Structure, which your "solution" violates.

 

Bob Schor

0 Kudos
Message 8 of 12
(154 Views)

@gcambie88 wrote:

many thanks! I saw this solution in other places arounf here but never thought it could fit to me!


Note that changing the event setting to not lock the panel should not be needed with proper code architecture. In this case it is just a bandaid cludge masking a serious deeper problem that will bite you later. I guarantee it! You need to learn dataflow principles. (For example if you would operate other controls linked to other event cases, they will accumulate in the event queue causing unexpected behavior once the current event ends.)

 

You still have not attached your code so we can demonstrate how to do it better. Make sure to use "save for previous" (2020. or below) if you use any recent version.

Message 9 of 12
(145 Views)

The Labview version I'm using is 2025.

The problem with the .vi code is that, as i said earlier, this is just a small piece of the 8 MB project consisting of:

  • 3 main while loops: one for automatic collaudo steps, one for retrieving data from PLC and another for event handling;
  • 11 different collaudo steps interfacing with voltage/frequency converter, power meter, power supplies, safety electrical tester
  • 20 external triggers to handle

So that's why I was not sharing it...I just needed help with a stuck button, that is all, which, to be clear, is a rectangular “latched when released” mechanism button. Not to mention that, since it’s the company’s proprietary software, I’m not allowed to post everything.

 

gcambie88_0-1779261687690.png

 

 

"Note that changing the event setting to not lock the panel should not be needed with proper code architecture. In this case it is just a bandaid cludge masking a serious deeper problem that will bite you later. I guarantee it! You need to learn dataflow principles."

 

Thank you for the advice!

So...the problem is the following: there are several action to perform in an automatic way, but sometimes it would be needed to make manual commands. As you could have argued, the piece of code (as we can talk about "code"), perform only starting and stopping a device and collecting data from the power meter during the run phase. This is handled by the automatic test cycle with a set duration. However, it was necessary to provide the option to act manually. With other processes, I had solved this using a sub.vi that was called by the event handler of the event loop; however, these processes have a defined start and end without the need for start/stop buttons... so once the sub.vi finishes it is just needed to close the panel. they are essentially handled like a pop-up window. In this specific case indeed, I tried the same approach but without success... I need to investigate further, but I’m fairly certain the issue was of the same nature as the lock on the panel buttons.

If you have any REAL advice on how to make it works...please enlighten me

 

"(For example if you would operate other controls linked to other event cases, they will accumulate in the event queue causing unexpected behavior once the current event ends.)"

 

Oh my... you're so right! And what makes you think I haven't thought about this or don't know how to handle it?

 

I've noticed that asking questions on this forum is a double-edged sword... many people are annoyed, almost irritated, when answering, and often don't even offer a solution, as if it were their duty and perfectly acceptable to be dismissive rather than genuinely helpful or understanding.

Generally, before judging someone, I look at the context, find out their reasons, and think things through before speaking up. Not everyone has to be an expert in a particular field... maybe they find themselves doing something they haven’t even studied. I’d be curious to know how many people on this forum could answer the following question without using Google or AI: Which lepton describes the Weyl field equation?

 

Unluckily, I ended up making collaudo tests in a private company which uses only LabView for their purpose. So I don't have time, neither the will, to start learning a lot about LabView dataflow, however, I might actually be interested once my deadlines are over and I can spend some time studying through tutorials or any other available resources.
So, it would have been better if you had provided some links or advice on where to find answers to my question, or pointed me toward the right tutorial.

Thank you in any case for your help.

 

0 Kudos
Message 10 of 12
(108 Views)