From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conflict when using a SubVI twice in a VI

Solved!
Go to solution

Hi,

I'm trying to understand how a subVI works in this case:

I create a subVI, like in the picture below. Where the "Numeric" control replace 1st value in the "Array" control, and move the result to "Array 2" indicator.

meihk_0-1597336393391.png

Then I create a VI, attach the subVI above:

meihk_1-1597336598825.png

What I want is, every 2 seconds, the array's 1st value is replaced by a number that I enter (numeric).

The problem is, while running this VI, only the second block works.

Is there any way that I can make 2 blocks work at the same time?

 

The .vi files are attached below.

 

 

Download All
0 Kudos
Message 1 of 6
(1,274 Views)

Your VI is not reentrant, meaning that the "first call?" only executes once globally. Whatever instance executes first gets it. The other doesn't.

 

Possible solutions:

  1. Make the subVI reentrant.
  2. Leave it at non-reentrant but create a control for the init boolean and wire a i=0 to each instance.
  3. Initialize the shift regsiters on the main diagram with your default 5 element array and remove the first call primitive in the subVI.
  4. ...

 

In general, you might also want to initialize your shift registers. In fact you could make the subVI reentrant and have a feedback node inside the subVI, dramatically cleaning up your main diagram.

0 Kudos
Message 2 of 6
(1,260 Views)
Solution
Accepted by meihk

@altenbach wrote:

In fact you could make the subVI reentrant and have a feedback node inside the subVI, dramatically cleaning up your main diagram.


Here's how that could look like:

 

altenbach_0-1597339985091.png

 

0 Kudos
Message 3 of 6
(1,241 Views)

@altenbach wrote:

@altenbach wrote:

In fact you could make the subVI reentrant and have a feedback node inside the subVI, dramatically cleaning up your main diagram.


Here's how that could look like:


Or just use the Data Queue PtByPt.vi.  No development required.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(1,227 Views)

@crossrulz wrote:
Or just use the Data Queue PtByPt.vi.  No development required.

Yes, I intentional did not mention that in order to keep it simple. 😉 (I actually looked up the help on the ptbypt queue before posting).

 

(Also note that it is NOT the same because it fills the queue from the "other side")

 

Substituting basically a "one liner" subVI with something hidden deep in the palettes and having much more functionality (9 terminals!!) Would just complicate things to any newbie.

 

It's more about learning and understanding the basics of subVIs, "first call?", reentrancy, feedback nodes, etc. than to find a turnkey solution for exactly one specific problem. Maybe I misunderstood the purpose. :).

 

Data queue is strictly for DBLs (or CDBs for the other version) and this will not work, or work well, for most datatypes (integers, strings, etc.). Maybe somebody will make a VIM out of it eventually ...;)

0 Kudos
Message 5 of 6
(1,215 Views)

That works. Thank you so much!!

 

0 Kudos
Message 6 of 6
(1,206 Views)