LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help restructuring subVI with internal While Loop in a state machine

Hi, I’m working on a LabVIEW project and need guidance on restructuring a subVI that contains an internal While Loop with shift registers and Case Structures. My goal is to call this subVI only once from a specific state in the main VI’s state machine, without blocking the main loop. All inputs to the subVI come from variables that feed the Case Structure in the main VI for that specific state. The joystick button mentioned in the subVI is just a simulation of a “true” value and is intended to be replaced later by an actual input from a joystick channel.
 
What I’ve tried:
 
  • Calling the subVI directly from the desired state – the internal While Loop blocks the main loop.
  • Using a Case Structure to execute the subVI only when a condition is true – didn’t work.
  • Nested Case Structures inside the subVI to limit execution – also didn’t solve the problem.
  • Wrapping the subVI in a For Loop to simulate “call once” – still blocks the main loop.
  • Using VI references and Start Asynchronous Call – the internal While Loop requires state handling that these methods do not resolve.
  • Running the subVI in parallel, outside the main While Loop – it executes earlier than needed and still prevents the main loop from advancing. Tried both inside and outside the main loop.
 
Cannot use the same While Loop as the main structure – a photodetector is already running there doing something similar, which also blocks the loop.
 
The main challenge is to preserve the subVI’s internal logic (shift registers and Case Structures) while allowing it to be called without interfering with the main loop’s execution. Any guidance, suggestions, or examples would be greatly appreciated.😭
 
 
Download All
0 Kudos
Message 1 of 10
(344 Views)

Many here cannot open Vis saved in LabVIEW 2025. Please do a "save for previous", (2020 or below) and attach again. Thanks!

 

When discussing mainVi and subVI, it would help to attach simplified versions of both.

 

Make sure all controls have typical default values.

0 Kudos
Message 2 of 10
(338 Views)

Thanks for the notes! I just uploaded the 2018 version. I hope is clear now:

0 Kudos
Message 3 of 10
(326 Views)

Your Vis are still in 2025. "Save for previous" will NOT overwrite your VIs, but create a new folder next to your VIs Zip that folder and attach here.

0 Kudos
Message 4 of 10
(319 Views)

Probably the easiest thing to do is get rid of the while loop.  The code happening outside the subVI will provide the looping (if needed).

 

You just go into the subVI, execute the case based on what the inputs are, come out, and if you need to go back in, go back.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 10
(301 Views)

I tried this before, because I had a similar issue with a photodetector. I used in that way because I need monitoring both. But, for some reason this don't work. I will try again, maybe is the input. 🫠

 

 

0 Kudos
Message 6 of 10
(260 Views)

I will do that tomorrow that I have access to the computer in the lab again. Thanks for the notification

0 Kudos
Message 7 of 10
(255 Views)
0 Kudos
Message 8 of 10
(215 Views)

The only way I can think of implementing your idea, would be having a parallel loop with the sub-vi want to run. 

This way the main vi does not stop waiting the sub-vi to finish execution to continue  (as you already experience). 

 

ONe idea is using the template Producer/Consumer, your current main vi is the producer. whenever you want to trigger the subvi, it sends a message to the queue messuge handler. 

The consumer loop, keeps looking into the queue message. WHneever it sees and finds the appropriate message, it executes the subvi. Note that the subvi runs on the Consumer loop, while the Main loops keeps running with no dependence from the sub-vi to finish. 

 

LVNinja_0-1756500323232.png

 

0 Kudos
Message 9 of 10
(146 Views)

Thank you for your response!, I will try this new aproach and see if it works for my pourpuse, 

0 Kudos
Message 10 of 10
(109 Views)