From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Dynamic Dispatch

Solved!
Go to solution

Inheritance newbie question. I built a class for a TCP-based motion instrument. Some commands to the instr. are context-dependent. For example, depending on the variation of the UUT being tested, there are five different commands that implement "move-to-next-position." So I could have a parent move-to-next VI, and then override it depending on the UUT. But I already have a live TCP session on the class wire, how do I change the wire to a child? I'll need to change UUTs, and thus the wire, over and over.

 

Can I typecast the wire? Or should I have a different, has-a, class for the context-dependent commands? I could reconnect the TCP session and change the class using class constants at the start of each UUT 😞

Many thanks!

0 Kudos
Message 1 of 8
(2,399 Views)

On the diagram, you should place parent functions and connect them with parent-type class wires.  Any child UUT you instantiate gets to travel along these wires at run-time (based on the "child IS A parent" notion of inheritance, which sounds odd when I type it out explicitly) and dynamic dispatch will know to use a child override function when it exists.

 

So in short, you don't change or cast the wire on the diagram at programming time.  The diagram is all about parent-looking wires.  Run time is all about child-functioning objects doing their own thing along these wires by means of dynamic dispatch.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 8
(2,387 Views)
Solution
Accepted by topic author DowNow_

I probably wouldn't make child classes of the TCP motion instrument for what you want to do. I think doing so would unnecessarily couple the TCP motion instruments to the UUT. Without knowing too much about your application I would investigate having a UUT class which uses a TCP motion instrument to perform it's measurements.

Matt J | National Instruments | CLA
0 Kudos
Message 3 of 8
(2,375 Views)

@DowNow_ wrote:

But I already have a live TCP session on the class wire, how do I change the wire to a child? I'll need to change UUTs, and thus the wire, over and over.


The only thing that should have to change is the initialization.  If you initialize the child class, nothing else needs to change.  Now loading the correct class is the hard part.  Look to the Load LV Class Default Value.vi in order to load up the class you need to.  From there, I use To More Specific Class to change the generic LabVIEW Class into the parent class that you actually care about. Dynamic Dispatch will take care of the rest.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(2,373 Views)

I think if the communication is handled by normal TCP and not with a specific instrument driver, probably the suggestion of Matt would be the best, a composition of UUT Class and a TCP instrument class, I understood that only the payload of the frame changes so of this way you can adapt the command inside a Move-to-next method with dynamic dispatch and reuse the communication API.

0 Kudos
Message 5 of 8
(2,355 Views)

I'm going with this solution, also mentioned by SYanez below

0 Kudos
Message 6 of 8
(2,303 Views)

I'm sorry, I don't know how to use the forum. I selected the solution by Jacobson and AYanez. Thanks.


@DowNow_ wrote:

I'm going with this solution, also mentioned by SYanez below


 

0 Kudos
Message 7 of 8
(2,296 Views)

You can select multiple solutions if more than one message applies.

 

Just click the Accept as Solution on syanez's post also.

0 Kudos
Message 8 of 8
(2,294 Views)