LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling an Event in a subVI

Solved!
Go to solution

Hello all,

 

I have a main VI, and a subVI (a bit complicated one) which works with an Event structure.

I need a way to link a button (the trigger) in that specific event VI to a button in my main VI.

 

I know there isn't a very easy way to do this, and I'm a newbie when it comes to references.

I've tried globals, but that didn't seem to work..

Can anyone help me by telling exactly how I link two buttons together (from different VI's), so that it will change the specific event (the button is a boolean btw)

 

Thx in advantage!

0 Kudos
Message 1 of 7
(3,483 Views)

Hi,

May be going through this example will help you. Download both the VIs and run 123.vi

 

Regards,


Nitz

(Kudos are always WelcomeSmiley Wink)

 

Download All
0 Kudos
Message 2 of 7
(3,479 Views)

Thank you for the reply!

But I'm affraid that didn't clear things up for my case

 

I've attached my program to this post

Open Main.vi, and the subVI is AVS_Main.vi (alot of SubVI's are missing, but it's just to give a picture of my problem)!

 

Hope anyone can help 🙂 

Download All
0 Kudos
Message 3 of 7
(3,472 Views)

Ow and PS, don't pay attention to the globals, I was just testing something and forgot to delete m

0 Kudos
Message 4 of 7
(3,471 Views)
Solution
Accepted by topic author WickedWalker

What a mess!

 

1. Try to keep the size of your diagrams to one screen.  Scrolling around to see what is going on makes understanding (and troubleshooting) a VI very difficult.

2. Get rid of the local variables. They break dataflow, may lead to race conditions, and make it difficult to tell what the program is doing. The WIRE is the variable.  Controls and indicators ( and local variables linked to them) are merely the user access point to the value of a variable (the WIRE).

3. The main program has 3 infinite loops running in parallel.  At least one of them has no delays or waits and likely will hog the CPU resources.  How do you stop this program?  Someone on this Forum once said, "Stopping a VI by using the Abort button is like stopping a car by running it into a tree." It works but it has (undesirable) consequences.

4. The AVS_Main.vi has a 10 second wait in the lower case structure which runs in parallel to the event structure.  This will make things very unresponsive to events.

5. Sequence structures are almost always unnecessary. Stacked sequence structures should be avoided because they hide code, are hard to extend or modify and result in right to left wiring.  Use dataflow.  Use a state machine.

 

Now to the core of your question.

6. While it is possible to set up an event structure in a subVI to respond to user actions on the main front panel, it would probably be better for you to have the event structure in a loop of its own in the main VI.  Look at the Producer/Consumer (Events) Design Pattern.

 

While I cannot be sure what your program is supposed to do, I think it can be done with two while loops in a Producer/Consumer pattern, without sequence structures, without local variables, and with diagrams no larger than one screen.

 

Lynn

0 Kudos
Message 5 of 7
(3,437 Views)

thx for the response 🙂

 

In my defense, the AVS_Main was a standard example of a spectrometer which I would like to use, so don't blame me for the programming ^^

This program doesn't need to be stopped, and need to run for several weeks at a minimum, so that's the reason for the 'no abort button'!

 

Anyway, thank you for the tips! I was allready thinking of all of that, but I thought there may have been a simple solution to this without editing the entire crappy sub VI. 

0 Kudos
Message 6 of 7
(3,416 Views)

I did not mean to be critical of you, only of the program.  Clearly you are aware of some of these issues and are trying to learn.  Those are attributes which are appreciated on these Forums.  Keep asking questions as you run into things you do not understand.

 

Rather than editing that VI, I would probably use it as a reference while trying to generate a specification document. The specification would clearly indicate what the VI is required to do (not what it actually does or does not do now) but not how to do it.  Then I would design a program to meet the spec and write a new subVI.  You will likely get a better program, learn a few things along the way, and probably not take any longer than trying to edit the original.

 

Unfortunately there are a lot of example programs out there which are not very good "Examples" of how to write in LV.

 

Lynn

0 Kudos
Message 7 of 7
(3,406 Views)