LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using existing VI as a Sub VI

Hello everyone,

 

I am trying to use a VI that is used to control motors, totally functional right now. However I need to use it as a Subvi in my project, as it will have to be used in parallel with other hardware. As the VI is not of my authority I posted a screen shot only of how it is structured.

 

I have been trying to send data from a very simple VI to understand how to control the flow of the data between both VI's. From what I understood the while loop is a problem for me. Each time I press a button that accesses the subvi, it stays there forever. However, after removing the while, it doesn't do anything.

I tried using references and I was able to use one of the controls from the main vi. But then I don't understand how to change numbers of values.

 

I don't need to use the whole VI. Basically I need to send the "distance" for the motor to move, start moving and stop when it reaches there. Lately I need to use other sensors in parallel.

 

Anyone has some suggestion for what I should do or look for?

 

Thank you in advance!

0 Kudos
Message 1 of 8
(3,814 Views)

Your VI is set up to behave like a top level VI, an application.  It has a master while loop.  It has an event structure that relies on user interaction with the front panel controls.  If you call this as a subVI, and you don't have it open the front panel when called.  It is going to run in the background and never return because you've never provided the user with a way to end it.

 

If you call it and allow the front panel to open, that's fine.  But it is still going to behave like a top level application.

 

What you need to do is break up each of the functions that this VI does into subVI's.  Then have your new master program call each subVI as needed rather than calling this VI.  If you change this VI as well to call all of your new subVI's, then you can proceed to use this VI whenever you want to run it as its own standalone application again.  And it will use a common code base so that if you ever need to fix a bug within one of your functions, you fix the subVI and it will apply to both this standalone master VI, and your new VI where you call the functions individually.

Message 2 of 8
(3,804 Views)

Another problem is the fact that we don't know where your terminals are. You seem to subscribe to the notion that everything should go through value property nodes. This is definitely a bad and inefficient design.

 

Please attach your actual code. We cannot judge images. thanks!

Message 3 of 8
(3,752 Views)

Thank you for both answers.

 

I was avoiding touching the already existing VI too much, but I guess I will try to divide it into sub VIs.

About the property nodes, it was not me who programmed it. But what would you suggest to be more efficient? I can still make changes while I am transforming it into sub VIs.

I attached the main VI.

 

Thank you again!

Message 4 of 8
(3,697 Views)

All your value properties can be replaced with local variables for signficantly better performance.

In many cases you could even hook up the actual control or indicator terminals, most are currently disconnected.

You have significant race conditions due to blatant overuse of value proerty nodes, for example in the INIT event case, you are reading and writing to several proerty nodes of the same terminal in parallel. the outcome will depend on the order while the order is not defined. For example you are reading "IS X" in the lower part and that could occur before or after the upper part writes to it. Since the upper sequence is probably slower it is likely that the lower part reads stale values. Maybe that's what you want, but maybe once in a blue moon the upper part is faster. 😄

Also since all the subVIs in the sequence are lined up along an error wire, their execution order is determined and most of that flat sequence structure is not needed at all. get rid of it!

 

Why is there no event for the exit button? It could be latch action, wired to the termination condition and thus both its value property nodes could be eliminated. Simplify!

 

This is just the tip of the iceberg....

Message 5 of 8
(3,674 Views)

I will try to implement it taking in consideration your tips 🙂 Thank you.

 

Meanwhile I was suggested to use shared variables to control the existing VI. What do you think of it?

0 Kudos
Message 6 of 8
(3,660 Views)

@Rhen wrote:

 

Meanwhile I was suggested to use shared variables to control the existing VI. What do you think of it?


What do you mean by "control"? To make such a design decision requires significantly more information on what you are trying to do.

You cannot trigger events using shared variables.

0 Kudos
Message 7 of 8
(3,656 Views)

So this VI I attached, I need to use functions of it in my main VI. My problem right now is to access its functionalities as there are the while cycle and the events structure, so I am wondering which is the best approach to use its functionalities.

One of the first options is to transform each function in sub VIs as mentioned.

Now I received the suggestion of shared variables (which I never used before).

About triggering the events, well I guess that might reject the option of shared variables 🙂

0 Kudos
Message 8 of 8
(3,648 Views)