LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using control references to connect two Vi's

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.

0 Kudos
Message 1 of 6
(3,052 Views)

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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(3,042 Views)

@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.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 3 of 6
(3,029 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 6
(3,021 Views)

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?

0 Kudos
Message 5 of 6
(3,006 Views)

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

0 Kudos
Message 6 of 6
(3,000 Views)