LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a list of options on the Main Vi and have that selection be passed to several SubVis

I'm newer to labview and working with a very large coding base, so much so I can't really upload it. Basically - on the main Vi I want the user to be able to select from a list which type of module is being build. This item selected from the list would then be passed to several SubVis. For example, if we are building Module Type A, then the subvis would see "Module Type A" and my case structures in the SubVis would change to Module Type A and use those parameters, same for B, or so on.

 

I want this to be easy to use. So when you hit "Run" and begin Module development, you input the commands and then select "Module Type A", and then hit "go" and the subVis will all change their case structure to match that initial selection.

 

I've begun working and created a CTL file called "Type of Hexaboard" but this doesn't seem to pass info between Vis. I'm not sure how I should go about doing this but any help is appreciated. Here's an image of the layout for example.

LBPhysics_0-1676921016662.png

 

0 Kudos
Message 1 of 6
(776 Views)

Hi LB,

 


@LBPhysics wrote:

on the main Vi I want the user to be able to select from a list which type of module is being build. This item selected from the list would then be passed to several SubVis. For example, if we are building Module Type A, then the subvis would see "Module Type A" and my case structures in the SubVis would change to Module Type A and use those parameters, same for B, or so on.


Use a typedefined enum to hold your list of options. Then use a wire from the enum control to your subVIs to forward the selected value. When you connect the enum to a case structure the cases will automatically show the enum items which helps with code readability!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(763 Views)

Thank you! The problem is that the SubVis are buried under several layers of SubVis - I should have been more clear. The ones that need the value of "Module A" or "Module B" are several layers deep - so I need a way to Link the typedefined enum between these seperate Vis without having to directly have a wire going through every intermediate Vi. Unless I'm misunderstanding how enums work.

 

Like it goes - Manual Assembly (Select Module Type), "Run operations", "Find Workspace", "Find Center", and then inside Find Center I need to use the type of module. So rather than wiring through several layers of labview - it would be better if I could select the value at the start and then it would automatically change the enum for all the subvis. Or it would be attached to a variable that could be called by all subvis to then change the case structures. I'm not sure which is the best way to go about it.

 

Thank you for your help!

0 Kudos
Message 3 of 6
(739 Views)

That's almost free functionality with OO programming.

 

You'd make a parent that does all the common work, and each child implements a function that can be executed somewhere deeper.

 

Or, you'd pass the object (a child) to the sub VIs, so they execute the function deeper down.

 

You'd always need to pass something, an enum, the object as a parameter, or the object as object.

 

The benefit of OO is that you can add a child, without changing the subVIs that use it. With an enum, you'd need to add an item, that changes the type def, and then add a case or cases to each case structure that uses the enum. That's a lot of changes.

 

This situation (polymorphism) is a very strong reason why people use OO. You get wires that change functionality....

 

This seems to be a typical use case, so a perfect candidate to start a first OO experiment. 

0 Kudos
Message 4 of 6
(674 Views)

I would like to learn object oriented. Do you have a tutorial link by any chance?

0 Kudos
Message 5 of 6
(653 Views)

@GRCK5000 wrote:

I would like to learn object oriented. Do you have a tutorial link by any chance?


Sadly, no, not really.

 

At the bottom there are some tutorial links:

Object-oriented programming - LabVIEW Wiki

 

I'd most definitely stay far, far away from a hardware abstraction layer for the next few years though.

 

Usually, I'd advice to use a class as a cluster as a first step. The class's private data is the cluster. But you don't 'expose' that data, you make methods to do things with that data.

 

However, since you need a 'functor' (control function behavior by a wire), you'd want to start with inheritance so you can use polymorphism.

 

A very basic example of polymorphism\inheritance (dynamic dispatching) is the dynamic dispatching.lvproj example in the example finder that's shipped with LabVIEW.

 

Just imagine the code in the for loop in a sub VI. Or don't imagine, select it and make it a sub VI. Now your class input controls the behavior in (of) the subVI.

0 Kudos
Message 6 of 6
(636 Views)