07-01-2016 09:07 AM
Dear NI Community,
I am working on a project that will make use of Object Oriented Programming (OOP) techniques. There seems to be a wealth of resources on topics like inheritance and dynamic dispatch but am really struggling on how to implement a composition.
Here is the issue... I have an instrument that may have several (relay) cards present to be determined at run time. I thought that OOP composition would be the most desirable technique as it is a `has a` relationship rather than `is a`. My parent class is "Instrument" and it has a property which is the visa resource and the children class is "relay card" which has properties; module slot/analogue bus/ relay state.
Instrument:
Properties: Visa Resource
Methods: Init, Self Test, Close etc
Relay Card:
Properties: Module Slot, Analogue Bus, Relay State (2D boolean array - XControl)
Methods: Init, Toggle Relay, Close etc
When I execute the Toggle Relay method I need to get the Visa Resource property from the parent class. I have done class compositions in text based languages which made use of pointers such that the children have a property "parent" which is a pointer to the parent and the parent has a property "children" which is an array of pointers to the respective children. Therefore to get the visa resource we might do get(@Parent,'Visa Resource') simples.
However, in LabVIEW... urm not sure! I looked into using a DVR to do the aforementioned method (see attached code LV2013) but came unstuck when considering that branching the class wire makes a copy. Furthermore by calling the Delete DVR method then I am able to generate multiple instances of the same object is disconcerting.
Anyway. If anyone could provide any help or advice on how to implement class compositions in LabVIEW I would be eternally grateful. Please let me know if any more clarification on the issue is required.
Thanks in advance,
Robert Ward
07-01-2016 09:21 AM
Robert,
from the setup, it is clear that your OO-experience is based on textual OO-languages. However, even if LV can OO since version 8.2, LVOOP does follow the very basic concept of LV: dataflow programming.
There is a famous sentence regarding OO in LV: The wire is the object.
DVR is a method in LV to get handles on specific data sets. A DVR of a class is indeed the handle to a single object. However, branching the DVR wire copies the handle and access must be protected which is what the Inplace Element Structure does. Circular usage of handles (A => B => A) is prohibited in LV and creates invalid VIs.
Regarding your question in the Instrument Init VI: Yes, you copy the object, create a handle and add the handle to the original (not the copy).
My recommendation is to not use DVRs but put the relay objects directly into the instrument object (as array of class "relay"). The pass around the instrument where it is needed and each user retrieves the relay object necessary, modifies it and puts it back in the instrument.
Do you need parallel access to relays?
Norbert
07-01-2016 09:36 AM
07-05-2016 07:12 AM
07-05-2016 09:41 AM
If Robert needs parallel access to relays, in reality, the only parallel way to pass VISA reference without it puking would be a DVR with an in-place element structure, correct? That way both "parallel" accessors to the relays would execute serially, while one blocks access to the other during execution until it's finished..
http://www.ni.com/white-paper/9386/en/
07-05-2016 10:10 AM
07-05-2016 10:14 AM
It's an area which needs a bit of care and attention, that's for sure.
I have already implemented a medium-sized object composition and the need to define wrapper methods for each and every little function of the composed objects is plain tiresome.