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,652 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

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 8
(2,640 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,628 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,626 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,608 Views)

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

0 Kudos
Message 6 of 8
(2,556 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,549 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,547 Views)