LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Classes and instances

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?

 

instance_calling.png

Thanks in advance!

0 Kudos
Message 1 of 4
(2,793 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 4
(2,786 Views)

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.

0 Kudos
Message 3 of 4
(2,757 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 4
(2,737 Views)