LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP -- Difference between "Class in" icons on Block diagram

Hello @Everyone,

 

I have recently started learning OOP paradigm implementation in LV.

I noticed that if I dragged a LV class from LV project hierarchy directly on the block diagram of a VI, I was getting a different entity in comparison to what would appear if I dragged it onto the VIs Front panel.

Also, doing it in the first manner, I am not getting any corresponding FP entity.

 

I suspect I might be missing on some fundamental concept here. Kindly guide me.

 

Additional info: I am using LV2020 SP1.

 

PFA, screenshot for reference.

SamKan1_0-1745839942535.png

SamKan1_1-1745839987009.png

 

 

0 Kudos
Message 1 of 9
(577 Views)

Hello Sam,

 

When you drag something on the block diagram it will create a constant (so there will be no terminal on front panel).

When you drag something on the front panel it will create a control.

 

You can redo all this by dragging a string from another VI, to see the differences.

 

A constant cannot be used as a terminal of a VI, whereas a control can.

 

Message 2 of 9
(566 Views)

Hello @PinguX,

 

Thank you for your response. I was suspecting some foundational concept to be at play. It's clear to me now.
I do have an additional question to this.

What is the usecase of an object constant on the block diagram and, if we can really call it an object constant or a class constant would be more suitable?
I can think of following uses for a class constant:

1. Help in typecasting to a particular class type using "To more specific class" node.

2. Initialize a shift register.

 

The thought process behind this question is, as it's a constant I am assuming it to have default values for each attribute and I also have a reference coming out of it. Does that mean I can call methods on this constant?

0 Kudos
Message 3 of 9
(475 Views)

Remember that LabVIEW classes are by-value so there aren't any constructors. Dropping a class constant is kind of equivalent to creating a class object with all default values so you are able to call methods on that constant.

 

Besides what you mentioned about using class constants for type casting or initializing shift registers, you'll usually have some initialization method for the class which has no class input but does output a class. In the simplest case that method would bundle initialization data into a class object constant.

Message 4 of 9
(456 Views)

Regrettably, you can even have class constants with non-default values. They get a black border, see here: https://lavag.org/topic/11050-labview-constant-values-change/page/2/#findComment-144406

 

Message 5 of 9
(448 Views)

One use case for class constants is for factory patterns that you don't need to load dynamically. Plop down a few child classes in your case structure and wire them all to the same output node, and it'll automatically convert to the common parent class.

 

They're also used as inputs when coercing classes (To More Generic Class and To More Specific Class) when handling parent/child classes.

 

Also, you'd use them when defining sets or maps via the block diagram.

 

Also, they're useful as constants in typedefs, clusters, or other object's private data controls.

 

Basically I mainly use constant values to get their type. I don't use class default values too much other than for the factory pattern I mentioned above. Comparing them, non-default values, etc. is tricky since you can't easily tell what a BD constant class has inside itself, so I prefer to do that explicitly if I need to.

0 Kudos
Message 6 of 9
(436 Views)

Hello @Jacobson,

 

Thank you for your response, and apologies for the delay in getting back to you.

 

The first paragraph very well answers my queries, however could you please elaborate on the second paragraph as I am unable to comprehend it.

 

Thanks & Cheers~

0 Kudos
Message 7 of 9
(200 Views)

Hello @cordm,

 

Thanks for this golden nugget I'll surely read into this, looks fascinating. 

 

Thanks & Cheers~

0 Kudos
Message 8 of 9
(198 Views)

@SamKan1 wrote:

 

...could you please elaborate on the second paragraph as I am unable to comprehend it.


There are no explicit constructors but it's pretty common to create an "Initialization" function which you would use just like a constructor. The screenshot below shows the basic structure where the VI returns an object which is built from the constant all the way to the left (ignore the missing VIs this just happened to be the code I had open).

 

This type of VI isn't required. You could wire the class constant directly into other methods and they would run but all of the class data would be the default values.

Jacobson_0-1748967883310.png

 

0 Kudos
Message 9 of 9
(158 Views)