LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Polymorphic Object??

HI,

 

I might be making this more difficult thatn it should be, or I'm just lost in OOP land.

 

Given a gpib with several devices, I want to be able to wire a single (polymorphic??) vi that figures out which device its to talk to and does the operation. For example, Init.vi decides whether it's initializing devA, devB, or devC. So Init.vi is the polymorphic vi that contains InitdevA, InitdevB, and InitdevC.

 

The goal being to avoid a big case statement and to allow quick change when the devices on the gpib change or get added.

 

Thing is, if I create a typedef for each dev, I need to be able to programatically select the typedef to wire to the terminal when calling Init.vi.

 

I tried controls and classes, but can't seem to figure out how to index an array of "things" to pass to Init.vi.

 

With classes I could create an array of classes that inherited from a top (for example devA, devB, devC inherit the main type from Equip). But I couldnt get a class out of the array that matched the class on devA, devB, etc. So the polymorphic selection didn't work and it was always calling the first vi listed in the polymorph.

 

Any pointers/comments/ideas/examples appreciated.

 

Regards,

Mac

0 Kudos
Message 1 of 45
(3,062 Views)

It sounds like you are trying to invent the "Factory pattern" where it accepts a selector value and spits out the class you want.

 

What may help you is to take a look at this thread where Cory was asking about LVOOP and I offered up an example but asked him to interpret it. The example uses two classes with a common ancestor. The example shows how a method "Add" can be implmented for a String and a numeric class such tht for the string version "1" Plus "2" equals "12" and for numerics it equals "3".

 

last i looked polymorphics were not allowed with LVOOP but maybe it has been added.

 

I hope that helps,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 45
(3,059 Views)

That looks very similar to my last attempt with objects.

 

I see the index selects the string or numeric class from the array, but where does data class learn that string and numeric classes are its peers (don't know if that's the right term...)?

 

Mac

0 Kudos
Message 3 of 45
(3,049 Views)

@MacDroid wrote:

That looks very similar to my last attempt with objects.

 

I see the index selects the string or numeric class from the array, but where does data class learn that string and numeric classes are its peers (don't know if that's the right term...)?

 

Mac


 

If I have the rule right...

 

siblings have no knowlege of each nor do the parents know about their children. Only the child knows who it's parent is. It learns this when you configure the ancestor of the class.

 

I believe there is an example of the "Factory Pattern" on this web-site. It uses a case structure to selec the proper class. The data flowing in the wire identifies what class and is used to choose the proper method when an override is called for.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 45
(3,047 Views)

After more playing around I think I see what's going on.

 

One thing though, how do I get a specific object at run time?

 

I can use Get LV Class Default Value on a path, but it appears to return a LV object, not the specific object in the path.

 

I don't think To More Specific Class is useful since, the reason I'm loading from a particular path is to get that type of object cuz the Target Class is unknown.

 

 

0 Kudos
Message 5 of 45
(3,009 Views)

"Come in to my parlor said the spyder to the fly."

 

This image*

 

 

...can be found in my LVOOP albumn found here. If you look below the images you will see a link to the thread where those images where first used.

 

In the image above I am searching for Classes that are children of the class "Plugins". All of my Plug-ins classes have a "Type" property that allows me identify each of the class types and is what ends-up populating a ring control that allows my users to select the flavor they want.

 

Have fun!

 

 

Ben

 

* Note the missing error wire is a bug by the way.

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 45
(3,005 Views)

Are the classes in the folder children of "Plug-ins in"?

 

For instance in my case I have an object Equipment. It has private data "VISA Name" and "Name" and accessor vi's for each.

 

Then the children "meter1", "powersupply1", etc. inherit from that. I want to create an array of children where the VISA Name, and Name is different, as well as the functionality. i.e. they both have an init routine (with different inputs), but, one has input vi and one has output.vi

0 Kudos
Message 7 of 45
(2,997 Views)

@MacDroid wrote:

Are the classes in the folder children of "Plug-ins in"?

 

...


 

No not all of them are children of Plug-Ins. That is why I have to check all that I find to determine which ones are the children.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 45
(2,995 Views)

I should asl oemhesize that what I showed above is the more complicated way to do it. The Factory Pattern (hint search this site) uses a case structure where there is a unique class in each case. Since the class constant of the objects the Factory Pattern will return are part of the code they are by default opened when the Factory Pattern is used in a diagram. There is no need to go and find them.

 

In the case that used the code image I posted, the final executable has the ability to support more widgets in the future by just adding the new child classes to the application folder. No changes to the top level VI required.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 45
(2,990 Views)

Implementing the Factory Pattern in LVOOP

--
Tim Elsey
Certified LabVIEW Architect
Message 10 of 45
(2,989 Views)