LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to "play" a given VI in another VI

Solved!
Go to solution

Hi guys,

 

so my question is the following can I "play" a given VI when I push a button on the main VI.

 

I've got 3 different VI that control 3 different device, let's say each of the device contains the logic to open 3 doors, so VI 1 opens door 1, VI 2 open door 2 etc .... 

I need a main Vi in which I can choose to open door 1,2 or 3 or 1 and 2, 2 and 3 etc ..., so I thought of using SubVI for each door but if I put the 3 sub-Vis on the main Block diagram both of the 3 doors opens when I hit the arrow to play the main VI.  

 

So I need a way of "play" a given Sub-vi to open the doors.

 

Of course this is a simplification. In fact I have to control Moving Stages and complex mouvement for them while measuring position and control a laser, but a "Play sub Vi" button would be usefull. 

 

 

 

Any idea ? 

0 Kudos
Message 1 of 11
(3,836 Views)
Why can't you use three buttons in the main vi and an event structure to handle the click events of which door needs to be open that was clicked in the main vi front panel
Message 2 of 11
(3,832 Views)

This might be a little more simplistic than what you're looking for. 

 

But what about something like this?

 

execute sub.jpg

---------------------
Patrick Allen: FunctionalityUnlimited.ca
Message 3 of 11
(3,820 Views)

GautierP wrote:

so my question is the following can I "play" a given VI when I push a button on the main VI.



yes

 


GautierP wrote:

I've got 3 different VI that control 3 different device, let's say each of the device contains the logic to open 3 doors, so VI 1 opens door 1, VI 2 open door 2 etc ....


well written code would only require a single VI.  However, let's have fun and pretend there are three different types of doors.  so yes, you can have 3 different sub-vi's (although not necessary)

 


GautierP wrote:

I need a main Vi in which I can choose to open door 1,2 or 3 or 1 and 2, 2 and 3 etc ..., so I thought of using SubVI for each door but if I put the 3 sub-Vis on the main Block diagram both of the 3 doors opens when I hit the arrow to play the main VI. 



Of course...  that's because your missing the codewhich decides which door to open based on a selection criteria.

Do you have one or multiple buttons?  How do you select which VI(s) (door(s)) should run (be opened)?

 


GautierP wrote:

So I need a way of "play" a given Sub-vi to open the doors.



Well...  let's not get carried away with additional sub-vi's.  The main VI should be able to handle that.

 


GautierP wrote:

Of course this is a simplification. In fact I have to control Moving Stages and complex mouvement for them while measuring position and control a laser, but a "Play sub Vi" button would be usefull. 

 


You need to first define how you will allow the operator to make selections.  You have to define if there is a single or multiple operations that can be selected at once.

 

You should look into using an Event Structure as part of the solution.  Which LabVIEW package are you using? (Basic, Pro, etc)

 

The key thing at this stage is to properly architect/design your solution, otherwise it can get messy very quickly.

 

To learn more about LabVIEW, I suggest you try looking at some of these tutorials.

 

 

 

 

Message 4 of 11
(3,817 Views)

Patrick,

 

I would not recommend your suggested approach.

 

If you would go toward that style, at least make the solution a State Machine.  Not a series of Case Statements.  Imagine if multiple process need to be selected, which one will run first? (race condition).

 

There are more elegant and simpler ways of doing this.  First, we need to know more about the requirements (what's really needed and how it should function).

 

R

Message 5 of 11
(3,812 Views)

Ray,

 

I agree that what I put up wasn't a good solution for anything more than the simplest of programs.  But I didn't know what the original poster's program actually did, or his/her LabVIEW abilities.  

 

I just figured I'd throw something out there and see what came back.   :smileytongue:

---------------------
Patrick Allen: FunctionalityUnlimited.ca
Message 6 of 11
(3,786 Views)

LOL!!

 

I know... I know... It's Monday..  😉

Message 7 of 11
(3,763 Views)
Solution
Accepted by topic author GautierP

Hello everyone, first, thank you for your contribution. 

 

Now regarding my "door" problem, my first idea was to use a loop + boolean + case structure but I am adding feature to an already made VI so it can't be done that easely. I thought I just added some extra code, by if I do so the final code design will be awfull and pretty difficult to understand for future coders.

 

So I think I will remade this particular part of the control and make it simplier while integrating the new features.

 

Kudos for all and once again thank you for your contribution. 

 

 

0 Kudos
Message 8 of 11
(3,722 Views)

What a solution. Highly deserved to be " accepted as solution".

 

 

Regards
Asad Tirmizi
Design Engineer
Institute of Avionics and Aeronautics

" Its never too late to be, what u want to be"
Using LabVIEW 8.2
0 Kudos
Message 9 of 11
(3,718 Views)

Well, I'm not sure if you're sarcastic, but it was more a way to close the conversation rather than really giving the solution.

 

Most of the contributions contains a solution that would work depending on what you need to do, but for my particular case the solution IS to remade the VI and I'll probably use the loop+case structure.

 

I'm pretty sure that a coder would say that the best solution is allways to rethink the whole program and find an elegant structure each time. This time I chose to follow that leitmotiv rather adding an extra layer of VI and Sub-VI.

 

------------------- 

"What's up?"

"I don't know," said Marvin, "I've never been there."

------------------- 

0 Kudos
Message 10 of 11
(3,716 Views)