LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call the same loop using two different function/inputs?

Solved!
Go to solution

Hello, please see my example code. 

I want first loop to call the top loop, multiply 4 by 5 and receive 20 inside that same loop, then I want second loop to call the top loop and multiply 3 by 5 to return 15 into second loop. 

This is what I have, it kind of works but the problem is that it is inefficient because it runs through the code every single time. Ideally, I want to call the loop on the top ONLY when conditions of one of the bottom loops is met, pass value back to the bottom loop and continue. I have two commands only, what if I have, lets say 10 commands, wiring will become a mess. 

Can I make use of shift registers to achieve what I want?  

0 Kudos
Message 1 of 4
(1,030 Views)
Solution
Accepted by John32d

I cannot see your code because I'm running LabVIEW 2019 and 2021, but I wonder if you don't know about sub-VIs?  It sounds like your "top loop" should be a sub-VI (what other Programming Languages call a "subroutine" or a "function"), where you pass in two (or more) parameters and it passes out "the answer (or answers).

 

A sub-routine looks like any other LabVIEW routine -- it has Controls (= Inputs) and Indicators (= Outputs) on its Front Panel.  A difference is that you need to use the "Connector Pane", the checkerboard-like thing in the upper right corner of the Front Panel screen, next to the "generic icon").  The top two squares on the left hand side are for "inputs" (which are the Controls on your Front Panel).  When you get your cursor over, say, the upper-left square of the Connector pane, you might see it turn into a "wiring spool".  Click the upper-left square, then click the first "input/Control".  The square should turn the color of the wire associated with the Control (i.e. orange for a Dbl, blue for an Integer, etc.).

 

An easier way is to select code already on your Block Diagram that you want to make a sub-VI.  Select it (don't worry about the wires dangling out), right-click it, and choose "Create Sub-VI" from the Edit menu.  Now name it.  Open it, and clean it up.  Now you can simply "call it" whenever you want to use it.  Note how little space it takes (32x32 pixels) -- this can be a great help as you start writing larger, more complex routines.

 

Bob Schor

Message 2 of 4
(1,015 Views)

@John32d wrote:

 

This is what I have, it kind of works but the problem is that it is inefficient because it runs through the code every single time.


I think you need to start with some basic tutorials about dataflow, whatever you have attached is not fixable. It also helps to arrange the front panel elements in a logical way instead of scattering them randomly across the panel. Give all controls and indicators reasonable names that hits at their purpose ("subarray 2", "element 3", etc. are NOT reasonable names!

 

  • None of your inner FOR loops do anything useful. If you would remove them, nothing would change!
  • Your while loop spins millions of times per second burning 100% of a CPU core. Place a reasonable wait!
  • You never use some of the output tunnels, so all related code with get removed by the compiler once debugging is disabled (dead code elimination)
  • Not sure what the purpose if the feedback node is, but my guess is that you created a wire loop and LabVIEW inserted it automatically.
  • If you have 2D arrays (why???), expand them in both direction instead of just showing one column.
  • Do not use left-to-right wires unless is very specific small number of cases.

 

Here's your diagram so others with lower version can see it

 

altenbach_0-1681488447419.png

 

 


@John32d wrote:

Hello, please see my example code. 

I want first loop to call the top loop, multiply 4 by 5 and receive 20 inside that same loop, then I want second loop to call the top loop and multiply 3 by 5 to return 15 into second loop.   


To most of us, your description is pure gibberish! Don't explain HOW you want to do it, but WHAT you want to do. You don't "call" things, you just place them into the correct data dependencies. You don't "receive" things, you just out it to an indicator or other code section.

 

What should the user see after one iteration? How about at the next iteration? How about after an infinite time?

 


@John32d wrote:

Ideally, I want to call the loop on the top ONLY when conditions of one of the bottom loops is met, pass value back to the bottom loop and continue. I have two commands only, what if I have, lets say 10 commands, wiring will become a mess. 


There are no "conditions" in any of the loops. There are no "commands"!. The only user control is the stop button.

0 Kudos
Message 3 of 4
(1,007 Views)

See if this can give you some ideas.... (I am sure it is not what you want, but maybe you get some ideas.... 😄 )

 

altenbach_0-1681490030794.png

 

0 Kudos
Message 4 of 4
(997 Views)