11-16-2009 11:37 AM
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 ?
Solved! Go to Solution.
11-16-2009 11:40 AM
11-16-2009 11:50 AM
This might be a little more simplistic than what you're looking for.
But what about something like this?
11-16-2009 11:50 AM
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.
11-16-2009 11:53 AM
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
11-16-2009 12:13 PM
11-16-2009 02:07 PM
LOL!!
I know... I know... It's Monday.. 😉
11-17-2009 03:01 AM
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.
11-17-2009 03:07 AM
What a solution. Highly deserved to be " accepted as solution".
11-17-2009 03:25 AM
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."
-------------------