08-26-2019 01:42 AM
Hello everyone,
I have a rather big project with many VIs. I would like to name 2 VI's the same but with different inputs.
VI_A: int, double, string
VI_B: Cluster (int, double,string)
VI_C: Variant
in conventionell programming it is usually posible to call a function with different arguments.
Is this possible in Labview or should I just name the VI's with different iterations (e.g. setInput1, 2,...)?
Thanks for the help
Solved! Go to Solution.
08-26-2019 01:52 AM - edited 08-26-2019 01:53 AM
Hi s.h.,
usually it's a bad idea to have two functions with different parameters, but the same label…
There are several ways to handle your problem:
1. Use polymorphic VIs. Here you can use the same (polymorph) VI with different inputs.
2. Use OOP with (atleast) 2 classes to handle the same functionality for two different sets of inputs…
3. You can use the same VI name when the VIs are in separate libs ("lvlib"). Now they don't share the same namespace…
VI_A: int, double, string
VI_B: Cluster (int, double,string)
VI_C: Variant
4. Use a VI with two inputs: variant and enum. The enum describes the content of the Variant and lets you choose the right conversion from variant to "plain" datatype inside your VI…
in conventionell programming
What is conventional programming? In which way do you think is LabVIEW "unconventional"?
08-26-2019 02:23 AM
I come frome Java,C++,C,... programming and I am still getting used to the visual programming (with cables) in LV.
To make matters worse:
I used a class which is shared between my parallel loops. From my understanding a class can consists of many (same named) functions with different arguments (inputs). Polymorphic VIs should do the trick but I found this entry
Use-Polymorphic-VI-inside-classes-as-dynamic-dispatch-to-emulate
where it states it is not possible.
Do you know a method for classes?
08-26-2019 02:35 AM - edited 08-26-2019 02:48 AM
I played around a little bit.
Create a polymorphic (parent) outside the class. Create dynamic VIs and insert them into the Polymorph. Then drag the polymorph into the class.
Only caviat: The child VIs from the parent polymorph still have to be named differently. But for documentation and visibility inside the Blockdiagram it works.
Thankfully not many people will see the project folder 😉
I will mark the topic as solved, if this is a viable solution.
EDIT: after compiling an error occured -> dynamic library could no be loaded
08-26-2019 02:38 AM
Hi s.h.,
From my understanding a class can consists of many (same named) functions with different arguments (inputs).
No. A (read: one) class can contain many functions, each having its own unique name!
From my understanding you would use child classes with dynamic dispatch to implement the same function with different inputs/outputs…
08-26-2019 02:46 AM
Thats correct. But the inputs only changes slightly. The general idea of the VI's stay the same (e.g. insertX, insertY,...).
It is just for my convinience to have them look the same and call them with the same name.
After compilation the proposed method of mine did not work, I will correct my statement.
08-26-2019 02:57 AM
Hi s.h.,
But the inputs only changes slightly. The general idea of the VI's stay the same (e.g. insertX, insertY,...). It is just for my convinience to have them look the same and call them with the same name.
You can have them "look the same" from the icon and the connector pattern.
But still they should be named differently, as you implement different methods in your class to access items of the class data! (Even "InsertX" and "InsertY" are different names!)
08-26-2019 03:14 AM
Did you try the polymorphic approach? It sounds to me like the best fit solution.
/Y
08-26-2019 03:23 AM
With the help @GerdW I organized my common VIs with the Polymorphic approach.
In the special case of a class, I will name the dynamic VIs each with its unique name.
Maybe there is a reason that polymorphism does not work inside a LV-Class?
08-26-2019 03:42 AM
Take a look at malleable VIs. They can be used for what I think you are after, and much more:
https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/malleable_vis_intro/
Polymorphic VIs work inside classes. If you are talking about the dynamic dispatch, then you just need to create a wrapper method to get that, see AristosQueue's answer: https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Use-Polymorphic-VI-inside-classes-as-dynamic-dispatch....