Eugen Graf Posted April 16, 2008 Report Share Posted April 16, 2008 Hello LAVAs! I began with OOP and want to use one Class in two parallel while loops. I have created a class with a Enum Member and Read and Write this member VIs (Set& Get Methods). So the upper loop should Increment this Enum on Buttonclick. I Read this Enum using Read, increment and Write the enum. The bottom loop should Read the enum and Swith the Switch-Case structure. But nothing happens. Can You explain me please why it doesn't work? Thank You, Regards, Eugen Quote Link to comment
Cmal Posted April 16, 2008 Report Share Posted April 16, 2008 QUOTE (Eugen Graf @ Apr 15 2008, 08:41 AM) Hello LAVAs!I began with OOP and want to use one Class in two parallel while loops. I have created a class with a Enum Member and Read and Write this member VIs (Set& Get Methods). So the upper loop should Increment this Enum on Buttonclick. I Read this Enum using Read, increment and Write the enum. The bottom loop should Read the enum and Swith the Switch-Case structure. But nothing happens. Can You explain me please why it doesn't work? Thank You, Regards, Eugen Eugen, One important thing to note about LVOOP is that classes are passed by value, not by reference. So, if you branch a wire containing a LabVIEW class you will then have two separate objects of that class, and changing one will not affect the other. It helps to think of class objects as clusters with added functionality, so they obey dataflow just like anything else in LabVIEW. If you want to create classes that behave more like reference objects, a trick I've found useful is to create "Reference" classes that contain a single-element queue reference to each "Value" class. There's an example that shows how to do this in the Example Finder (browse to Fundamentals >> Object-Oriented >> ReferenceObject.lvproj). Here's a document that explains a lot more about how classes work in LabVIEW: http://zone.ni.com/devzone/cda/tut/p/id/3574 -Chris Quote Link to comment
LAVA 1.0 Content Posted April 16, 2008 Report Share Posted April 16, 2008 QUOTE (Eugen Graf @ Apr 15 2008, 09:41 AM) Can You explain me please why it doesn't work? The implementations of OOP in LabView use the Dataflow paradigm. That mean your data is in your wire. If you split the wire, than you have two set of class data. You can take a look to http://forums.lavag.org/Refactoring-the-ReferenceObject-example-in-LV-82-t3788.html&st=30&start=30' target="_blank">this for more detail on how to implement a by reference object. You can also look to LabVIEW example. Quote Link to comment
Eugen Graf Posted April 16, 2008 Author Report Share Posted April 16, 2008 Ok, thank You both! I understand this very good, but that is really bad! Do NI want in the next time implement this feature or it will always stay by "pass by value"? If not, I don't see any advantages in use LVOOP. Thank You Quote Link to comment
Yair Posted April 16, 2008 Report Share Posted April 16, 2008 QUOTE (Eugen Graf @ Apr 15 2008, 05:28 PM) Do NI want in the next time implement this feature or it will always stay by "pass by value"? This is probably the single biggest issue users have with LVOOP (at least users who are used to GOOP). The document Chris linked to goes into this in some detail, with the bottom line that in the future, by-ref support might be implemented, but I wouldn't hold my breath. If you want by-ref, you can use the options mentioned by the others. QUOTE If not, I don't see any advantages in use LVOOP. That's because you're looking at it from the wrong frame of reference. You're used to GOOP, which works by reference and is very convenient and powerful. LVOOP can probably do that, with the appropriate wrappers, but it was also designed to do other stuff where you don't care about using a single instance of an object in different parts of your code. There are all kinds of examples you can find online to see where LVOOP gives you more power. Searching through this board should provide you with some. The key is in understanding that the use cases for LVOOP are not necessarily the same as the ones for GOOP. Quote Link to comment
shoneill Posted April 16, 2008 Report Share Posted April 16, 2008 QUOTE (Yen @ Apr 15 2008, 05:45 PM) That's because you're looking at it from the wrong frame of reference. Shucks, you beat me to it! I was just going to say the same thing. I'm currently coding in C#, By-Reference Class usage and all. I can see the appealy of both sides..... Shane. Quote Link to comment
MikaelH Posted April 17, 2008 Report Share Posted April 17, 2008 Maybe you should try the referenced based version, which you can get from the GOOP Development Suite (GDS). Currently there are 2 referenced based versions of GOOP the GDS supports, but soon there will be another GOOP-flavor. BTW, Version 2.5 was just released (as yesterday). Cheers, Mikael Quote Link to comment
Aristos Queue Posted April 20, 2008 Report Share Posted April 20, 2008 QUOTE (shoneill @ Apr 15 2008, 01:34 PM) Shucks, you beat me to it! Ah... It is so nice to know that we have reached the point where I can go on vacation and count on others to preach the gospel while I'm gone. :-) Quote Link to comment
Eugen Graf Posted April 22, 2008 Author Report Share Posted April 22, 2008 So, ok. I will use a task (loop) for each class and communicate over queues, notifiers or user events. Can anybody explain me please when I should use dynamic member VIs and when to use static member VIs? And the next question is how can I define class members so, if I add new members or remove some members, all member VIs will update the class cluster? Should I define the class cluster as typedef for it? Thank You. Quote Link to comment
Aristos Queue Posted April 22, 2008 Report Share Posted April 22, 2008 QUOTE (Eugen Graf @ Apr 21 2008, 09:13 AM) And the next question is how can I define class members so, if I add new members or remove some members, all member VIs will update the class cluster? Should I define the class cluster as typedef for it? You can't have the class cluster be a typedef directly (for a long list of hotly debated reasons during the design phase of LVClasses that I'm not going into now). But you can put a cluster inside the main cluster and typedef that. Doing so would also save you from ever having to update the Bundle/Unbundle nodes, since you'd just unbundle the cluster as a whole and bundle the cluster as a whole, not each individual element. I'll let someone else field the static/dynamic dispatch question. Quote Link to comment
Yair Posted April 22, 2008 Report Share Posted April 22, 2008 QUOTE (Eugen Graf @ Apr 21 2008, 04:13 PM) Can anybody explain me please when I should use dynamic member VIs and when to use static member VIs? You use VIs with dynamic dispatch inputs to override the implementations of parent classes. For example, if you have the class "animal" and a child class "dog" and a grandchild class "poodle" and you create a "speak" method for each class, then wiring a poodle object into the DD input will return "woof" and wiring a cat object will return "meow". You should follow the link Chris provided earlier for more details. Also, Tomi's blog had a tutorial about inheritance in LVOOP. QUOTE And the next question is how can I define class members so, if I add new members or remove some members, all member VIs will update the class cluster? Should I define the class cluster as typedef for it? The class data already acts as a private typedef for all member VIs in the class. That's the encapsulation mechanism. Quote Link to comment
Eugen Graf Posted April 23, 2008 Author Report Share Posted April 23, 2008 Ok, thank you for answers! 1) Where can I see if a member VI is dynamically or statically defined (e.g. if I get a OOP project from other people)? 2) Can I change a static member VI to dynamical and back after definition? Should I always take better dynamical? 3) Can I use one dynamical member VI on more than one loop in my programm parallely (for copies of the same class) or it's the same as staticaly use in this issue? Reentrant VI is other thing as statical or dynamical member VI? QUOTE Doing so would also save you from ever having to update the Bundle/Unbundle nodes, since you'd just unbundle the cluster as a whole and bundle the cluster as a whole, not each individual element. Is there a possibility to update Bundle/Unbundle Node by rightklicking or sth. like this? QUOTE The class data already acts as a private typedef for all member VIs in the class. That's the encapsulation mechanism. Yes, right, but I think e.g. if I change a name of an member, my Bundle/Unbundle will not be automatically updated like if I use Strickt Type Definitions. Quote Link to comment
Yair Posted April 23, 2008 Report Share Posted April 23, 2008 You should note that dynamic dispatch has nothing at all to do with dynamically loaded VIs. It refers to VIs which override the implementation of the parent class. The VIs themselves are loaded with the rest of the class. The answer to your other question is that the class data type acts like a typedef, so you shouldn't have any problem. LVOOP is a big thing. You should really take the time to read the relevant material, because you can't expect to learn it based on what you already know. Quote Link to comment
Aristos Queue Posted April 23, 2008 Report Share Posted April 23, 2008 QUOTE (Eugen Graf @ Apr 22 2008, 03:09 AM) 1) Where can I see if a member VI is dynamically or statically defined (e.g. if I get a OOP project from other people)? 90% of the time you shouldn't care. But if you need to care, look at the terminal conpane of the VI. If the class input has a dotted line around it, that's a dynamic dispatch VI. QUOTE 2) Can I change a static member VI to dynamical and back after definition? Sure. Popup on the conpane terminal, select "This terminal is..." and choose the one you want. QUOTE Should I always take better dynamical? No. You should choose the one that matches your functionality. There are trade-offs to both options. QUOTE 3) Can I use one dynamical member VI on more than one loop in my programm parallely (for copies of the same class) or it's the same as staticaly use in this issue? Reentrant VI is other thing as statical or dynamical member VI? Reentrancy is supported for dynamic dispatch VIs in LV8.5, but not LV8.2. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.