LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

object oriented development

I would like to ask some questions about OO development in LV8.20, so as to make sure I understand a few of the fundamentals.  I watched the demo (ni.com) and thought it was very well done.  However, the examples used had only two attributes, a number and a string, and both were set (as defaults) within the controls contained within the class.  Am I correct in that anytime you want to use a method of a class, you first place the class itself on the block diagram.  Also, within an application VI, if several of the class methods (for the same class) are to be called sequentially, do you only need the one instance of the class icon.
 
Finally, in the example above, the initial value of the class attributes were known.  What if there is an I/O card that is opened by calling a function within a DLL.  I want to make the handle (returned from the Open) and attribute, and then provide get/set methods.  How do I perform this initialization?  Do I just create all the attributes and have an initialization routine that calls all the set methods?
0 Kudos
Message 1 of 8
(3,236 Views)

Mr. Bean,

It is hard to answer this question quickly but here is my attempt.  With OOP or GOOP you always will need a create and a destroy.  Create will create the private and public data that is part of the class.  Create is a good place to add initialize code because it will then auto-initialize every time create is called. Each time you call create it will will make a new instance and in most cases you only want on instance of a class.  You use destroy to remove the class and clean up the memory. 

Multiple instances makes your code scalable.  Let say you have one switch box then you add a second one.  You can create a second instance with the address of the new box and you are done!  This means you will get all the data and methods needed to operate on this second box just by creating a second instance.

Use Create to initialize, use set to change a property, and use get to return data from the class.  Private Data can only be accessed by the class but Public Data can be accessed outside of the class.  Properties act on data and Methods do something.  It is more involved than this but have to get back to work.

Hope this helps,

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
Message 2 of 8
(3,216 Views)
I thought LabVIEW GOOP had auto garbage collection, like java??

Message Edited by MJBrehm on 10-03-2006 03:27 PM

0 Kudos
Message 3 of 8
(3,203 Views)

Not sure what you mean by, "Auto Garbage Collection".  I am not sure but it will release memory when you close the application but may not release it when the program ends.  It is proper to destroy what you create just like closing a serial port if you open it.  Doesn't hurt!

 

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 4 of 8
(3,193 Views)
What I meant by auto garbage collection was that it disposes of references after they are not needed anymore. For instance, a variable that is only used in a for loop. At the end of the for loop that memory allocation is released.
0 Kudos
Message 5 of 8
(3,131 Views)
You are correct in your presumption that you will need to write a VI that performs any necessary initialization such as opening a file or loading a DLL. LVOOOP has no concept of anything other than the default constructor, which means all you get when you load a class is its default data in memory. No other function is performed.

There are two ways of accomplishing this:

The first is much more conservative. Create a VI in your class that takes no class data as an input, performs the initialization, and statically outputs an "initialized" set of class data. This is analogous to writing a constructor, but of course you have to remember to call it. LabVIEW won't figure that out for you.

Alternatively, you could write an XControl whose datatype is your class and have it perform special code when it recognizes the Execution Change event that fires when the VI containing it starts. It could then output initialized class data. This is more like a constructor in the dataflow sense, but the downside is that you're not guaranteed that the initialization will finish before the XControl terminal is read the first time. It's a race condition, unfortunately.
Jarrod S.
National Instruments
0 Kudos
Message 6 of 8
(3,117 Views)
I sort of when with option 1 (Initialize).  It seemed a little more straight forward to me.  Thanks.
0 Kudos
Message 7 of 8
(3,098 Views)

I am in sync now.  The comments I made were in reference to the GOOP Wizard from Endevo.  Had to stop doing my regular job and spend a few hours playing with 8.20.

General comments:

- Do not like the fact that you can't call a destructor.  I feel this is an important part of OOP and dynamic programs were resources can be added and removed On-The-Fly

- Changed the class icon after I started to code.  I had t go back manually and change the icons so make sure you do this when you create the class.  An auto update option would be nice simular to Icon Wizard.

- You have to use Shift Registers to maintain the state of the private data.  Using references would be a better way so you don't have to always pass data using SR.

On the plus side, very easy to use and get results quickly

 

Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 8 of 8
(3,060 Views)