LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Naming convention

Solved!
Go to solution

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

0 Kudos
Message 1 of 13
(2,371 Views)

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"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 13
(2,360 Views)

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?

0 Kudos
Message 3 of 13
(2,341 Views)

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

 

0 Kudos
Message 4 of 13
(2,334 Views)

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…

Best regards,
GerdW


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

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.

0 Kudos
Message 6 of 13
(2,328 Views)

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

Best regards,
GerdW


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

Did you try the polymorphic approach? It sounds to me like the best fit solution.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 13
(2,308 Views)

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?

0 Kudos
Message 9 of 13
(2,300 Views)

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

 

 

 

 

 

Certified LabVIEW Architect
0 Kudos
Message 10 of 13
(2,285 Views)