LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LV OOP Multiple Instances of a class

Solved!
Go to solution

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 

0 Kudos
Message 1 of 5
(5,113 Views)
Solution
Accepted by mthimm1

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.

Array of Single Class.PNG

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 2 of 5
(5,109 Views)
Solution
Accepted by mthimm1

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/

Matt J | National Instruments | CLA
Message 3 of 5
(5,079 Views)

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.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 4 of 5
(5,066 Views)

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.

0 Kudos
Message 5 of 5
(5,042 Views)