LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing DI states from main.vi to sub panel VIs

For a machine control application, I have a sub panel container called the Main.vi. And depending on the user menu selection , I have a variety of  sub VIs to load ( AutoMode, ManualMode , Calibration mode etc )

I need to read and update the state of some 14 Digital Inputs in each of the above VIs at 50ms intervals in a Timed Loop. Since the 14 DIs are common to all the sub VIs, which is the best way to go  ? :

A. Read the state of the DIs in each of the sub VIs which is currently loaded.

B. Read the state of the DIs in the main.vi and pass on to the loaded sub VIs through Global Variables ( after all somone has to use them ;-))

I know the option A is preferred but there is a small catch : The menu selections are mostly done by  switches which are also part of the 14 DIs that I mentioned. So when only the main.vi is loaded and I choose the A Option, there is no way for me to "read" the user intention and load the relevant sub VI.

I would hence have to choose option B. If so what is the real penalty ??

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 22
(3,496 Views)
Hi Raghunathan,

I guess the best solution for this is to use Functional Globals. You will have the ease of implementation as in B and the functionality as in A.
Furthermore, you can add a "command" input and have it return the status of the lines by reading the last written value.

Here is more information about Functional Globals.
Here is an example of it.
Here is more information about variables in general.

Hope this helps,
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 2 of 22
(3,479 Views)
Hi Gerardo,

Thanks for the good links.

I guess this issue on using variables in a data flow environment is going to persist as long as you have programmers ( like me ) who have to do LV coding in the morning and C coding in the evening. ( Only to debug both of them tomorrow ;-))

Regards

Raghu
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 3 of 22
(3,469 Views)
Hi Raghunathan, Gerardo,
      When I read Raghunathan's post it sounds like there's a single data-producer and multiple consumers - might this be a good application for using a notifier or queue - both event-driven solutions (see LV7.1 Queue example attached.)
 
Cheers!    
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 4 of 22
(3,458 Views)
>> When I read Raghunathan's post it sounds like there's a single data-producer and multiple consumers - might this be a good application for using a notifier or queue - both event-driven solutions (see LV7.1 Queue example attached.)

Thanks. It looks to be elegant. The only difference in my case is that I shall be passing the information from the main.vi  to another VI which is running inside the sub-panel of main.vi. I hope there should be no problem in this ??

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 22
(3,453 Views)
Hi Raghunathan,

If you store the queue reference in a functional global, you can use it in multiple VIs. As you said and TBD is proposing, this is an elegant solution but it will be scalable and, if well designed, maintainable which are really good qualities of any code.
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 6 of 22
(3,433 Views)
Hi Raghunathan,

@Raghunathan wrote:
in my case is that I shall be passing the information from the main.vi  to another VI which is running inside the sub-panel of main.vi. I hope there should be no problem in this ??

It's no problem to pass parameters via connector-pane to Sub-VIs that appear in a Sub-panel.
 
Depending on your application-design, you might want to call the Sub-VI once and let it run during updates, or call it repeatedly (in a loop) whenever there's new data. (Sometines it's helpful to post some code with these kinds of questions - Smiley Wink -)  If it's the case that the Sub-VI should be called repeatedly, whenever there's new data, and the DI data is produced in the caller, then I'd pass the data "explicitly" through a connector.  If the Sub-VI is called once and needs to receive DI updates, then I'd pass it a queue reference (per example.)  The attached example shows one of the Sub-VIs in a Sub-panel!
 
Cheers.
 
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 7 of 22
(3,425 Views)
Hi tbd,

I am happy I asked this question here. After going through the examples posted by you I now realize the potential of the Queues and Notifiers. When learning any new language one normally skips such off-beat functions, only to learn later that they are quite powerful.

I already have started recoding my VIs with queues in place  of Globals.

Thanks to all of you who responded and set the track right for me.

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 8 of 22
(3,411 Views)
Hi Yardov,

Thanks for your post.

Do I really need the functional global ? I thought I can directly use the queue reference and get the data into multiple VIs.

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 9 of 22
(3,411 Views)
Hi Raghunathan,

Sure you can do it without functional globals. I am probably just a fan of them and therefore I use them quite often to store data.
I am glad TBD recommended queues and now you started to use them. Those are best practices. Smiley Happy

Message Edited by Yardov on 08-10-2007 07:56 AM

Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 10 of 22
(3,405 Views)