09-10-2012 08:05 AM
Hi,
I am trying to design a sub vi, that takes in three inputs (is jet on, is ethane valve on, and off signal) and process them continuously.
Working them in a while loop in the sub vi was working fine, but once I got them in the main vi, it turned out that the variables were updated only once, at the beginning of the while loop (simple dataflow structure).
I tried to use global variables first to continuously update the control signals, but it turns out that i need two while loops (one in the main program, and another in the sub vi), which I decided against.
I think using control references should solve the problem here. I read up the tutorials, and edited the sub vi to contain some references. But when called from the main vi, the problem persists. Dataflow again, the signals pass into the sub vi only once.
1.How can I connect the control signals from the main vi to the one in the sub vi without using a while loop?
2. In the examples I checked, the references were always connected to controls in the front panel. What if I wanted to pass in a signal into the sub vi, that is the result of an operation; e.g. 'jet is on' = 'fire' OR 'switch'. fire and switch are two toggle switches, but 'jet is on' is a signal that should be referenced in the sub vi.
I hope I defined the problem clearly. I will really appreciate any help.
Thanks.
09-10-2012 08:55 AM
You are referencing the controls in the subVI. Of course they will never change. To make this setup correct, you need to pass in a reference to the controls to the subVI and read the value from the property node connected to those references. I would not recommend this setup.
Does the subVI need to contain a while loop? This is typically a bad idea. Instead the subVI should be inside of a while loop (do not have the while loop in the subVI).
09-10-2012 10:33 AM - edited 09-10-2012 10:34 AM
@SohamSaha wrote:
Hi,
I am trying to design a sub vi, that takes in three inputs (is jet on, is ethane valve on, and off signal) and process them continuously.
Working them in a while loop in the sub vi was working fine, but once I got them in the main vi, it turned out that the variables were updated only once, at the beginning of the while loop (simple dataflow structure).
I tried to use global variables first to continuously update the control signals, but it turns out that i need two while loops (one in the main program, and another in the sub vi), which I decided against.
I think using control references should solve the problem here. I read up the tutorials, and edited the sub vi to contain some references. But when called from the main vi, the problem persists. Dataflow again, the signals pass into the sub vi only once.
1.How can I connect the control signals from the main vi to the one in the sub vi without using a while loop?
2. In the examples I checked, the references were always connected to controls in the front panel. What if I wanted to pass in a signal into the sub vi, that is the result of an operation; e.g. 'jet is on' = 'fire' OR 'switch'. fire and switch are two toggle switches, but 'jet is on' is a signal that should be referenced in the sub vi.
I hope I defined the problem clearly. I will really appreciate any help.
Thanks.
If I understand what you are asking, you want to be able to use your controls on the fly. You need to create a while loop at your top-level VI. Forget about using it in the sub-vi. That's not a good idea. You can also use a Producer-Consumer design pattern using Queues and pass your values using an event structure. I would recommend this if the user interface will be heavily used. It's important to think of your design, but also any future design. This makes it scalable.
09-10-2012 10:41 AM
If you uise a subVI and it is essentially a background task (running in parallel to other code and runing continuiously) you should consider using queues/notifiers/user events to pass data to/from the subVI. Unless the the subVI is specifically for managing the UI it is best not to pass control references to subVIs. Doing so creates a highly coupled application and makes reuse and maintenance much harder.
09-10-2012 10:14 PM
Thanks for the replies, guys.
@crossrulz: How do I pass the reference to the sub vi from the main vi? Is there a tutorial for this?
@MoReese and Mark: For queues/notifiers etc, is there a tutorial/nugget I could use as a starting point to learn?
Also, what if the reference I want to pass into the sub vi is not a physical control (e.g.) a switch, but rather a result of an operation (inputA OR inputB). How can I reference it to the sub vi?
09-10-2012 11:10 PM - edited 09-10-2012 11:12 PM
rt click an indicator or control from the front panel and create a "reference", then rt click the reference and create a "control" then drop it in the sub vi and connect it to an explicit property node...read or write to it from the main vi.have a look at access to controls property from another VI