09-17-2015 04:41 PM
Hi Folks,
I am absolutely new to Labview OOP and I am wondering how i can create two instances of the same class.
Usually in other object oriented programming languages there is a constructor which returns a newly initialized instance. I have the feeling, that every class in LV exists only once.
Can please somone tell me where to find information about this?
Thanks
Michael
Solved! Go to Solution.
09-17-2015 04:43 PM - edited 09-17-2015 04:46 PM
In LabVIEW, the class wires on the block diagram are the different instances. If you take a wire and split it off to go two different places, each of the new branches is its own data and instance.
Here's a screenshot of the code I am currently working on. The red class wire is a Message that I am passing. I need to enqueue the same message a few times with different message actions, so I made an array of this same message. Each array element is a different instance of that message class.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
09-17-2015 09:55 PM
James is correct, the following link explains that among other OOP questions. It's an interesting read if you have the time.
http://www.ni.com/white-paper/3574/en/
09-17-2015 11:38 PM
Also it's worth mentioning that because each wire is a separate instance of a class, the data on every wire is unique. I know that sounds obvious, but keep it in mind when developing your application. For example you may have a device class which talks via serial to a piece of hardware. A loop contains a call to a member VI of the class which reads and parses messages from the hardware and stores it in a private member of the class. If you want to access that data from another loop, a branch of that class won't be updated with the data, as it is a completely different instance.
So remember to design your classes thinking in terms of dataflow. Class based designs which you may have used in other languages might not directly translate to LabvIEW classes. There are methods of performing the above example using DVRs, private queue or FIFO references, or other techniques. That said, given you're new to LVOOP I'd avoid these techniques (for now), and just get thinking in terms of classes and dataflow.
09-18-2015 01:52 AM
If you really need to have your classes be by reference (equivalent of using pointers) rather than by value then you should look at the GOOP toolkit.
It comes with a certain amount of overhead because you have to do your own garbage collection and generally have to be more careful/mindful of what you do but there are apparently some things that are easier to do using GOOP than the already included LVOOP.