07-25-2011 04:16 PM
I am trying to make a project that would allow me to call instances of a class multiple times. And then if I wanted to refer to the same instance later on. I haven't been able to do that in a concise way, I found a adhoc method of accomplishing that by creating a loop that created a new instance each time. Is there a better way of doing this that I am unaware of due to lack of Labview-experience?
Thanks in advance!
07-25-2011 04:25 PM
There really isn't a better method. I would recommend that you use an array or a cluster (which one depends on whether you have a fixed number of items or a variable number of instances). You can use an array of clustes as well with the clsuter containing the object instance and then other instance specific data such as the name or identifier of the instance). Unfortunately in LabVIEW there isn't a convenient way to free resources associated with an instance of an object.
If you use an array this gives you the flexibility to have any number of instances. However you must keep track of which instance is in which array position. If you use a cluster you are constrained to a fixed number of instances which requires a code change to modify. However the code is more readable since the unbundle will have meanigful names for the cluster elements.
Using class inheritance will allow you to have different object types which are derived from a base class. This makes it easy to customize the code using dynamic dispatch calls.
07-27-2011 01:14 PM
I tried to use arrays however, I'm having a hard time accesing one element at a time. When, I print it out.. it still prints out all of the information stored in the array.
The mod subvi - prints out the information in the array as a histogram.
07-28-2011 08:13 AM - edited 07-28-2011 08:17 AM
like most LVOOP questions, a short answer is hard to give.
I use "Active Objects" which are simply VI templates that have dynamic dispatch terminals that I use to determine the instance type before I run the template. The parent class has methods that allow interacting with the template that runs in the back-ground.
Queues are used to do the communications and implement the methods in the template ased on the request from other objects in the application.
Yes I know, "Complete correct but totally useless."
I have code images in my gallery that START here.
See this thread where I included words with the images and the questioner seemed to have figured it out.
Ben