From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Functional Global variables with polymorphic VI

Solved!
Go to solution

Hi,

 

I am want to build a functional global variable in a polymorphic VI. So, for example in a functional global variable, we have case structure. I would like to build separate VI's for case structure and make a polymorphic VI.

 

Is there a way that I could use a polymorphic VI instead of case structures?

 

 

Thanks!

0 Kudos
Message 1 of 16
(4,296 Views)

I think you have a misunderstanding about polymorphism.

Polymorphism enables the developer to use a specific function independent of the data type DURING EDIT TIME.

That means:

1. You have a "File Save" function, which is polymorphic. Possible (read: implemented instances) are: String, Numeric Array, String Array.

2. You as developer want to use that "File Save" function in your application. During development (read: Edit Time), you don't have to care for data types passed to "File Save" as long as it matches the three above. If it matches, polymorphism selects the correct instance of "File Save" for you (by default, polymorphic inputs autoselect the instance!). As result, the instance is selected during edit time.

3. You can add additional instances of polymorphic "File Save" for other data types. These will still only select during edit time. If during runtime, the passed data type doesn't match the selected instance, you will get a runtime error.

 

A case structure on the other hand is a selection done DURING RUNTIME.

So you have to implement each case you expect (like polymorphic instances for polymorphic VIs), but the actual selection of the case to execute is done during execution (read: runtime).


So long story short: No, you cannot use polymorphism to get rid of a case structure.

 

Hint: There is an option to get rid of the case structure. It is called "Dynamic Dispatch" and is part of LV OOP.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 16
(4,283 Views)

Do you mean you have different variables and you are updating each of them in seperate cases? So you are trying to have a polymorphic VI to handle each variables seperately?

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 16
(4,282 Views)

Hi P@Anand,

 

Yes, I have different data as an input and don't want to get confused including data for different case structures. So, I thought I can use a polymorphic VI which will be easier. But, the problem then arises with Functional global variables. It doesn't pass data. Maybe, because it is not within the case structure. I tried finding myself but couldn't find it. So, maybe, I needed some help!

0 Kudos
Message 4 of 16
(4,263 Views)

Hi Robert,

 

I had used polymorphic VI for case structures. But, it won't work with Functional Global Variables. How would dynamic dispact help?

0 Kudos
Message 5 of 16
(4,258 Views)

Dynamic dispatch is in LVOOP. I would recommend you to use cluster with the number of variables you need. So in this case you can use the case structure to Read, Write and Initiate. So by using the Read case you can read any variable and the same way you can also write but before using Write use the Read instance to read the data and update only the variable that need change.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 6 of 16
(4,244 Views)

@c_prisha wrote:

Hi Robert,

 

I had used polymorphic VI for case structures. But, it won't work with Functional Global Variables. How would dynamic dispact help?


Again, a polymorphic VI is not an alternative to a case structure. It is a complete different setup (Edit Time vs. Runtime).

I don't understand the remark of the FGV. Do you want to create an FGV which is polymorphic? That doesn't work for sure as each different polymorphic instance will create a separate data space; as result, the different FGV instances don't share data if the data type is different (polymorphic instance).

 

I think you should start with some small examples of LVOOP to get familiar with that topic. Also browse ni.com for white papers explaining use cases of LVOOP.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 7 of 16
(4,243 Views)
Solution
Accepted by topic author c_prisha

You could create a polymorphic VI that is used as a wrapper for the FGV.  The idea would be that each instance of the polymorphic VI calls the FGV with the correct case selected.  Then your API is the polymorphic VI instead of the FGV.


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
Message 8 of 16
(4,215 Views)

+1 to Crossrulz

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 16
(4,194 Views)

@crossrulz wrote:

You could create a polymorphic VI that is used as a wrapper for the FGV.  The idea would be that each instance of the polymorphic VI calls the FGV with the correct case selected.  Then your API is the polymorphic VI instead of the FGV.


An API to an engine (or "Core" if you prefer) as polymorphic instances?  I suppose it is possible but the connector pane limitation will beat you up and require all those extra terminals that the OP wanted to avoid.

 

Ben's famous Action Engine Nugget is always a good read.See Here

 

Towards the end Ben "Goes to Nirvana" by creating wrapper vis for each method to create an API

 

I Reciently posted an example with pseudo BDs as well for  (I think it was a flow counter Resource Module) I'll try again to find it but Tim will surely link to it while I look

 

 

Edit {Message 6 here}


"Should be" isn't "Is" -Jay
Message 10 of 16
(4,185 Views)