BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP

Thanks for the example Ben.
That really tied everything together.
I'm going to play around with that for a while, and see if any questions arise.
Cory K
0 Kudos
Message 11 of 20
(8,717 Views)

Please edit the icons (good leason to learn what part comes from the class and what part are VI specific) and post some screen shots with a short narative please. I am on-site with an old version of LV and can't do so myself.

 

Your reply with those screen shots will be agood intro for others and it will let us check your understanding (as well as me learn from others that know LVOOP better than me).

 

Trying to learn as a team,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 12 of 20
(8,712 Views)

Sure, I will try to get some screen shots up.

 

Quick question : I tried to create a new class. I put 3 controls in the cluster for the newly created class.
When I created a new VI, I tried to unbundle the class to access the elements, but I got an error saying the class was 'private'.
Am I doing something incorrectly?

Cory K
0 Kudos
Message 13 of 20
(8,708 Views)

The Unbundle by name etc can only be used by a VI that is a member of the class. Right click on the class and choose "create accessor". THis will give you a dialog that will then create the accessors for you. Use the accessors to put dat in and get data out.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 14 of 20
(8,705 Views)

Here is my understanding of Bens code. Take it with a grain of salt.... or rather, the amount of salt on McDonald's french fries.

 

On the top level VI, named Test.vi, you can 'add' A and B.

The index will tell the VI whether to treat A and B as an instance of the 'data' class or an instance of the 'strings' class.

 

Both classes are clusters of 3 controls : A, B, and Answer

Controls.PNG

 

 

For example, if you enter A = 8 and B = 9:

 

If you set the index to 0, both A and B will be treated as numbers.

Add Numbers.PNG

 

If you set the index to 1, A and B will be treated as strings, so 'adding' them will concatenate.

Add Strings.PNG

 

In the code for Test.VI, you can see that first the two class constants (data and string) are built to an array.

Top Level.PNG
The index then chooses which class to operate with.

The next 2 functions create an instance of A and an instance of B respectively as the selected class.

Write A:

Write A.PNG

 

Write B:

Write B.PNG

 

Once A and B are defined as objects of the selected class, they are 'added'.

The 'Add' VI first figures out what class the objects are in, then adds them accordingly.

 

If it determines that A and B are numbers (instances of 'data') it will add the two values:

Add Numbers Code.PNG

 

If it determines that A and B are instances of the class 'strings' it will concatenate:

Add Strings Code.PNG

 

In both cases, the returned value is passed to the control 'answer'.

 

This answer is read by 'Read Answer.vi':

Read Answer.PNG

 

The user then sees the final answer of the whole operation.

 

 

I hope I didnt butcher that explination too much.

Feel free to explain further if you feel I left anything out.

 

Cory K
Message 15 of 20
(8,703 Views)

Good work!

 

This is starting to look more like a "nugget".

Message 16 of 20
(8,699 Views)

Excellent Cory!

 

Let me split hairs.

 

Only the parent class "Data" has anything in its private data cluster. The other two classes do not have their own data, they inherit the data from their parent.

 

THe two child classes Numeric and Strings only have a single VI each. THey have their own version of the "add" VI (method) that is used to over-ride the callers version of "add" when it comes to execute that function. Which type is used is determined by which class it was passed.

 

Thank you Cory!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 17 of 20
(8,696 Views)
Ben, for your 'add' VI in the top level VI, how did you import the other 2 add VIs so it knew to only select from among those 2?
Cory K
0 Kudos
Message 18 of 20
(8,681 Views)

Cory K wrote:
Ben, for your 'add' VI in the top level VI, how did you import the other 2 add VIs so it knew to only select from among those 2?

 

After creating the dummy add in the top level class and defing the child classes I,

 

Right-click (in proj window) on child class and select Create Vi for over-ride.

 

That will give you a dialog window to choose which VI you want to over-ride (any of the ancestors VI with dynamic dispatch connectors (I think).

 

Repeat for the other class or "Copy Save as" on one class to clone it and then mod the over-ride VI for the other class.

 

If you right-click the class and choose properties you can define your inheritance to control which classes that class inherit from.

 

I use the over-ride all of the time to define my class names. In the "Create_New" methods (OOP talk for creating a new instance, ie "Init" ) an over-ride VI calls its parents "Read Class Name" property (Cludge that is helping my until I learn a better way) and appends its name and writes it back to "Class Name". When read by the child class when executing it reads like a VI call chain, a kind of class chain.

 

Have fun and keep asking questions. I'm just learning LVOOP myself and thinking about your questions is helping me a lot.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 19 of 20
(8,674 Views)

I just looked through DFGray's Xylophone project.

That really shows how powerful LVOOP is.

Cory K
0 Kudos
Message 20 of 20
(8,612 Views)